formatter for durations of varying units

I need to make a dates (on x) vs. durations of time (on y) plots and
need to have smart formatting for the y axis. My y data is in the
database in the format: '0:00:02.994000', (that is, 2.9 seconds) and
I'd like the y axis to be expressed in ticks of, e.g., "2 hrs", or "10
minutes", or "25 seconds", whichever is applicable...see below.

The data could range from as little as a few seconds to more than 12
hours. Sometimes there will be outliers that are in a different unit.
E.g., there may be a plot in which most durations are 1-3 hrs, but now
and then there is a datapoint of 5 minutes, or even 30 seconds. Or it
could be another one with mostly datapoints in minutes, but an
occasional long or short one in hours or seconds.

I want to pick a good (dynamic, for zooming) way to format the y axis.
There are two issues:

1) Should I analyze the data to see what units the majority of
datapoints are in and then use that as the y axis units before
zooming? That is, if most are durations of minutes, then the y axis
should be given in minutes. If most are in hours, the y axis should be
hours, etc... This way the formatting is appropriate for the majority
of the data displayed.

2) If a plot's y units are given in terms of minutes (because of point
#1), but a user wants to zoom in on a datapoint that is only a few
seconds, I'd like the formatter to change the y scaling to be in terms
of seconds. I don't want to have express durations on the y axis as
anything like "0.0335" minutes, but rather "2 seconds".

Does (1) seem like the right approach? And for 2, is there already a
formatter that is appropriate for this or could be adapted to it?

Suggestions welcome. Thanks,
Che

Hi,

I want to pick a good (dynamic, for zooming) way to format the y axis.
There are two issues:
Does (1) seem like the right approach? And for 2, is there already a
formatter that is appropriate for this or could be adapted to it?

did you try the AutoDateLocator (from matplotlib.dates)?

And if you did so, are there specific problems with this locator?

Maximilian

I hadn't. I am trying now but am stuck on: How can I plot the data
given that, from the database, each datapoint is of the form
''0:00:02.994000'? Is there a way to tell matplotlib to read that as
a time duration?

Thanks,
Che

ยทยทยท

On Tue, Jul 12, 2011 at 3:15 AM, Maximilian Trescher <faucon@...3667...> wrote:

Hi,

I want to pick a good (dynamic, for zooming) way to format the y axis.
There are two issues:
Does (1) seem like the right approach? And for 2, is there already a
formatter that is appropriate for this or could be adapted to it?

did you try the AutoDateLocator (from matplotlib.dates)?