gpt4 book ai didi

python - Matplotlib:如何更改双条形图的图大小

转载 作者:行者123 更新时间:2023-12-02 00:35:12 25 4
gpt4 key购买 nike

我使用以下代码在 matplotlib 中绘制了双条形图:

x = pd.Series(range(12))
y = self.cust_data['Cluster_ID'].value_counts().sort_index()
z = self.cust_data['Cluster_ID_NEW'].value_counts().sort_index()
plt.bar(x + 0.0, y, color = 'b', width = 0.5)
plt.bar(x + 0.5, z, color = 'g', width = 0.5)
plt.legend(['Old Cluster', 'New Cluster'])
plt.savefig("C:\\Users\\utkarsh.a.ranjan\\Documents\\pyqt_data\\generate_results\\bar", bbox_inches='tight',pad_inches=0.1)
plt.clf()

我想使用Figsize参数来使结果图的尺寸更大。绘制单个条形图时这很容易,但在这里我很困惑将 Figsize 参数放在哪里。

最佳答案

您可以使用figsize设置大小

import matplotlib.pyplot as plt

f, ax = plt.subplots(figsize=(18,5)) # set the size that you'd like (width, height)
plt.bar([1,2,3,4], [0.1,0.2,0.3,0.4], label = 'first bar')
plt.bar([10,11,12,13], [0.4,0.3,0.2,0.1], label = 'second bar')
ax.legend(fontsize = 14)

enter image description here

关于python - Matplotlib:如何更改双条形图的图大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51080491/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com