首页 > 解决方案 > 更改图形大小

问题描述

我需要更改下面代码生成的绘图的图形大小。

import matplotlib.pyplot as plt
%matplotlib inline

df.index = df.Date
df.drop(["Date"],  axis=1, inplace=True)
df.plot(kind="bar", stacked=True)
plt.xticks(rotation = 45)
plt.figure(figsize=(20,8))
plt.show()

在 x 轴上,我有 100 天,数据目前不易读取。我曾尝试使用 plt.figure,但不幸的是没有任何改变。我可以尝试什么来解决这个问题?

标签: pythonmatplotlib

解决方案


尝试以下操作:

  1. 创建所需大小的图形
  2. 将创建的轴传递给df.plot()命令

fig, ax = plt.subplots(figsize=(20, 8)) # <---- Create the figure of desired size

df.index = df.Date
df.drop(["Date"],  axis=1, inplace=True)
df.plot(kind="bar", stacked=True, ax=ax) # <---- Pass the created axis to plot

推荐阅读