How to automatically set the scale for x-axis to be equal for all subplots in matplotlib?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


How to automatically set the scale for x-axis to be equal for all subplots in matplotlib?



In this example:


import numpy as np
import matplotlib.pyplot as plt

t1 = np.linspace(0, 1, 1000)
t2 = np.linspace(0, 0.5, 1000)

plt.figure(figsize=(10,5))

plt.subplot(121)
plt.plot(t1, np.sin(t1 * np.pi))

plt.subplot(122)
plt.plot(t2, np.sin(t2 * np.pi))

plt.show()



enter image description here



How can I squeeze the size of the second plot so that the x-axis for both subplots would have the same scale? I am looking for a simple and automatic way to do this because I have more than 30 subplots and would want them all have the same x-axis scale.









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

Future solutions