0

I'm attempting to plot a temperature vs date graph with Matplotlib in Python3. The dates are in increasing order along the x-axis, but the y-axis is not set up from smallest to largest. Matplotlib defines the range seemingly correctly, but then the y-axis doesn't begin at the smallest value and the order becomes more incorrect at the top of the plot as seen here: y-axis view

The code I'm using to plot is below. The data comes from a dictionary with four keys (ie: US...) that each have four lists as their values. The first contains the dates, the second a maximum temp, then min temp, then average.

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()

The whole plot can be seen here: plot

The whole scripts can be found here: parseNCEI.py though the path would need to be edited to wherever the below file is.

And the file the data is coming from can be found here: 1166240.csv

underasail
  • 63
  • 1
  • 8

1 Answers1

3

As DavidG suggested, I was checking my data and converted the y values from strings to integers and this solved the issue.

underasail
  • 63
  • 1
  • 8