【发布时间】:2018-07-12 16:20:07
【问题描述】:
我有一个关于使用 matplotlib 的子图的每行共享 y 轴的问题。
我以以下脚本为例。当我在 subplots 函数中使用sharey=True 作为参数然后ax[x, x].set_ylim(n, n) 然后它使用我使用的最后一个参数。
import matplotlib.pyplot as plt
fig, ax = plt.subplots(3, 2, figsize=(8, 10), sharey=True, gridspec_kw={'height_ratios': [1, 2, 2]})
ax[0, 0].set_ylim(-1.5, 1.5)
ax[1, 0].set_ylim(-40, 40)
ax[1, 1].set_ylim(-40, 40)
ax[2, 0].set_ylim(-40, 40)
ax[2, 1].set_ylim(-40, 40)
有没有一种方法可以共享每行的 y 轴?
【问题讨论】:
-
您可以找到一个如何做到这一点的示例here。简短回答:
f, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, sharex='col', sharey='row').
标签: python python-3.x matplotlib subplot