【发布时间】:2015-12-28 18:34:23
【问题描述】:
我有以下代码,其中只有 ax3 显示绘图区域和数据。子图 ax1 和 ax2 显示绘图区域但没有数据。最终,我想要三个带有 sharex=True 的图(3、1 配置)。我正在使用 Python 2.7.2 和 matplotlib 1.2.1
import numpy as np
import matplotlib.pyplot as plt
f, (ax1, ax2, ax3) = plt.subplots(3, 1, sharex=True, sharey=False)
f.subplots_adjust(wspace=0)
N = 4
ind = np.arange(N)
width = .4
group_names = ('A', 'B', 'C', 'D')
q2 = [84, 21, 10, 4]
q4 = [69, 34, 22, 0]
q6 = [66, 28, 17, 2]
colors = ['c', 'purple', 'g', 'red']
ax1 = plt.barh(ind, q2, width, color=colors)
plt.yticks(ind+width/N, group_names)
plt.ylim([min(ind)-0.25, max(ind)+0.65])
plt.xticks(np.arange(0, 110, 10.))
plt.xlim(0, 100)
ax2 = plt.barh(ind, q4, width, color=colors)
plt.yticks(ind+width/N, group_names)
plt.ylim([min(ind)-0.25, max(ind)+0.65])
plt.xticks(np.arange(0, 110, 10.))
plt.xlim(0, 100)
ax3 = plt.barh(ind, q6, width, color=colors)
plt.yticks(ind+width/N, group_names)
plt.ylim([min(ind)-0.25, max(ind)+0.65])
plt.xticks(np.arange(0, 110, 10.))
plt.xlim(0, 100)
plt.show()
【问题讨论】:
-
为什么在这里使用
plt.barh?而是使用ax1.barh等直接绘制到您的轴上。 -
顺便说一句,
matplotlib v1.2.1已经两岁半了。1.4.3是当前的稳定版本。您可能会考虑更新您的版本
标签: python matplotlib subplot