【问题标题】:Pandas: Splitting a Graph into many sub graphs while maintaining scalePandas:在保持规模的同时将图拆分为许多子图
【发布时间】:2015-09-22 15:14:13
【问题描述】:

我有一个包含 150 个值的条形图。
代码是:
rcParams.update({'figure.autolayout': True}) plt.figure(figsize=(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_names 和 reso_values(两个列表。

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

【问题讨论】:

    标签: python pandas matplotlib graph


    【解决方案1】:

    您可以指定 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)
    

    或者如果你喜欢单独绘制它们,你可以手动配置ax.set_ylim()

    【讨论】:

    • 在我的代码中应该把命令放在哪里?我没有使用 plot 命令。
    猜你喜欢
    • 2021-11-19
    • 2022-06-21
    • 1970-01-01
    • 2013-08-11
    • 2021-01-27
    • 2015-10-24
    • 1970-01-01
    • 2022-11-30
    • 2014-11-20
    相关资源
    最近更新 更多