Re: [Matplotlib-users] Dynamically change X time format while zooming plot?
Are you definately passing through datetime objects, or are you passing through the datetime ordinals / Julian time? Definitely datetime objects: if xtime: min_x = datetime.datetime(, 12, 31, 23, 59, 59) max_x = datetime.datetime(1970, 1, 1, 0, 0, 0) def parse_x(x): try: return dateutil.parser.parse(x) except ValueError: print sys.stderr, Can't parse, repr(x), as a timestamp. raise ... You're suggesting that I shouldn't have to do anything with formatters and locators if my X values are datetime objects? Maybe I should simply scrub any locator/formatter initialization altogether. When I first started this little tool I used a FuncFormatter which (unknown to me) performed about like the AutoDateFormatter without the Auto part. It simply selected the X axis format based on the range of the data. Skip -- See everything from the browser to the database with AppDynamics Get end-to-end visibility with application monitoring from AppDynamics Isolate bottlenecks and diagnose root cause in seconds. Start your free trial of AppDynamics Pro today! http://pubads.g.doubleclick.net/gampad/clk?id=48808831iu=/4140/ostg.clktrk ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Dynamically change X time format while zooming plot?
On Fri, Jul 12, 2013 at 8:47 AM, Skip Montanaro s...@pobox.com wrote: Is there some way to get the x axis to display fractions of a second? There is no strftime format character corresponding to that. (I proposed one on python-dev several years ago, but I don't think it was ever adopted.) My memory failed me. I not only proposed, but submitted the necessary patches which were accepted. However, this only works for datetime objects: import datetime datetime.datetime.now().strftime(%H:%M:%S.%f) '08:58:57.854562' It's not supported by time.strftime: import time time.time() 1373637581.478104 time.strftime(%H:%M:%S.%f, time.localtime()) '09:00:10.%f' which I suspect is what matplotlib uses if it converts datetime objects to floats internally. Skip -- See everything from the browser to the database with AppDynamics Get end-to-end visibility with application monitoring from AppDynamics Isolate bottlenecks and diagnose root cause in seconds. Start your free trial of AppDynamics Pro today! http://pubads.g.doubleclick.net/gampad/clk?id=48808831iu=/4140/ostg.clktrk ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Dynamically change X time format while zooming plot?
Let me return to my FuncFormatter usage. As I indicated in an earlier post, I made a single format decision based on the x range of the entire data set. The decision code was straightforward: x_delta = x_range[1] - x_range[0] if x_delta int(1.5 * 365) * ONE_DAY: xfmt = %Y-%m-%d elif x_delta 2 * ONE_DAY: xfmt = %m/%d\n%H:%M elif x_delta 2 * ONE_HOUR: xfmt = %H:%M:%S else: xfmt = %H:%M How do I compute x_delta as it relates to the currently visible window? In the above code, x_range represents the x range of my entire data set. Thx, Skip -- See everything from the browser to the database with AppDynamics Get end-to-end visibility with application monitoring from AppDynamics Isolate bottlenecks and diagnose root cause in seconds. Start your free trial of AppDynamics Pro today! http://pubads.g.doubleclick.net/gampad/clk?id=48808831iu=/4140/ostg.clktrk ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Dynamically change X time format while zooming plot?
I am not at all familiar with dates in matplotlib, but what does plt.xlim() yield? Or are the limits not updated before calling the tick formatter? Bingo! I changed plt to pylab and now I have access to the x range of the current viewport. Thanks, Skip -- See everything from the browser to the database with AppDynamics Get end-to-end visibility with application monitoring from AppDynamics Isolate bottlenecks and diagnose root cause in seconds. Start your free trial of AppDynamics Pro today! http://pubads.g.doubleclick.net/gampad/clk?id=48808831iu=/4140/ostg.clktrk ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Dynamically change X time format while zooming plot?
Skip, I am not at all familiar with dates in matplotlib, but what does plt.xlim() yield? Or are the limits not updated before calling the tick formatter? -Sterling On Jul 12, 2013, at 8:49AM, Skip Montanaro wrote: Let me return to my FuncFormatter usage. As I indicated in an earlier post, I made a single format decision based on the x range of the entire data set. The decision code was straightforward: x_delta = x_range[1] - x_range[0] if x_delta int(1.5 * 365) * ONE_DAY: xfmt = %Y-%m-%d elif x_delta 2 * ONE_DAY: xfmt = %m/%d\n%H:%M elif x_delta 2 * ONE_HOUR: xfmt = %H:%M:%S else: xfmt = %H:%M How do I compute x_delta as it relates to the currently visible window? In the above code, x_range represents the x range of my entire data set. Thx, Skip -- See everything from the browser to the database with AppDynamics Get end-to-end visibility with application monitoring from AppDynamics Isolate bottlenecks and diagnose root cause in seconds. Start your free trial of AppDynamics Pro today! http://pubads.g.doubleclick.net/gampad/clk?id=48808831iu=/4140/ostg.clktrk ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- See everything from the browser to the database with AppDynamics Get end-to-end visibility with application monitoring from AppDynamics Isolate bottlenecks and diagnose root cause in seconds. Start your free trial of AppDynamics Pro today! http://pubads.g.doubleclick.net/gampad/clk?id=48808831iu=/4140/ostg.clktrk ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Dynamically change X time format while zooming plot?
I have a small matplotlib app I wrote to plot columns of a CSV files. The X axis is almost always time. Once displayed, I will often zoom in on a small patch of a plot. I'm currently selecting the strftime format based on the original time range of the input. As I zoom in, however, that doesn't work so well but when I use it in the obvious way, all I get is the current year for all tick labels, despite the fact that the scaled attribute of the formatter has keys which are much smaller than a year. I kind of got this working. I had to associate the locator with the X axis and call it's autoscale() method before calling plot.show(). Now I get %H:%M:%S formatting for everything, even when I'm zoomed way out on a data set containing two-days worth of time series data. I suppose I can fiddle with the AutoDateFormatter's scaled attribute, but the default looks like it ought to work. Any thoughts on what I'm (still) missing? The locator/formatter code looks like this: locator = matplotlib.dates.AutoDateLocator() formatter = matplotlib.dates.AutoDateFormatter(locator) ... left_plot = figure.add_subplot(111) left_plot.set_title(title) left_plot.set_axisbelow(True) left_plot.yaxis.set_major_formatter(pylab.FormatStrFormatter('%g')) ... locator.set_axis(left_plot.xaxis) left_plot.xaxis.set_major_formatter(formatter) locator.autoscale() pylab.show() This works fine except for the lack of dynamic scaling and apparently incorrect choice of labels on plots over large time scales. Skip -- See everything from the browser to the database with AppDynamics Get end-to-end visibility with application monitoring from AppDynamics Isolate bottlenecks and diagnose root cause in seconds. Start your free trial of AppDynamics Pro today! http://pubads.g.doubleclick.net/gampad/clk?id=48808831iu=/4140/ostg.clktrk ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Dynamically change X time format while zooming plot?
I have a small matplotlib app I wrote to plot columns of a CSV files. The X axis is almost always time. Once displayed, I will often zoom in on a small patch of a plot. I'm currently selecting the strftime format based on the original time range of the input. As I zoom in, however, that doesn't work so well. Consider the attached plot. How do I trigger a recalculation of the X axis format? I see this class, which looks promising: http://matplotlib.org/api/dates_api.html#matplotlib.dates.AutoDateFormatter but when I use it in the obvious way, all I get is the current year for all tick labels, despite the fact that the scaled attribute of the formatter has keys which are much smaller than a year. formatter = matplotlib.dates.AutoDateFormatter( matplotlib.dates.AutoDateLocator()) print formatter.scaled The default scaled attribute displays as: {1.0: '%b %d %Y', 365.0: '%Y', 30.0: '%b %Y', 0.041664: '%H:%M:%S'} I'm plotting data now with a range of about four hours, so I think the last format (%H:%M:%S) should be used. Thx, Skip attachment: trend4.png-- See everything from the browser to the database with AppDynamics Get end-to-end visibility with application monitoring from AppDynamics Isolate bottlenecks and diagnose root cause in seconds. Start your free trial of AppDynamics Pro today! http://pubads.g.doubleclick.net/gampad/clk?id=48808831iu=/4140/ostg.clktrk___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users