我正在尝试在我的图中的多个轴上绘制直方图。下面的脚本可以实现,但是我无法为每个
我想为每个
到目前为止,我的输出如下所示。你可以看到刻度混乱,特别是在最后一个
脚本如下:
ax
标准化x/y刻度,即没有重叠,每个ax都有一个公共间隔范围。我想为每个
ax
指定x/y刻度,而不是为整个图设置全局刻度。到目前为止,我的输出如下所示。你可以看到刻度混乱,特别是在最后一个
ax
中。我已经尝试过ax_set_x/yticks、plt.x/yticks等方法,但我相信我做错了什么。非常感谢!![enter image description here](https://istack.dev59.com/N9OmC.webp)
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as ss
data = np.random.normal(0.0005, 0.001,1000)
data2 = np.random.normal(0.0004, 0.001,1000)-data
diff = {k:[data, data2] for k in range(3)}
for k in diff:
print k
ttls= ['SC2 vs SC1', 'SC4 vs SC3','SC6 vs SC5']
colors = ['chocolate', 'green']
leg = ['var1', 'var2']
bins = 100
fig, axes = plt.subplots(nrows=3, ncols=1, figsize=(8.27, 11.69))
fig.add_subplot(111, frameon=False)
fig.suptitle('Normed Histograms', color='#6E6E6E', fontsize=10, fontweight='bold')
for ax, ttl, arr in zip(axes, ttls, diff.itervalues()):
ax.hist((arr[0], arr[1]),bins, histtype='stepfilled', density=True, color=colors, label=leg, alpha=0.70)
for i, v in enumerate(arr):
mean = np.mean(v)
std = np.std(v)
xRange = np.linspace(np.min(v), np.max(v))#, len(cs))
nd = ss.norm.pdf(xRange, mean, std)
if i == 0:
socNd = ax.plot(xRange, nd, color='r', alpha=0.70, linewidth=0.8, label="fitted PDF*")
socLine = ax.axvline(mean, color=colors[0], linestyle = ':',linewidth=2, label="Mean value")
if i == 1:
bcNd = ax.plot(xRange, nd, color='r', alpha=0.70, linewidth=0.8)
bcLine = ax.axvline(mean, color=colors[1], linestyle = ':',linewidth=2)
ax.set_title(ttl, loc='left', color='#6E6E6E', fontsize=8.5, fontweight='bold', pad=12)
ax.set_ylabel("Frequency", color='#6E6E6E', fontsize=8)
axes[2].legend(loc='lower center', bbox_to_anchor=(0.5, -0.5),ncol=4)
axes[2].set_xlabel("xlabel", fontsize=8, labelpad=3)
plt.subplots_adjust(hspace=0.7)
plt.show()
fig.add_subplot(111, frameon=False)
。 - DavidG