我正在尝试在绘图的多个轴上绘制直方图。我下面的脚本正在执行此操作,但是我根本无法标准化每个ax
的x / y刻度,即没有重叠,每个斧头的间隔范围都相同。
我想为每个ax
指定x / y刻度,而不是为整个图设置全局刻度。
我到目前为止的输出也在下面。正如您所看到的,滴答声被弄乱了,特别是在最后一个ax
中。我已经尝试过ax_set_x / yticks,plt.x / yticks...。但是我很确定我做错了什么。非常感谢!!
脚本:
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()