6

I'm unable to resize the graph in my matplotlib scatter plot. I have included plt.figure(figsize=(20,20)) but it doesn't affect the size.

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   
cmaher
  • 5,100
  • 1
  • 22
  • 34
sanjeet kishore
  • 71
  • 1
  • 1
  • 3

1 Answers1

24

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

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()
Caleb
  • 284
  • 2
  • 7