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

标签 python pandas matplotlib

我正在使用 matplotlib.pyplot 从 Dataframe 中绘制图表。

我想在每个矩形上显示栏的高度,我正在使用 Text()。为了标准化 y 轴,我采用了日志。下面是我的代码,我收到错误

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

当我不使用 plt.yscale('log') 时,代码工作正常。

根据一些建议,我也重新启动了我的内核,但仍然遇到这个问题。欢迎就此提出任何建议。

我的代码:

# 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


# 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()

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

最佳答案

autolabel 定义中的 plt.text 行检查您的位置变量。我遇到了同样的问题,我发现我给 plt.text 函数的 y 变量与我的 plot 数据集的值相比太大了。

如果位置在图外,这也是 plt.annotate 的问题。

关于python - 1005x132589 像素的图像尺寸过大。每个方向必须小于 2^16,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51980366/

相关文章:

python - 如何在 Django 过滤器中使用 AND?

python - 为什么 '362' > 378?

pandas - 似乎无法缩短我的 Pandas 列的小数

python - 每组内累计运行百分比和每组降序排列python

python - Pandas 按行号分组产生意外输出

python - 防止 GridSpec 子图分离随图形大小而变化

python - matplotlib 在 mac osx 上挂起并且不显示图形

python - 如何将 "include"第三方模块放入我的 python 脚本以使其可移植?

python - 启动默认编辑器(如 'webbrowser' 模块)

python - 设置绘图 y 轴和 x 轴比例相等