0
我有N個子圖,我想分享除了其中一個以外的所有Y軸。可能嗎?有沒有辦法在matplotlib中的部分子圖中共享Y軸?
我有N個子圖,我想分享除了其中一個以外的所有Y軸。可能嗎?有沒有辦法在matplotlib中的部分子圖中共享Y軸?
是的,你可以指定哪個suplots與哪個軸共享哪個軸(這不是我輸入的錯字)。有一個sharex
和sharey
論據add_subplot
:
例如:
import numpy as np
import matplotlib.pyplot as plt
x = np.array([1,2,3,4,5])
y1 = np.arange(5)
y2 = y1 * 2
y3 = y1 * 5
fig = plt.figure()
ax1 = fig.add_subplot(131) # independant y axis (for now)
ax1.plot(x, y1)
ax2 = fig.add_subplot(132, sharey=ax1) # share y axis with first plot
ax2.plot(x, y2)
ax3 = fig.add_subplot(133) # independant y axis
ax3.plot(x, y3)
plt.show()
這將創建這樣的曲線圖(1 ST和2 第二份額y軸,但3 RD沒有):
您可以在matplotlib示例"Shared axis Demo"中找到此示例。