我使用以下代码在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参数放在哪里。
发布于 2018-06-28 18:35:58
您可以使用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)

发布于 2018-06-28 19:12:09
要做到这一点,最好的方法是遵循更面向对象的方法:
fig, ax = plt.subplots(figsize=(12,12))
ax.bar(x + 0.0, y, color = 'b', width = 0.5)
ax.bar(x + 0.5, z, color = 'g', width = 0.5)
ax.legend(['Old Cluster', 'New Cluster'])
fig.savefig("C:\\Users\\utkarsh.a.ranjan\\Documents\\pyqt_data\\generate_results\\bar", bbox_inches='tight',pad_inches=0.1)
plt.clf()您可能还想在文件名中添加格式。如果没有,格式取自rc参数savefig.format,该参数通常为png。
顺便说一句,如果你想尽可能地坚持你的代码,你也可以在你的plt.bar(...)之前添加这一行
plt.figure(figsize=(12,12))发布于 2021-06-19 15:43:52
增加绘图大小的一个非常简单的方法是只需在代码之前添加以下代码行:
plt.rcParams["figure.figsize"] = (10, 5)您可以根据自己的意愿更改图形大小。
https://stackoverflow.com/questions/51080491
复制相似问题