numpy - Plotting Pandas DataFrames as single days on the x-axis in Python/Matplotlib -
i've got data this:
col1 ;col2 2001-01-01;1 2001-01-01;2 2001-01-02;3 2001-01-03;4 2001-01-03;2 2001-01-04;2
i'm reading in python/pandas using pd.read_csv(...)
dataframe. want plot col2 on y-axis , col1 on x-axis day-wise. searched lot couldn't many useful pages describing in detail. found matplotlib not support dataformat in dates stored in (datetime64).
i tried converting this:
fig, ax = plt.subplots() x = np.asarray(df['col1']).astype(dt.datetime) xfmt = mdates.dateformatter('%b %d') ax.xaxis.set_major_formatter(xfmt) ax.plot(x, df['col2']) plt.show()
but not work. best way? can find bits there , bits there, nothing working in complete , more importantly, up-to-date ressources related functionality latest version of pandas/numpy/matplotlib.
i'd interested convert absolut dates consecutive day-indices, i.e: starting day 2001-01-01 day 1, data this:
col1 ;col2 ; col3 2001-01-01;1;1 2001-01-01;2;1 2001-01-02;3;2 2001-01-03;4;3 2001-01-03;2;3 2001-01-04;2;4 ..... 2001-02-01;2;32
thank in advance.
ok far can see there's no need anymore use matplotlib
directly, instead pandas offer plotting functions can used methods dataframe-objects, see http://pandas.pydata.org/pandas-docs/stable/visualization.html. these functions use matplotlib, easier use because handle datatypes correctly :-)
Comments
Post a Comment