【发布时间】:2017-12-07 19:07:05
【问题描述】:
我想根据数据跨度自动缩放共享 x 轴图形的子图的垂直高度!我想比较显示数据的相对强度。如果我对 subbplots 使用 sharey=True kwarg,则数据以相对强度可识别的方式显示:
import matplotlib.pyplot as plt
from matplotlib import gridspec
import numpy as np
SIZE = (12, 8) #desired overall figure size
# Simple data to display in various forms
x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x ** 2)
y2 = 2*(np.sin(x ** 2))
y3 = 3*(np.sin(x ** 2))
fig, ax = plt.subplots(3,ncols=1, sharex=True, sharey=True)
fig.set_size_inches(SIZE[1], SIZE[0])
fig.subplots_adjust(hspace=0.001)
ax[0].plot(x, y)
ax[1].plot(x, y2)
ax[2].plot(x, y3)
plt.show()
所有子图现在都具有相同的高度,并且 y 轴上的数据跨度是可识别的,因为数据以正确的相对比例显示。 我想要实现的是每个绘图的比例都在数据结束的地方结束。基本上消除了未使用的空白。子图的大小将代表数据的相对高度比。它们在 Y 轴上仍应具有相同的缩放比例,以便查看者估计相对数据高度(例如,它是一个计数)。
我找到了类似问题的以下链接,但没有一个真正帮助我解决我的问题:
【问题讨论】:
标签: python matplotlib height subplot