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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/51980366/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 20:00:32  来源:igfitidea点击:

Image size of 1005x132589 pixels is too large. It must be less than 2^16 in each direction

pythonpandasmatplotlib

提问by debaonline4u

I am using matplotlib.pyplot to plot graph from Dataframe. Here I want to show the height of the bar upon each rectangle and am using Text(). And for normalising Y-Axis, I have taken Logscale upon Y-Axis. Below is my code, I am getting error

我正在使用 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

When I am not using plt.yscale('log')then code is working fine. According to some suggestion I have restarted my Kernel too, but still getting this issue. Any suggestions regarding this is welcomed.

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

My Code:

我的代码:

`
# data collected to list. 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

`
# 收集到列表的数据。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()

`

`

I am using Jupyter Notebook, Pandas, Python3.

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

回答by ???

Check your location variables at plt.textline in autolabel definition. I had a same problem and I found that y variable which I gave to plt.textfunction is too large compared to the value of my dataset of plot.

plt.text在自动标签定义中检查您的位置变量。我遇到了同样的问题,我发现我给plt.text函数的y 变量与我的绘图数据集的值相比太大了。

回答by Phoenix

You can adujust pixels and update your update_datalim()

您可以调整像素并更新您的 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)

回答by Reinier Koops

Another possible explanation could be that one of your y-axis values is zero. Thus you could edit your autolabel function into something like this:

另一种可能的解释可能是您的 y 轴值之一为零。因此,您可以将自动标签功能编辑为如下所示:

def autolabel(rects):
for rect in rects:
    height = rect.get_height()
    if (height != 0):
        ax.annotate('{}'.format(height),
                    xy=(rect.get_x() + rect.get_width() / 2, height),
                    xytext=(0, 3),  # 3 points vertical offset
                    textcoords="offset points",
                    ha='center', va='bottom')