SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Johan M. <joh...@gm...> - 2008年04月29日 13:12:40
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
From: John H. <jd...@gm...> - 2008年04月29日 14:12:07
On Tue, Apr 29, 2008 at 8:12 AM, Johan Mazel <joh...@gm...> 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
From: Johan M. <joh...@gm...> - 2008年04月29日 16:39:00
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 <jd...@gm...>:
> On Tue, Apr 29, 2008 at 8:12 AM, Johan Mazel <joh...@gm...>
> 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
>
From: John H. <jd...@gm...> - 2008年04月29日 16:40:48
On Tue, Apr 29, 2008 at 11:38 AM, Johan Mazel <joh...@gm...> 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).
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')
From: Johan M. <joh...@gm...> - 2008年04月29日 17:13:48
---------- Forwarded message ----------
From: Johan Mazel <joh...@gm...>
Date: 2008年4月29日
Subject: Re: [Matplotlib-users] Plot data with specified time (hour, minute,
second)
To: John Hunter <jd...@gm...>
When you wrote "import matplotlib.ticker", you meant "from matplotlib.dates
import ticker" ?
I think I have a bug or something because I get an error like "ValueError:
setting an array element with a sequence." with a lot of debug stuff from
python and MatPlotLib
The line concerned is the one where I do plot(datetime_list,data_list).
It's very strange because just before I use "my_datetime.strftime("%d %H %M
%S")" with my_datetime as an element of my list and it works perfectly.
Anyway, thanks a lot for the help.
Johan Mazel
2008年4月29日 John Hunter <jd...@gm...>:
> On Tue, Apr 29, 2008 at 11:38 AM, Johan Mazel <joh...@gm...>
> 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).
>
> 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')
>
From: Johan M. <joh...@gm...> - 2008年04月29日 17:26:26
Ok.
I tried to do the job through the old way and it's working.
But I have the latest version (0.91.2). Is it possible that my version
wasn't successfully installed and that an older one is doing the job ?
Anyway, thanks a lot for the (fast) help.
Johan
2008年4月29日 John Hunter <jd...@gm...>:
> On Tue, Apr 29, 2008 at 12:10 PM, Johan Mazel <joh...@gm...>
> wrote:
> > When you wrote "import matplotlib.ticker", you meant "from
> matplotlib.dates
> > import ticker" ?
>
> No sorry, I meant "import matplotlib.ticker as ticker"
>
> > I think I have a bug or something because I get an error like
> "ValueError:
> > setting an array element with a sequence." with a lot of debug stuff
> from
> > python and MatPlotLib
> > The line concerned is the one where I do plot(datetime_list,data_list).
> > It's very strange because just before I use "my_datetime.strftime("%d %H
> %M
> > %S")" with my_datetime as an element of my list and it works perfectly.
>
>
> Possibly your matplotlib version is a bit old. With the latest
> release (0.91.2) you can pass sequences of native datetimes in. For
> older versions, you had to convert your dates to numbers first:
>
> import matplotlib.dates as mpldates
>
> d = mpldates.date2num(datetime_list)
> ax.plot_date(d, ydata)
>
> JDH
>
From: Johan M. <joh...@gm...> - 2008年04月30日 12:53:33
Hello
I think that my problem is linked to the data struture that I'm using for
the dates since my error message is : "ValueError: setting an array element
with a sequence."
I use list data structure, the one that you can declare through :
datetime_list = [].
And maybe I souldn't use this type of data structure and another one.
Regards
Johan Mazel
*
*2008年4月29日 Johan Mazel <joh...@gm...>:
> Ok.
> I tried to do the job through the old way and it's working.
> But I have the latest version (0.91.2). Is it possible that my version
> wasn't successfully installed and that an older one is doing the job ?
> Anyway, thanks a lot for the (fast) help.
> Johan
>
> 2008年4月29日 John Hunter <jd...@gm...>:
>
> > On Tue, Apr 29, 2008 at 12:10 PM, Johan Mazel <joh...@gm...>
> > wrote:
> > > When you wrote "import matplotlib.ticker", you meant "from
> > matplotlib.dates
> > > import ticker" ?
> >
> > No sorry, I meant "import matplotlib.ticker as ticker"
> >
> > > I think I have a bug or something because I get an error like
> > "ValueError:
> > > setting an array element with a sequence." with a lot of debug stuff
> > from
> > > python and MatPlotLib
> > > The line concerned is the one where I do
> > plot(datetime_list,data_list).
> > > It's very strange because just before I use "my_datetime.strftime("%d
> > %H %M
> > > %S")" with my_datetime as an element of my list and it works
> > perfectly.
> >
> >
> > Possibly your matplotlib version is a bit old. With the latest
> > release (0.91.2) you can pass sequences of native datetimes in. For
> > older versions, you had to convert your dates to numbers first:
> >
> > import matplotlib.dates as mpldates
> >
> > d = mpldates.date2num(datetime_list)
> > ax.plot_date(d, ydata)
> >
> > JDH
> >
>
>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /