简体   繁体   English

如何调整Matplotlib散点图的大小

[英]How to resize matplotlib scatter plot

I'm unable to resize the graph in my matplotlib scatter plot. 我无法调整matplotlib散点图中的图形大小。 I have included plt.figure(figsize=(20,20)) but it doesn't affect the size. 我已包含plt.figure(figsize=(20,20))但它不会影响大小。

Here is the current plot output. 这是当前绘图输出。

plt.scatter(x['so2_x'],x['state'],alpha=0.5,c=x['so2_x'],s=x['so2_x'])
plt.title("so2@2011 vs state")
plt.figure(figsize=(20,20))
plt.show   

This line isn't doing what you think it is. 这条线没有按照您的想法做。

plt.figure(figsize=(20,20))

Instead of adjusting the size of the existing plot, it's creating a new figure with a size of 20x20. 无需调整现有图的大小,而是创建一个20x20大小的新图形。 Simply move the above line before the call to scatter and things will work as you want. 只需在调用散点图之前将上面的行移动即可,一切随心所欲。

plt.figure(figsize=(20,20))
plt.scatter(x['so2_x'],x['state'],alpha=0.5,c=x['so2_x'],s=x['so2_x'])
plt.title("so2@2011 vs state")    
plt.show()

Another alternative is to change the size after the call to scatter implicitly creates the figure object using gcf() to return the current figure handle. 另一种选择是在调用散点图隐式创建图形对象之后使用gcf()返回当前图形句柄来更改大小。

plt.scatter(x['so2_x'],x['state'],alpha=0.5,c=x['so2_x'],s=x['so2_x'])
plt.title("so2@2011 vs state")
plt.gcf().set_size_inches((20, 20))    
plt.show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM