0

I have a problem in plotting in subplot, i.e. title and axis label is overlap in python. This is my code:

import numpy as np
import matplotlib.pyplot as plt
x=np.linspace(-np.pi,np.pi,50,endpoint=True)
plt.figure()
plt.subplot(211)
plt.plot(x,np.sin(x),'r-')
plt.title('y=sin(x)')
plt.xlabel('x')
plt.ylabel('y')
plt.grid()
plt.subplot(212)
plt.plot(x,np.cos(x),'b-')
plt.title('y=cos(x)')
plt.xlabel('x')
plt.ylabel('y')
plt.grid()
plt.show()

This is the result:

enter image description here

Now I want the title of second subplot is not overlap with x label in first subplot. How to make it?

0 Answers0