简体   繁体   中英

Plotting Days of the year Python

I am trying to plot time(axis-x) vs flow(axis-y). My data series "time" is Days of the year but it goes from 1 to 365. Any way to have the plot show on the x axis days/months (So Jan 1st would be 1-1, Feb 1st 1-2,...,Dec 1st 1-12) of the year instead of 1,2,3,4,5 all way to 365? Or do I need to add another column with the dates?

from matplotlib import pyplot
enter code from matplotlib import pyplot
from math import log
time = list(mom6[0])
flow = list(mom6[1])
pyplot.scatter(x,y,linestyle = '--')
pyplot.ylabel('Flow (cfs)')
pyplot.xlabel('Time')
pyplot.title('Flow Duration')
pyplot.yscale('log')
plt.grid(True)
plt.show()here

Also for pyplot.scatter(x,y,linestyle = '-') it will not connect the points. Also my array looks like:

  1,972
  10,847
  100,2234
  .
  .
  .
  365,1990

Best

You could use datetime to do the conversion:

(for insertion just after time = list(mom6[0]) ):

import datetime
start = datetime.date(2015, 1, 1)
dts = [ start + datetime.timedelta(days=int(ea)-1) for ea in time ]
time = [ ea.strftime('%d-%m') for ea in dts ]

Results in:

>>> time[:5]
>>> ['01-01', '02-01', '03-01', '04-01', '05-01']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM