[SciPy-user] Still having plotting issue with latest svn scikits.timeseries

Pierre GM pgmdevlist@gmail....
Wed Dec 10 12:02:41 CST 2008

On Dec 10, 2008, at 12:32 PM, Dharhas Pothina wrote:
> When I read a datafile in and try to plot it, Whether it plots  
> correctly or not depends on what symbols I use in the plot.

I'm very, very surprised. Most likely, some dates get messed up and  
don't show up where you expect them.
The plotlib routines only deal with where the data should be, not how  
it is plotted.

* When you create a tsplot, you need to specify an associated series  
with the 'series' keywords. This series will control the behavior of  
the axes. OK, let me get a tad deeper here:
Rmmbr that a DateArray is basically nothing but a int ndarray with  
some extra candy. The frequency parameter controls how the dates are  
converted to integers, and vice-versa. For example, today (12/10/2008)  
is associated with 733386 if you use a daily frequency (that's the  
corresponding gregorian proleptic day), with 24096 if you use a  
monthly frequency, or simply 2008 if you use an annual frequency.

Plotting a series with tsplot just amounts to plot a standard masked  
array with a given set of integers as x coordinates (the dates).
If you don't give a series when you create a tsplot, the first series  
to be plotted will be associated with the plot. Its frequency will  
dictate how dates are converted.
So, if you plot series #1 with a daily frequency and then series #2  
with a monthly frequency on the same graph, some conversion should  
happen to make sure that the dates of #2 are actually expressed in the  
same frame as series #1. Normally, that happens in the background when  
you plot series one after the other, using one command for each  
series. If you try to plot several series at once using a single  
command, the conversion will happen provided that a frequency was  
already associated with the plot.

> If I convert the timeseries using the .convert or .asfreq methods  
> the plots work without a problem.

Which is a strong hint that the dates get messed up before you plot.  
Are you trying to plot several series with different frequencies ?

> Since I can plot after converting using .asfreq this isn't too much  
> of a problem but I was wondering if there is a bug or whether a  
> warning should be thrown.

A bug is always possible, but I would tend to think it's a misuse of  
the function on your side here. Then, of course, the doc could be  

> The dataset and commands I used are below.

OK, thx for the dataset, but please, don't copy-paste directly from  
ipython. Just send us the commands, without a prompt (the In[...]), in  
a script if you prefer. Right now, I don't have time to spend on  
removing these extra characters to check what's going on.

> thanks,
> - dharhas
>>>> "Dharhas Pothina" <Dharhas.Pothina@twdb.state.tx.us> 12/5/2008  
>>>> 11:26 AM >>>
> Hi,
> I'm attaching a ascii datafile called JDM3_short.txt and the  
> commands I typed in ipython to reproduce the problem. The first  
> figure works the second has the correct axes but is blank.
> In [2]: import sys
> In [3]: import subprocess
> In [4]: from numpy import *
> In [5]: from pylab import *
> In [6]: import datetime
> In [7]: import scikits.timeseries as ts
> In [8]: import scikits.timeseries.lib.plotlib as tpl
> In [9]: import numpy.ma as ma
> In [10]: fieldfile='JDM3_short.txt'
> In [11]: year, month, day, hour, minute, fdata =  
> loadtxt(fieldfile,comments="#",usecols=(0,1,2,3,4,8),unpack=True)
> In [12]: fielddates =  
> [datetime.datetime(int(y),int(m),int(d),int(hh),int(mm),0) for  
> y,m,d,hh,mm in zip(year,month,day,hour,minute)]
> In [13]: fdates = ts.date_array(fielddates,freq='MIN')
> In [14]: fseries = ts.time_series(fdata, dates=fdates)
> In [15]: #remove -999.9 nodata values fo parameter
> In [16]: fseries[fseries==-999.9] = ma.masked
> In [17]:
> In [18]: fseries = fseries.fill_missing_dates()
> In [19]: fig = tpl.tsfigure()
> In [20]: fsp = fig.add_tsplot(111)
> In [21]: fsp.tsplot(fseries, '.')
> Out[21]: [<matplotlib.lines.Line2D object at 0x23cafd0>]
> In [22]: fig1 = tpl.tsfigure()
> In [23]: fsp1 = fig1.add_tsplot(111)
> In [24]: fsp1.tsplot(fseries, 'b', label='data')
> Out[24]: [<matplotlib.lines.Line2D object at 0x3109650>]
> In [25]: show()
> - dharhas
>>>> "Dharhas Pothina" <Dharhas.Pothina@twdb.state.tx.us> 12/05/08  
>>>> 10:42 AM >>>
> Ok I've narrowed it down. It has nothing to do with plotting two  
> timeseries. The problem is plotting the any of the original  
> timeseries I read from files. Once I convert them to daily means the  
> plotting works fine.
> With the original timeseries whether it plots or not seems to depend  
> on what plotting symbol I use.
> - dharhas
>>> If I use two commands and certain other symbols like 'b',b--' etc
>>> for the first series, it only plots the second series :
>> ??? can't reproduce this one...
> I've double checked, its happening consistently with multiple  
> datasets (The datasets are similar just at different locations). How  
> do I track down the problem? Should I send you a datafile and my  
> short script?
> <JDM3_short.txt><Part. 
> 002>_______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user

More information about the SciPy-user mailing list