Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.9k views
in Technique[技术] by (71.8m points)

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

I am using matplotlib.pyplot to plot a graph from a Dataframe.

I want to show the height of the bar upon each rectangle and am using Text(). For normalising the y-axis, I have taken the log. Below is my code, I am getting error

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 the code is working fine.

According to some suggestions, I have restarted my kernel too, but still getting this issue. Any suggestions regarding this is welcomed.

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


# 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Check your location variables at plt.text line in autolabel definition. I had the same problem and I found that the y variable I gave to plt.text function was too large compared to the value of my dataset of plot.

This is also an issue with plt.annotate if the location is outside the figure.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...