【发布时间】:2020-09-06 16:22:51
【问题描述】:
我想使用 matplotlib 在两个子图的右侧添加一个表格。我尝试了以下代码,但它只将表格与一个子图对齐...
import matplotlib.pyplot as plt
import numpy as np
t = np.linspace(-1,1,100)
fig, axs = plt.subplots(2, 1, constrained_layout=True)
ax1, ax2 = axs
ax1.plot(t, t**2)
ax1.set_title('One plot')
ax1.set_xlabel('Time')
ax1.set_ylabel('Amplitude')
ax1.legend()
ax2.plot(t, t**3)
ax2.set_title('Another plot')
ax2.set_xlabel('Time')
ax2.set_ylabel('Amplitude')
clust_data = np.random.random((10,3))
collabel=("col 1", "col 2", "col 3")
the_table = plt.table(cellText=clust_data,
colLabels=collabel,
loc='right')
我也尝试使用 Gridspec,但没有成功。感谢您的帮助!
【问题讨论】:
标签: python matplotlib subplot