Pandas:将一个图拆分为多个子图,同时保持s

2024-09-27 22:18:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个150个值的条形图。
代码是:
rcParams.update({'figure.自动布局':真}) plt.图(尺寸=(14,9),dpi=600)

reso_names = [x[0] for x in resolution3]
reso_values = [x[1] for x in resolution3]

plt.bar(range(len(reso_values[0:20])), reso_values[0:20], align='center')
plt.xticks(range(len(reso_names[0:20])), list(reso_names[0:20]), rotation='vertical')

plt.margins(0.075)
plt.xlabel('Resolution Category Tier 3')
plt.ylabel('Volume')
plt.title('Resolution Category Tier 3 Volume', {'family' : 'Arial Black',
        'weight' : 'bold',
        'size'   : 22})

plt.savefig('Reso3.pdf', format='pdf')
plt.show()

因为我想把它分成20个子图来保持可读性,所以我在reso_名称和reso_值处使用[0:20](两个列表)。

然而,问题是尺度不能被保持,每个子图有非常不同的尺度,这是一个没有保持一致性的问题。我如何设置一个可以在所有图形中保持的比例。在


Tags: inforlenpdfnamesrangeplttier
1条回答
网友
1楼 · 发布于 2024-09-27 22:18:09

您可以指定sharey=True以保持所有子批次中的y刻度相同。在

import numpy as np
import matplotlib.pyplot as plt

x = np.random.randint(1, 10, 10)
y = np.random.randint(1, 100, 10)

fig, axes = plt.subplots(nrows=1, ncols=2, sharey=True)
# do simple plot here, replace barplot yourself
axes[0].plot(x)
axes[1].plot(y)

enter image description here

或者,如果您希望单独打印它们,您可以手动配置ax.set_ylim()。在

相关问题 更多 >

    热门问题