1005x132589像素的图像尺寸太大。每个方向都必须小于2 ^ 16

deb*_*e4u 10 python matplotlib pandas

我正在使用matplotlib.pyplot从Dataframe绘制图形。在这里,我想显示每个矩形上条形的高度,并且正在使用Text()。为了标准化Y轴,我在Y轴上采用了Logscale。以下是我的代码,出现错误

Image size of 1005x132589 pixels is too large. It must be less than 2^16 in each direction
Run Code Online (Sandbox Code Playgroud)

当我不使用时,plt.yscale('log')代码工作正常。根据一些建议,我也重新启动了内核,但仍然遇到此问题。欢迎对此提出任何建议。

我的代码:

`
#收集到的数据列出。list_alarms = df_region.alarmName#list_east = df_region.EAST list_west = df_region.WEST list_north = df_region.NORTH list_south = df_region.SOUTH

# X-ticks customization
N = len(list_alarms)
xpos = np.arange(N)

# this json file is used to update the style of the plot. 
s = json.load(open('style.json'))    
rcParams.update(s)

# Graph customize
plt.rcParams['figure.figsize'] = (15,8)
plt.xlabel('AlarmNames at different Regions')
plt.ylabel('Frequency for alarms in MNG-PAN devices')
plt.title('Alarm Generated by MNG-PAN Device at different Regions')
plt.xticks(xpos,list_alarms, rotation = 280)

# bar1 = plt.bar(xpos - 0.3,list_east, width = 0.2, label = 'EAST', 
    color = '#3154C8')
bar2 = plt.bar(xpos - 0.1, list_west, label = 'WEST', color = 
    '#FF9633')
bar3 = plt.bar(xpos + 0.1, list_north, label = 'NORTH', color = 
    '#12B794')
bar4 = plt.bar(xpos + 0.3, list_south, label = 'SOUTH', color = 
    '#EF6FE3')
plt.yscale('log')
plt.legend()

def autolabel(rects):
    for rect in rects:
        height = rect.get_height()
        if height < 10000:
            plt.text(rect.get_x() + rect.get_width()/2., 1.05*height, 
                 '%d'%int(height),
                 ha = 'center', va = 'bottom', rotation = 90, 
    fontsize=9)


# # autolabel(bar1)
autolabel(bar2)
autolabel(bar3)
autolabel(bar4)

plt.show()
Run Code Online (Sandbox Code Playgroud)

`

我正在使用Jupyter Notebook,Pandas,Python3。

Cre*_*edd 7

它使用关键字参数对我有用transform=ax.transAxes

例如:

plt.text(0.5, 0.5, 'Some text', transform=ax.transAxes)
Run Code Online (Sandbox Code Playgroud)


小智 5

plt.text在自动标签定义的行中检查您的位置变量。我有一个相同的问题,我发现给plt.text函数的y变量与我的plot数据集的值相比太大。


小智 5

您的 X 轴可能是字符串值,而 plt.text() 仅采用标量值在轴上移动。所以这就是您的范围可能超出图像大小的原因。将 x 轴转换为标量值。我有同样的问题,我做了同样的事情。


Pho*_*nix 3

您可以调整像素并更新 update_datalim()

fig = plt.figure(1, figsize=(8, 14), frameon=False, dpi=100)
fig.add_axes([0, 0, 1, 1])
ax = plt.gca()

corners = ((x1, y1), (x2, y2))
ax.update_datalim(corners)
Run Code Online (Sandbox Code Playgroud)