Yaxis未正确排序matplotlib

2024-10-02 14:15:55 发布

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

我试图用Python3中的Matplotlib绘制温度与日期的关系图。日期沿x轴按递增顺序排列,但y轴不是从最小到最大。Matplotlib似乎正确地定义了范围,但是y轴并不是从最小的值开始的,并且在图的顶部顺序变得更加不正确,如下所示:y-axis view

我用来绘图的代码如下。数据来自一个有四个键(即:US…)的字典,每个键都有四个列表作为它们的值。第一个包含日期,第二个是最高温度,然后是最低温度,然后是平均温度。在

from matplotlib import pyplot
...
pyplot.figure(figsize = (250, 20))
pyplot.plot(\
station_dict['USW00012839'][0], station_dict['USW00012839'][1], 'b-', \
station_dict['USC00081306'][0], station_dict['USC00081306'][1], 'b-', \
station_dict['USW00092811'][0], station_dict['USW00092811'][1], 'b-', \
station_dict['USC00085667'][0], station_dict['USC00085667'][1], 'b-', \
station_dict['USW00012839'][0], station_dict['USW00012839'][2], 'g-', \
station_dict['USC00081306'][0], station_dict['USC00081306'][2], 'g-', \
station_dict['USW00092811'][0], station_dict['USW00092811'][2], 'g-', \
station_dict['USC00085667'][0], station_dict['USC00085667'][2], 'g-', \
station_dict['USW00012839'][0], station_dict['USW00012839'][3], 'r-', \
station_dict['USC00081306'][0], station_dict['USC00081306'][3], 'r-', \
station_dict['USW00092811'][0], station_dict['USW00092811'][3], 'r-', \
station_dict['USC00085667'][0], station_dict['USC00085667'][3], 'r-' \
)
pyplot.title('Miami Temperature from August 2015 to December 2017\n', \
size = 'x-large', weight = 'bold')
pyplot.ylabel('Temperature (Fahrenheit)', style = 'italic')
pyplot.xlabel('Date', style = 'italic')
pyplot.xticks(rotation = 'vertical')
pyplot.show()

整个情节可以在这里看到:plot

整个脚本可以在这里找到:parseNCEI.py 尽管路径需要编辑到下面文件所在的位置。在

数据来源的文件可以在这里找到:1166240.csv


Tags: 数据fromplotmatplotlibstyle温度dicttemperature

热门问题