python - Plotting timestamps (hour/minute/seconds) with Matplotlib -
i want plot timestamps (year-month-day hour-minute-second format). using following code, doesn't show hour-minute-second information, shows them 00-00-00. double checked date array, , can see snippet below, not zero.
do have idea why getting 00-00-00's?
import matplotlib.pyplot plt import matplotlib.dates md import dateutil dates = [dateutil.parser.parse(s) s in datestrings] # datestrings = ['2012-02-21 11:28:17.980000', '2012-02-21 12:15:32.453000', '2012-02-21 23:26:23.734000', '2012-02-26 17:42:15.804000'] plt.subplots_adjust(bottom=0.2) plt.xticks( rotation= 80 ) ax=plt.gca() xfmt = md.dateformatter('%y-%m-%d %h:%m:%s') ax.xaxis.set_major_formatter(xfmt) plt.plot(dates[0:10],plt_data[0:10], "o-") plt.show()
try zooming in on graph, see datetimes expand x axis scale changes.
plotting unix timestamps in matplotlib
i had annoying problem when trying plot heatmaps of positive selection on chromosomes. if zoomed out far things disappear entirely!
edit: code plots dates give them, doesn't add ticks in between.
import matplotlib.pyplot plt import matplotlib.dates md import dateutil datestrings = ['2012-02-21 11:28:17.980000', '2012-02-21 12:15:32.453000', '2012-02-21 23:26:23.734000', '2012-02-26 17:42:15.804000'] dates = [dateutil.parser.parse(s) s in datestrings] plt_data = range(5,9) plt.subplots_adjust(bottom=0.2) plt.xticks( rotation=25 ) ax=plt.gca() ax.set_xticks(dates) xfmt = md.dateformatter('%y-%m-%d %h:%m:%s') ax.xaxis.set_major_formatter(xfmt) plt.plot(dates,plt_data, "o-") plt.show()
Comments
Post a Comment