2

Is there an easy way to modify this code so that the plots are bigger without changing the scale on the axes?

import numpy as np
import matplotlib.pyplot as plt
import math
%matplotlib inline

a, c = -10, 10                                
x = np.linspace(a,c,100)                         
x = np.array(x)
def y(x): return np.arctan(x)                       

h = 0.0000001                                   

def grad(x,h): return (y(x+h)-y(x))/h          
m = grad(x,h)

plt.figure(1)
plt.subplot(121)
plt.plot(x, y(x), 'b')
plt.xlim([a,c])
plt.ylim([min(y(x)),max(y(x))])
plt.gca().set_aspect('equal', adjustable='box') 

plt.subplot(122)
plt.plot(x,m,'b')
plt.xlim([a,c])
plt.ylim([min(m),max(m)])
plt.gca().set_aspect('equal', adjustable='box')

plt.subplots_adjust(wspace = 0.5)
plt.show()

enter image description here

If I get rid of plt.gca().set_aspect('equal', adjustable='box') the plots come out a decent size but they are not to scale.

0

1 Answer 1

6

The subplots are shrunk such that their aspect is equal. This seems to be desired; and thus it is not really clear what "bigger" refers to.

You can still make the figure larger, e.g.

plt.figure(1, figsize=(12,2))

and then adjust the margins and spacings using plt.subplots_adjust.enter image description here

You can also let the axes scale and only set the equal aspect to the data,

plt.gca().set_aspect('equal', adjustable='datalim')

enter image description here

Finally plotting the subplots beneath each other makes them bigger as well. So you might use plt.subplot(211) and plt.subplot(212).enter image description here

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.