子图大小/刻度间隔pyplot

时间:2016-08-30 17:23:20

标签: python matplotlib subplot

我搜索过类似的问题而没有发现任何问题,所以我道歉。

我有这个:

import matplotlib.pyplot as plt

yearlymean_gm = np.load('ts_globalmean_annualmean.npz')
ts = yearlymean_gm['ts_aqct']

time = np.arange(0., 45 , 1)
plt.figure( figsize=(12, 5), dpi=80, facecolor='w', edgecolor='k' )

ax = plt.subplot(3, 4, 1)

data = ts[0, :]
plt.plot(time, data)
plt.title('Annual Mean Global Mean Temperature', fontsize=14)
plt.xlabel('year', fontsize=12)
plt.ylabel(modnames[0], fontsize=12)
plt.xlim(0, 50), plt.ylim(275, 310)
ax.set_xticks(time)
ax.set_xticklabels(time, fontsize = 8)

ax= plt.subplot(3, 4, 2)

data = ts[1, :]
plt.plot(time, data)
plt.title('Annual Mean Global Mean Temperature', fontsize=14)
plt.xlabel('year', fontsize=12)
plt.ylabel(modnames[1], fontsize=12)
plt.xlim(0, 50), plt.ylim(275, 310)
ax.set_xticks(time)


ax = plt.subplot(3, 4, 3)

data = ts[2, :]
plt.plot(time, data)
plt.title('Annual Mean Global Mean Temperature', fontsize=14)
plt.xlabel('year', fontsize=12)
plt.ylabel(modnames[2], fontsize=12)
plt.xlim(0, 50), plt.ylim(275, 310)
ax.set_xticks(time)


plt.tight_layout()
plt.show()
plt.close

目前有9个缺失的地块,我相信你可以猜到,Here's what it's spitting out right now

以下是三个问题,需要明确: 1)每个子图是 tiny 与图形的大小相比(并且,你知道......什么是容易看到的)。减小图形的大小不会使子图更容易阅读。

2)他们太靠近了。我对如何解决这个问题有一些想法,但我觉得我需要先解决1)。

3)轴非常小,以至于xticks全部聚集

我已经搜索过,并没有找到关于如何做到这一点的解释,这是我能理解的水平。 pyplot文档对我来说基本上是胡言乱语。

提前感谢您的任何帮助(如果有人能提供更多有关我正在做的事情的一般性建议,除了有关解决此问题的具体建议外,我将非常感谢您的启发。)

1 个答案:

答案 0 :(得分:2)

好的,这里发生了好几件事。我们一次一个地通过它们。实例化绘图后,调用git fetch /wp-contents/themes master git merge -s ours --no-commit FETCH_HEAD git read-tree --prefix=wp-contents/themes -u FETCH_HEAD git commit -m "message" 3次。但是,ax = plt.subplot(3, 4, _)将绘图分为3行和4列,下划线选择从1开始选择此网格的哪一部分(而不是0)。我们可以使用以下代码对它们进行编号:

.subplot(3,4,_)

enter image description here

但是,使用plt.figure( figsize=(12, 5), dpi=80, facecolor='w', edgecolor='k' ) for N in range(1,13): ax = plt.subplot(3, 4, N) ax.annotate(s=str(N), xy=(.4,.4), fontsize=16) .subplot(3,4,1).subplot(3,4,2),您只需选择12个部分中的前3个部分。

当您将数据添加到绘图中时,.subplot(3,4,3)会向x轴添加45个刻度(这是很多),ax.set_xticks(time)在每个刻度处添加一个标签。这就是它看起来如此拥挤的原因。一种选择是减少刻度数,另一种是将x轴拉伸。由于你有3个子图,我想你想要垂直堆叠3行。

您不需要ax.set_xticklabels(time, fontsize = 8)plt.xlim(0, 50)。除非您有特定原因要覆盖它们,否则轴将为您调整绘图限制。

我的建议是使用plt.ylim(275, 310)(注意额外的" s"),而不是重复拨打plt.subplots(3,1)。有什么区别? plt.subplot返回plt.subplots(3,1)对象的元组和figure个对象的数组。在这种情况下,它是一维数组,因为我们只需要一列。 (注意:我出于说明目的创建了假数据。)

axis

enter image description here