सभी सबप्लॉट्स में समान X और Y लिमिट्स के लिए sharex और sharey पैरामीटर्स का उपयोग करें।
चरण
- फिगर साइज़ और ऑटोलेआउट सेट करें।
- पहला सबप्लॉट
ax1 = plt.subplot(2,2,1)बनाएं औरset_xlim(),set_ylim()सेट करें। - बाकी सबप्लॉट्स में
sharex=ax1, sharey=ax1पास करें। - प्रत्येक पर अलग डेटा प्लॉट करें।
plt.show()से दिखाएं।
उदाहरण कोड
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
ax1 = plt.subplot(2, 2, 1)
ax1.set_xlim(left=0, right=5)
ax1.set_ylim(bottom=0, top=5)
ax1.plot([1, 4, 3])
ax2 = plt.subplot(2, 2, 2, sharey=ax1, sharex=ax1)
ax2.plot([3, 4, 1])
ax3 = plt.subplot(2, 2, 4, sharey=ax1, sharex=ax1)
ax3.plot([2, 4, 2])
ax4 = plt.subplot(2, 2, 3, sharey=ax1, sharex=ax1)
ax4.plot([4, 0, 4])
plt.show()
आउटपुट
2x2 ग्रिड जहां सभी सबप्लॉट्स में समान X (0-5) और Y (0-5) लिमिट्स हैं।