如何使用Python中的pyplot绘制日期与值的折线图?

2024-09-30 18:18:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我在绘制简单的折线图时遇到了问题,在y轴上有数值,其中轴上的日期是:

我的python代码如下:

i = 0       #iterator for weather data
xAxis = []
yAxis = []

for trainingDate in observations[:,0]:                  #getting values in x and y axis for the desired chart
    while weatherAttribute[0][i] != trainingDate:
        xAxis.append(trainingDate)
        yAxis.append(weatherAttribute[1][i])
        i = i + 1
    i = 0

fig=plt.figure()
graph = fig.add_subplot(111)

i = 0
for xdate in xAxis:    #format of xdate is '2007-05-29'
    graph.plot(DT(xdate).strftime("%Y-%b-%d"), yAxis[i])
    i = i + 1

plt.show()

weatherAttribute列表存储日期和值,其中as observations list只有日期。在两个列表的匹配日期上,我希望在图表上显示weatherAttribute列表的相应值。简而言之,期望的图表应该在x轴上有日期,在y轴上有数值。在

但我在这方面面临着错误:

^{pr2}$

错误信息是:

TypeError: 'module' object is not callable

我的进口是:

import datetime as DT
from matplotlib import pyplot as plt

我相信这是一个简单的问题,但我已经查过了,不能解决。我很抱歉,因为我是Python的初学者。感谢您抽出时间等待建议!在


Tags: in列表forasfigpltgraph数值