python - 1005x132589 像素的图像尺寸太大。每个方向必须小于 2^16
问题描述
我正在使用matplotlib.pyplot
从数据框中绘制图表。
我想在每个矩形上显示条的高度并使用Text()
. 为了标准化 y 轴,我记录了日志。下面是我的代码,我收到错误
1005x132589 像素的图像尺寸太大。每个方向必须小于 2^16
当我不使用时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。
解决方案
plt.text
在autolabel
定义中检查您的位置变量。我有同样的问题,我发现y
我给plt.text
函数的变量与我的绘图数据集的值相比太大了。
plt.annotate
如果位置在图形之外,这也是一个问题。
推荐阅读
- excel - 启动 Excel 时如何打开 Visual Basic?
- php - 为什么注册服务在 laravel 中不起作用?
- javascript - 带有计数器的 each() - 常量名称
- xamarin - Xamarin WebView 有时不会在 UWP 中显示
- css - 如何使用 Internet Explorer 11 开发人员工具检查伪元素
- javascript - 如何以角度重置ng-select
- python-3.x - 在文本文件中按升序排列
- performance - 节点上的 Spark 分区 foreachpartition
- java - 使用哪个 HTTP 动词来触发 Kafka 消息的发布
- sql - T SQL Cte delete where group by 大于 1