i'm trying to manipulate the axes limits of my subplots in python. Whereever i try to place the axes-command there always seems to be another problem. I would like to create a subplot and manipulate the axes limits individually. Either no limits are set in my plot window or a subplot disappears entirely.
My code:
"Import"
import numpy as np
import matplotlib.pyplot as plt
"Maths"
x = np.linspace(-10,10,1000)
b = [2,3,4]
f = 3 #in Hz
def y(z):
return(np.sin(2*np.pi*f*x) * np.sin(2*np.pi*b[z]*x))
"Plot"
plt.close("all")
%matplotlib inline
plt.figure(figsize = (12,10))
plt.axes(xlim=(-5,5), ylim=(-1,1))
plt.subplot(3,1,1)
plt.plot(x,y(0))
plt.grid()
plt.subplot(3,1,2)
plt.plot(x,y(1))
plt.grid()
plt.subplot(3,1,3)
plt.plot(x,y(2))
plt.grid()
Try these. It has to be put after each plt.subplot()
command.
Often you see these commands right after the plt.plot()
command.
plt.xlim((left, right))
plt.ylim((bottom, top))