Issue
I want to compare subplots visually with ease. To do this, I want to set the same scale for all subplots.
My code works fine, and I'm able to plot subplots, but with their own scales. I want to maintain the scale on the x axis.
Solution
If you want to have two subplots with the same xaxis, you can use the sharex
-keyword when you create the second axes:
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax1 = fig.add_subplot(2, 1, 1)
ax2 = fig.add_subplot(2, 1, 2, sharex=ax1)
t = np.linspace(0, 1, 1000)
ax1.plot(t, np.sin(2 * np.pi * t))
ax2.plot(t, np.cos(2 * np.pi * t))
plt.show()
Answered By - MaxNoe
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.