我想根据共享x轴图形的数据跨度自动缩放子图的垂直高度!我想比较显示数据的相对强度。如果我将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轴上仍应具有相同的缩放比例,以便查看者估计相对数据高度(例如,cold是一个计数率)。在
我发现了以下与类似问题相关的链接,但没有一个真正帮助我解决问题:
下面是一个为您确定比率并相应创建子批次的示例:
代码确定每组数据的最大y扩展,将其转换为一个整数,然后使用这些扩展的总和作为
GridSpec
的比例将图形划分为子图。在结果图如下:
在Python3.5上测试
编辑:
如果数据的最大和最小范围不可比较,最好将
^{pr2}$hs
的计算方式改为相关问题 更多 >
编程相关推荐