【发布时间】:2021-04-15 18:32:54
【问题描述】:
我想创建一个带有 for 循环的图表。 X 轴绘制正确,甚至 y 轴刻度设置正确,但没有创建实际的折线图。 下面的代码可能有什么问题?
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib
test = {'date':[2012, 2013, 2014, 2015],'val':[9,15,12,20]}
test_df=pd.DataFrame(data=test)
test_df=test_df.set_index('date')
fig, ax = plt.subplots(figsize=(25,25))
for i in range(0, len(test_df)):
ax.plot(test_df.index[i], test_df['val'].iloc[i], color='blue', linewidth=10)
plt.show()
【问题讨论】:
标签: python pandas dataframe for-loop matplotlib