我正在尝试使用 for 循环将多个图形绘制为 1,但我遇到了这个问题。我为其他循环尝试了它,它工作得很好,但我不知道这个循环发生了什么。
使用的文件是过去 2 年欧元兑美元的汇率,我试图在图表上绘制日期和价格。如果我不使用 figsize 图表太小但它的工作原理。
import pandas as pd
import matplotlib.pyplot as plt
file = ['somefile.csv', 'otherfile.csv', 'anotherfile.csv']
for files in file:
files1 = pd.read_csv ('%s' %files)
files1.plot (kind='line', x='Date', y='Price', ax=ax, figsize=(15,10))
plt.legend()
plt.show()
Run Code Online (Sandbox Code Playgroud)
一种解决方法是使用
plt.gcf().set_size_inches(15, 8))
Run Code Online (Sandbox Code Playgroud)
所以你的代码应该是
import pandas as pd
import matplotlib.pyplot as plt
file = ['somefile.csv', 'otherfile.csv', 'anotherfile.csv']
for files in file:
files1 = pd.read_csv ('%s' %files)
files1.plot (kind='line', x='Date', y='Price', ax=ax)
plt.gcf().set_size_inches(15, 8))
plt.legend()
plt.show()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8004 次 |
| 最近记录: |