Hello
I’d like to know wether Matplotlib can display data with an x axis based on day, hour, minute and seconds.
I found some example and tutorial that shows that this can be done for year, month and day but not for hour, minute, seconds.
It looks like matplotlib use the python type date and generate a list of date within a range (at least in the tutorials).
I’d like to do the same thing but with customized date and time for each of my points.
So my questions would be : can the plot function display some values with a certain time (and if possible date) for each one of the values ? Or, can the plot function use a time object as parameter for x axis ?
I also would like to know wether I can use the same type of functionnality as in
Gnuplot where you can specify the format of data in input and the data
displayed of the x axis. I just guess that the use of the date object replace any kind of setup in data input but anyway…
Thanks
Regards
Johan Mazel
If you are passing in datetime objects for plotting on the x-axis, you
can format the tick labels any way you want:
import matplotlib.ticker
formatter = ticker.DateFormatter('%Y-%m-%d %H:%M:%S')
ax.xaxis.set_major_formatter(formatter)
See the date_demo*.py examples at http://matplotlib.sf.net/examples
···
On Tue, Apr 29, 2008 at 8:12 AM, Johan Mazel <johan.mazel@...287...> wrote:
I also would like to know wether I can use the same type of functionnality
as in Gnuplot where you can specify the format of data in input and the data
displayed of the x axis. I just guess that the use of the date object
replace any kind of setup in data input but anyway...
Ok.
I manage to get either time or date but not both inside the same object .
And I don’t know how to use plot with two object (one for the time and the other for the date).
Thanks for the answer.
Johan Mazel
2008/4/29 John Hunter <jdh2358@…287…>:
···
On Tue, Apr 29, 2008 at 8:12 AM, Johan Mazel <johan.mazel@…287…> wrote:
I also would like to know wether I can use the same type of functionnality
as in Gnuplot where you can specify the format of data in input and the data
displayed of the x axis. I just guess that the use of the date object
replace any kind of setup in data input but anyway…
If you are passing in datetime objects for plotting on the x-axis, you
can format the tick labels any way you want:
import matplotlib.ticker
formatter = ticker.DateFormatter(’%Y-%m-%d %H:%M:%S’)
ax.xaxis.set_major_formatter(formatter)
See the date_demo*.py examples at http://matplotlib.sf.net/examples
you can get the date and time into a datetime object as follows:
import datetime
dt = datetime.datetime(2008,4,22,3,45,21)
print dt.strftime('%Y-%m-%d %H:%M:%S')
···
On Tue, Apr 29, 2008 at 11:38 AM, Johan Mazel <johan.mazel@...287...> wrote:
Ok.
I manage to get either time or date but not both inside the same object .
And I don't know how to use plot with two object (one for the time and the
other for the date).