Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何避免在matplotlib子批次中剪裁AnnotationBbox图像_Python_Matplotlib - Fatal编程技术网

Python 如何避免在matplotlib子批次中剪裁AnnotationBbox图像

Python 如何避免在matplotlib子批次中剪裁AnnotationBbox图像,python,matplotlib,Python,Matplotlib,我正在绘制纽约市的用水超时图,并试图用红色热浪图像对该图进行注释,这些图像在每年干旱的地方都会出现。然而,热浪图像是在绘图下面分层的,正在被剪裁 我如何“提前”热浪图像,使其完全可见且不被剪裁 这是我的密码: # create the plot fig, ax = plt.subplots(figsize=(11, 8)) # plot total consumption as a vertical bar chart ax1 = fig.add_subplot(111) bar = sns.

我正在绘制纽约市的用水超时图,并试图用红色热浪图像对该图进行注释,这些图像在每年干旱的地方都会出现。然而,热浪图像是在绘图下面分层的,正在被剪裁

我如何“提前”热浪图像,使其完全可见且不被剪裁

这是我的密码:

# create the plot
fig, ax = plt.subplots(figsize=(11, 8))

# plot total consumption as a vertical bar chart
ax1 = fig.add_subplot(111)
bar = sns.barplot(x = df['year'], y = df['nyc_consumption_million_gallons_per_day'], color = 'b')
ax1.set_ylim([600, 1600])
ax1.grid(False)
ax1.set_ylabel('Total Consumption (Millions of Gallons per Day)', fontsize=11)
ax1.set_xlabel('')

# plot per capital consumption as a line
ax2 = ax1.twinx()
line = plt.plot(df['per_capita_gallons_per_person_per_day'], color='g')
ax2.set_ylim(100,240)
ax2.grid(False)
ax2.set_ylabel('Per Capita Consumption (Gallons per Person per Day)', fontsize=11)

# design properties
ax.get_yaxis().set_visible(False) # removes y axis from underlying figure
ax.get_xaxis().set_visible(False) # removes x axis from underlying figure

# make a legend
leg1 = plt.Rectangle((0,0),1,1,fc='b', edgecolor='none')
leg2 = plt.Rectangle((0,0),1,1,fc='g', edgecolor='none')

l = plt.legend([leg1, leg2], ['Total Consumption', 'Per Capita Consumption'],
               bbox_to_anchor=(1.0,1.01), ncol = 4, prop={'size':14})

# add title
title = ax.annotate("Water Consumption in New York City is Decreasing",
            (0,0), (-75, 530), textcoords='offset points', color='gray', fontsize=26, fontweight='heavy')

# add subtitle
sub = ax.annotate("History of average daily water consumption in the New York City Water Supply System",
            (0,0), (-75, 505), textcoords='offset points', color='gray', fontsize=16, style='italic')

# add heatwave symbols on top of years that had a drought
arr_hand = read_png(r"C:\Users\Will\Downloads\heat-symbol-hi.png")
imagebox = OffsetImage(arr_hand, zoom=0.9)
xy = [0.25, 0.45]               # coordinates to position this image

ab = AnnotationBbox(imagebox, xy,
    xybox=(30., 30.),
    xycoords='data',
    boxcoords="offset points", frameon=False)                                  
ax.add_artist(ab)
结果如下:

嘿,我也有类似的问题,但在我的情况下,根本不显示图像!我正在使用Qt4Agg后端。我注意到,如果我添加
ax.imshow(arr\u hand)
命令,那么两个图像都会出现:一个来自
ab
,另一个来自
imshow
。真的很奇怪…嘿,我有一个类似的问题,但在我的情况下,图像根本不显示!我正在使用Qt4Agg后端。我注意到,如果我添加
ax.imshow(arr\u hand)
命令,那么两个图像都会出现:一个来自
ab
,另一个来自
imshow
。真奇怪。。。