python 个子图中的通用标签
Common label on python subplots
来自https://scipy-lectures.github.io/intro/matplotlib/auto_examples/plot_multiplot_ex.html
如何在 3 个子图(4,5 和 6)上放置一个通用的 y 轴标签?
fig = pl.figure()
fig.subplots_adjust(bottom=0.025, left=0.025, top = 0.975, right=0.975)
pl.subplot(2, 1, 1)
pl.xticks(()), pl.yticks(())
pl.subplot(2, 3, 4)
pl.xticks(())
pl.yticks(())
pl.subplot(2, 3, 5)
pl.xticks(())
pl.yticks(())
pl.subplot(2, 3, 6)
pl.xticks(())
pl.yticks(())
pl.show()
使用plt.subplots()
然后使用你想要的轴的numpy数组索引:
import matplotlib.pyplot as plt
fig, axes = plt.subplots(nrows=2, ncols=3, figsize=(6, 6))
for ax in axes[-1, :]:
ax.set_ylabel('My Ylabel')
fig.tight_layout()
现在您可以直接使用 Axes
对象进行绘图和自定义,而不是 plt
状态机和界面("explicit is better than implicit" 等等)
来自https://scipy-lectures.github.io/intro/matplotlib/auto_examples/plot_multiplot_ex.html
如何在 3 个子图(4,5 和 6)上放置一个通用的 y 轴标签?
fig = pl.figure()
fig.subplots_adjust(bottom=0.025, left=0.025, top = 0.975, right=0.975)
pl.subplot(2, 1, 1)
pl.xticks(()), pl.yticks(())
pl.subplot(2, 3, 4)
pl.xticks(())
pl.yticks(())
pl.subplot(2, 3, 5)
pl.xticks(())
pl.yticks(())
pl.subplot(2, 3, 6)
pl.xticks(())
pl.yticks(())
pl.show()
使用plt.subplots()
然后使用你想要的轴的numpy数组索引:
import matplotlib.pyplot as plt
fig, axes = plt.subplots(nrows=2, ncols=3, figsize=(6, 6))
for ax in axes[-1, :]:
ax.set_ylabel('My Ylabel')
fig.tight_layout()
现在您可以直接使用 Axes
对象进行绘图和自定义,而不是 plt
状态机和界面("explicit is better than implicit" 等等)