7

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   

1 Answer 1

25

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.