Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.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 1005x132589像素的图像大小太大。在每个方向上必须小于2^16_Python_Pandas_Matplotlib - Fatal编程技术网

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

Python 1005x132589像素的图像大小太大。在每个方向上必须小于2^16,python,pandas,matplotlib,Python,Pandas,Matplotlib,我正在使用matplotlib.pyplot从数据帧绘制图形 我想在每个矩形上显示条的高度,并使用Text()。为了使y轴正常化,我采用了对数。下面是我的代码,我得到了错误 1005x132589像素的图像大小太大。在每个方向上必须小于2^16 当我不使用plt.yscale('log')时,代码工作正常 根据一些建议,我也重新启动了我的内核,但仍然遇到这个问题。欢迎对此提出任何建议 我的代码: # data collected to list. list_alarms = df_region

我正在使用
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()
#收集到要列出的数据。
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定制
N=len(列出报警)
xpos=np.arange(N)
#此json文件用于更新打印样式。
s=json.load(打开('style.json'))
rcParams.update(个)
#图形定制
plt.rcParams['figure.figsize']=(15,8)
plt.xlabel('不同区域的报警名称')
plt.ylabel(“MNG-PAN设备中的报警频率”)
plt.title(‘MNG-PAN设备在不同区域产生的报警’)
plt.xticks(XPO,列表报警,旋转=280)
#bar1=plt.bar(xpos-0.3,列表东,宽度=0.2,标签='east',颜色='3154C8')
bar2=plt.bar(xpos-0.1,列表西,标签='west',颜色='FF9633')
bar3=plt.bar(xpos+0.1,列表北,标签='north',颜色='12B794')
bar4=plt.bar(xpos+0.3,列表南部,标签为“南部”,颜色为“EF6FE3”)
plt.yscale('log')
plt.legend()
def自动标签(rects):
对于矩形中的矩形:
高度=矩形。获取高度()
如果高度<10000:
plt.text(矩形get_x()+矩形get_width()/2,1.05*高度,
“%d”%int(高度),
ha=中心,va=底部,旋转=90,
字体大小=9)
##自动标签(bar1)
自动标签(bar2)
自动标签(bar3)
自动标签(bar4)
plt.show()

我正在使用Jupyter笔记本电脑、Pandas、Python3。

您可以调整像素并更新您的更新\u datalim()


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


这也是plt的一个问题。如果位置在图形之外,请注释。

另一种可能的解释可能是其中一个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')

X轴可能是字符串值,plt.text()只接受标量值在轴上移动。这就是为什么你的范围可能超出图像大小。将x轴转换为标量值。我有同样的问题,我也有同样的问题。

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

例如:

plt.text(0.5,0.5,'Some text',transform=ax.transAxes)

发生这种情况是因为x轴包含日期,并且在添加文本时传递的是标量值

要解决此问题,应使用matplotlib.mdates.date2num()转换日期 请参阅以下答案:

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')