python - 更改图形大小
问题描述
我需要更改下面代码生成的绘图的图形大小。
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,但不幸的是没有任何改变。我可以尝试什么来解决这个问题?
解决方案
尝试以下操作:
- 创建所需大小的图形
- 将创建的轴传递给
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
推荐阅读
- ssl - GKE、NGINX 入口、HTTPS 和证书
- c# - 如何从 WinForms 中的“图形”字符串元素中选择/复制文本
- encoding - 有效地将位数组编码为有限的字母表
- python - 使用 redshift SQL 分解长字符串的最佳方法(包含在问题中)?
- swift - Swift 弱引用比强引用慢得多
- elasticsearch - 如何使用 CURL 将 CSV 上传到 AWS elasticsearch?
- python-3.x - 如何使用正则表达式过滤数据框列?
- javascript - 在 JS 中播放音频
- javascript - Nextjs getInitialProps 错误阻止在 Netlify 上构建
- python - 在 Python 中处理时,如何确保在短路点之后不会急切地评估任意函数调用列表?