From: Peter G. <pio...@ho...> - 2004-06-12 05:51:35
|
I found another issue with plot_date. Dont have a simple example yet, and hope that this is something 'obvious' and I don't have to bother. I attach two images showing the issue. I can go get rid of the weird scaling in 'bad.png' when I do: ax.viewLim.intervalx().set_bounds(minXValueImPlotting, maxXValueImPlotting) after: ax.autoscale_view() I also noticed a couple of things inside axes.py, that might be wrong: 1) def get_ylim(self): "Get the y axis range [ymin, ymax]" return self.viewLim.intervalx().get_bounds() should that intervax() be intervaly() ?? 2) panx() and pany() are different as well, but perhaps they should be.. Changin these two things does not fix my problem so it has to be something else - hoping a simple typo. Will try to write a demo script that shows this... (I have matplotlib wrapped into other code so its not really a copy/paste-all type deal). Peter John Hunter wrote: >>>>>>"Michael" == Michael Hauser <ha...@na...> writes: > > > Michael> Hello, I am having a problem with plot_date. I keep > Michael> getting the error: > > Michael> Am I missing something obvious? > >No, there is a bug in plot_date in setting the tick formatter object. >I didn't find this in any of my test or example scripts since all >those explicitly set the formatter and hence hid the bug. At the end >of the Axes.plot_date function in matplotlib.axes, replace > > self.xaxis.set_minor_locator(formatter) > >with self.xaxis.set_major_formatter(formatter) > >and you'll be good to go. Note however that there is a problem with >your script in that the length of your x and y arrays must be the >same. After making the changes above, try > >from datetime import datetime >from matplotlib.dates import EpochConverter >from matplotlib.matlab import * > >times = [1084195314, 1084195375, 1084195436, 1084195497, 1084195557] >vals = [10.2, 11.1, 8.7, 12.1, 12.2] >converter = EpochConverter() >ax = subplot(111) >plot_date(times, vals, converter) >savefig('test') >show() > > > > >------------------------------------------------------- >This SF.Net email is sponsored by the new InstallShield X. >From Windows to Linux, servers to mobile, InstallShield X is the >one installation-authoring solution that does it all. Learn more and >evaluate today! http://www.installshield.com/Dev2Dev/0504 >_______________________________________________ >Matplotlib-users mailing list >Mat...@li... >https://lists.sourceforge.net/lists/listinfo/matplotlib-users > |
From: Peter G. <pio...@ho...> - 2004-06-12 06:01:43
|
hmm... forgot to attach the images... --- I found another issue with plot_date. Dont have a simple example yet, and hope that this is something 'obvious' and I don't have to bother. I attach two images showing the issue. I can go get rid of the weird scaling in 'bad.png' when I do: ax.viewLim.intervalx().set_bounds(minXValueImPlotting, maxXValueImPlotting) after: ax.autoscale_view() I also noticed a couple of things inside axes.py, that might be wrong: 1) def get_ylim(self): "Get the y axis range [ymin, ymax]" return self.viewLim.intervalx().get_bounds() should that intervax() be intervaly() ?? 2) panx() and pany() are different as well, but perhaps they should be.. Changin these two things does not fix my problem so it has to be something else - hoping a simple typo. Will try to write a demo script that shows this... (I have matplotlib wrapped into other code so its not really a copy/paste-all type deal). Peter John Hunter wrote: >>>>>>"Michael" == Michael Hauser <ha...@na...> writes: > > > > Michael> Hello, I am having a problem with plot_date. I keep > Michael> getting the error: > > Michael> Am I missing something obvious? > >No, there is a bug in plot_date in setting the tick formatter object. >I didn't find this in any of my test or example scripts since all >those explicitly set the formatter and hence hid the bug. At the end >of the Axes.plot_date function in matplotlib.axes, replace > > self.xaxis.set_minor_locator(formatter) > >with self.xaxis.set_major_formatter(formatter) > >and you'll be good to go. Note however that there is a problem with >your script in that the length of your x and y arrays must be the >same. After making the changes above, try > >from datetime import datetime >from matplotlib.dates import EpochConverter >from matplotlib.matlab import * > >times = [1084195314, 1084195375, 1084195436, 1084195497, 1084195557] >vals = [10.2, 11.1, 8.7, 12.1, 12.2] >converter = EpochConverter() >ax = subplot(111) >plot_date(times, vals, converter) >savefig('test') >show() > > > > >------------------------------------------------------- >This SF.Net email is sponsored by the new InstallShield X. >From Windows to Linux, servers to mobile, InstallShield X is the >one installation-authoring solution that does it all. Learn more and >evaluate today! http://www.installshield.com/Dev2Dev/0504 >_______________________________________________ >Matplotlib-users mailing list >Mat...@li... >https://lists.sourceforge.net/lists/listinfo/matplotlib-users > ------------------------------------------------------- This SF.Net email is sponsored by the new InstallShield X. From Windows to Linux, servers to mobile, InstallShield X is the one installation-authoring solution that does it all. Learn more and evaluate today! http://www.installshield.com/Dev2Dev/0504 _______________________________________________ Matplotlib-users mailing list Mat...@li... https://lists.sourceforge.net/lists/listinfo/matplotlib-users |
From: Peter G. <pgr...@ge...> - 2004-06-17 04:01:47
|
Thanks for the prompt response and the detailed explanation. The scaling is working now, and I have not encountered those old problems. There are a couple of things I should mention however: 1) The axes.auto_scale() seems to be broken. I get a following error: ------------ Traceback (most recent call last): File "./e3.py", line 97, in ? ax.autoscale_view() File "/usr/lib/python2.2/site-packages/matplotlib/axes.py", line 436, in autoscale_view tup = locator.autoscale() File "/usr/lib/python2.2/site-packages/matplotlib/ticker.py", line 327, in autoscale return self.nonsingular(self.dataInterval.get_bounds()) TypeError: nonsingular() takes exactly 3 arguments (2 given) ------------- When I run this: -------- #!/usr/bin/env python import time from matplotlib.dates import EpochConverter from matplotlib.matlab import * from matplotlib.ticker import FuncFormatter, NullLocator, MinuteLocator, DayLocator, HourLocator, MultipleLocator, DateFormatter wantLegend=1 time1=[1087192789.89] data1=[-65.54] time2=[ 1087161589.89 , 1087192289.0, 1087192389.0, 1087192489.0, 1087192589.0, 1087192689.0, 1087192789.89 , 1087192889.0, 1087192989.0, 1087193089.0, 1087193189.0, 1087193289.0, 1087238100.0 , ] data2=[ -55.44 -64.54 , -66.54 , -61.54 , -69.54 , -45.66, -55.54 , -77.54, -65.54 , -49.54 , -57.54 , -68.54 , -55.54 , -23.44 ] ax = subplot(111) p1Size=len(time1) p2Size=len(time2) p1=plot_date(time1, data1, None, '-', color='r') p2=plot_date(time2, data2, None, '-', color='b') p1=plot(time1, data1,'-', color='r') p2=plot(time2, data2,'-', color='b') now=time2[-1] then=time2[0] deltaSec=now-then deltaTickSec=deltaSec/7.0 tickList=[item for item in list(arange(then, now, deltaTickSec))] def tickString(x, pos): return time.strftime("%H:%M:%S", time.localtime(x)) formatter = FuncFormatter(tickString) ax.set_xticks(tickList) ax.xaxis.set_major_formatter(formatter) ax.xaxis.set_minor_locator(NullLocator()) #This line does not work. ax.autoscale_view() if wantLegend: legend((p1, p2), ('small data set (%d)' % p1Size, 'large data set (%d)' % p2Size)) xlabel('time') grid(True) show() #savefig('./blah.png') ------ Things work when I comment out the line: ax.autoscale_view() 2) The auto-scaling in plot_date() does not scale properly in some special cases. Consider this: ----------------- from matplotlib.matlab import * time2= [ 1087321489.89, 1087321500.0, 1087321789.89, 1087321800.0, 1087322089.89, 1087322100.0, 1087322389.89, 1087322700.0, 1087322989.89, 1087323000.0, 1087323289.89, 1087323300.0, 1087323589.89, 1087323600.0, 1087323889.89, 1087323900.0, 1087324189.89, 1087324200.0, 1087324489.89, 1087324500.0, ] data2=[ 3.02, 3.02, 3.14, 3.14, 3.21, 3.21, 3.26, 3.26, 3.39, 3.39, 3.51, 3.51, 3.58, 3.58, 3.75, 3.75, 4.0, 4.0, 4.22, 4.22,] plot_date(time2, data2, None, '-', color='b') xlabel('time') grid(True) show() --------------- The same thing happens over differnt ranges when the amount of ticks is large. Perhaps you may use something similar to the code below (from axes.py) to deal with these things. Note the ceilings get rid of the AssertErrors in ticks.Base when int() gives zero. Also, to finalize this, one would have to write a DayMultiLocator type class for the Weeks, otherwise when the number of weeks is close, but less then the number of weeks in numticks*months it will get crowded. This will probably be a little more involved than dealing with days, but perhaps one could use your existent WeekdayLocator class to simplify the problem. Also note that there was an error in defining months in your code; I changed the line to: months = span/(SEC_PER_DAY*31) # approx ----------- def plot_date(self, d, y, converter, fmt='bo', **kwargs): """ plot_date(d, y, converter, fmt='bo', **kwargs) d is a sequence of dates; converter is a dates.DateConverter instance that converts your dates to seconds since the epoch for plotting. y are the y values at those dates. fmt is a plot format string. kwargs are passed on to plot. See plot for more information. pass converter = None if your dates are already in epoch format """ if not self._hold: self.cla() if converter is not None: e = array([converter.epoch(thisd) for thisd in d]) else: e = d assert(len(e)) ret = self.plot(e, y, fmt, **kwargs) span = self.dataLim.intervalx().span() if span==0: span = SEC_PER_MIN minutes = span/SEC_PER_MIN hours = span/SEC_PER_HOUR days = span/SEC_PER_DAY weeks = span/SEC_PER_WEEK months = span/(SEC_PER_DAY*31) # approx years = span/(SEC_PER_WEEK*52) # approx #These should go to the top module. from math import ceil from ticker import DayMultiLocator numticks = 5 if years>numticks: locator = YearLocator(ceil(years/numticks)) # define fmt = '%Y' elif months>numticks: locator = MonthLocator(ceil(months/numticks)) # define fmt = '%b %Y' elif weeks>numticks: locator = WeekdayLocator(0) fmt = '%b %d' #Hack - need a DayLocator which operates like HourLocator #ie. Have a tick every so many days other than every day at a #particular hour. #This is a class I added to ticker.py: ## class DayMultiLocator(MultipleLocator): ## """ ## Make ticks on day which are multiples of base ## """ ## def __init__(self, base): ## MultipleLocator.__init__(self, base*SEC_PER_DAY) elif days>numticks: locator = DayMultiLocator(ceil(days/numticks)) fmt = '%b %d' elif hours>numticks: locator = HourLocator(ceil(hours/numticks)) fmt = '%H:%M\n%b %d' elif minutes>numticks: locator = MinuteLocator(ceil(minutes/numticks)) fmt = '%H:%M:%S' else: locator = MinuteLocator(1) fmt = '%H:%M:%S' formatter = DateFormatter(fmt) self.xaxis.set_major_locator(locator) self.xaxis.set_major_formatter(formatter) self.autoscale_view() return ret Let me know what you think. Peter John Hunter wrote: >>>>>> "Peter" == Peter Groszkowski <pgr...@ge...> writes: >>>>>> > > > Peter> It does?! Do you mean that this is done automatically? Can > Peter> you show me an example of this using only the time module > Peter> (since I use python2.2, dont have datetime)? I thought that > Peter> I had to manually set things up and tell matplotlib whether > > No, it's designed to work automagically. If you take a look at > axes.Axes.plot_date you'll see how it works. It looks at the max/min > span of your data and chooses a locator and formatter accordingly. > All the examples use custom locators and formatters ( I was busy > showing off how you could customize), but you don't need to > > from matplotlib.matlab import * > > time2= [ 1087161589.89 , 1087192289.0, 1087192389.0, 1087192489.0, > 1087192589.0, 1087192689.0, 1087192789.89 , 1087192889.0, > 1087192989.0, 1087193089.0, 1087193189.0, 1087193289.0, 1087238100.0, > ] > data2=[ -55.44 -64.54 , -66.54 , -61.54 , -69.54 , -45.66, -55.54, > -77.54, -65.54 , -49.54 , -57.54 , -68.54 , -55.54 , -23.44 ] > > plot_date(time2, data2, None, '-', color='b') > xlabel('time') > grid(True) > > show() > > In general you should try not to set the limits or ticks explicitly > since this is the job of the autolocator. I realize you were > encountering troubles and this is what led you to do it. Hopefully > the discussion below will save you from having to do this. > > Peter> On the other note, regarding the weird scaling that I > Peter> talked about (and showed pretty pics for) in my last mail, > Peter> I finally put together a small script that exposes the > Peter> problem. It is a bit rough because I ripped bits and pieces > Peter> from here and there, but shows the issue. Use the > Peter> 'wantBadPlot' and 'wantStandardDateTics' to see how things > Peter> go wrong. > > I looked at this and figured out the root cause of the problem. Your > "bad data" is a singleton plot > > time1=[1087192789.89] > data1=[-65.54] > p1=plot_date(time1, data1, None, '-', color='r') > > These are difficult to deal with - I'll explain why. The default > linear transformation maps data limits to display limits, and needs to > divide by the data span to do so. In this case min=max so the span is > zero and the transformation is undefined. To handle this case, I > detect the span=0 case and reset the data limits, lowering the min a > bit and raising the max a bit. > In earlier versions of maptlotlib, I did > > minx, maxx = min(xdata), max(xdata) > if minx==maxx: > minx -= 1 > maxx += 1 > > A problem arose if a person issued multiple calls to plot, first with > a singleton and then with a range of data, all really small > > >>> plot([1e-9], [10]) # x limits are now approx -1, 1 due to above > >>> plot([1e-9,2e-9,3e-9], [10,20,30]) > after the second call the data limits are still -1,1 because the limit > code only changes the data limits if the new lines are outside the > range of the existing limits. In this case they are not. The effect > is the plot is badly scaled since the data limits are wide compared to > all the xdata. > > Thinking myself clever (first mistake!), I rewrote the above code as > > minx, maxx = min(xdata), max(xdata) > if minx==maxx: > minx -= 0.001*abs(minx) > maxx += 0.001*abs(maxx) > > So the scaling would be proportionate to the data size. This helps in > some cases, but is failing for you. Again, in your example code, you > do the dreaded singleton plot followed by more plot commands > > p1=plot_date([1087192789.89], [-65.54], None, '-', color='r') > p2=plot_date(times, values, None, '-', color='r') > > Since minx==maxx in the first plot, the xlimits become 1086105597.1, > 1088279982.67. This is very wide compared to the subsequent range of > data you put in in the second plot_date call. This explains the bad > scaling you are seeing. > > Upon writing this, I realized that the fundamental problem is that I > am manipulating data limits to deal with a singular range, when the > data limits should *always* accurately reflect the true data limits > (doh!). It's the view limits that need to be mucked with to handle > this case. I had to make a number of changes throughout the code to > get everybody playing nicely with this new insight, but now everything > is working. Even your wantBadPlot example! > > Give it a try: > > http://nitace.bsd.uchicago.edu:8080/files/share/matplotlib-0.54.3a.tar.gz > > and let me know if it passes your tests. > > JDH > > ---- Msg sent via @Mail - http://WebBasedEmail.com/ |
From: John H. <jdh...@ac...> - 2004-06-17 14:13:33
|
>>>>> "Peter" == Peter Groszkowski <pgr...@ge...> writes: Peter> self.nonsingular(self.dataInterval.get_bounds()) TypeError: Peter> nonsingular() takes exactly 3 arguments (2 given) Peter> ------------- Should be self.nonsingular(*self.dataInterval.get_bounds()) Peter> 2) The auto-scaling in plot_date() does not scale properly Peter> in some special cases. Consider this: The example seems to work now with the above change and the changes you suggested in below. Peter> ticks.Base when int() gives zero. Also, to finalize this, Peter> one would have to write a DayMultiLocator type class for I added DayMultiLocator to matplotlib.ticker Peter> the Weeks, otherwise when the number of weeks is close, but Peter> less then the number of weeks in numticks*months it will Peter> get crowded. This will probably be a little more involved Peter> than dealing with days, but perhaps one could use your Peter> existent WeekdayLocator class to simplify the problem. A WeekMultiLocator would be useful, but it's not a priority for me. If you come up with one, send it my way. Peter> Also note that there was an error in defining months in Peter> your code; I changed the line to: Peter> months = span/(SEC_PER_DAY*31) # approx Thanks for the fix. Peter> Let me know what you think. Looks good; thanks! JDH |
From: Peter G. <pgr...@ge...> - 2004-08-07 23:33:41
|
Hi: Below is a little part of my post from a while ago regarding x-axis scaling on plot_date plots. > > 2) The auto-scaling in plot_date() does not scale properly in some > special cases. Consider this: > > ----------------- > from matplotlib.matlab import * > > time2= [ > 1087321489.89, 1087321500.0, > 1087321789.89, 1087321800.0, 1087322089.89, 1087322100.0, > 1087322389.89, 1087322700.0, 1087322989.89, > 1087323000.0, 1087323289.89, 1087323300.0, 1087323589.89, > 1087323600.0, 1087323889.89, 1087323900.0, > 1087324189.89, 1087324200.0, 1087324489.89, 1087324500.0, ] > data2=[ 3.02, > 3.02, > 3.14, > 3.14, > 3.21, > 3.21, > 3.26, > 3.26, > 3.39, > 3.39, > 3.51, > 3.51, > 3.58, > 3.58, > 3.75, > 3.75, > 4.0, > 4.0, > 4.22, > 4.22,] > > plot_date(time2, data2, None, '-', color='b') > xlabel('time') > grid(True) > > show() > --------------- > > The same thing happens over differnt ranges when the amount of ticks > is large. Perhaps you may use something similar to the code below > (from axes.py) to deal with these things. Note the ceilings get rid of > the AssertErrors in ticks.Base when int() gives zero. Also, to > finalize this, > one would have to write a DayMultiLocator type class for the Weeks, > otherwise when the number of weeks is close, but less then the number > of weeks in numticks*months it will get crowded. This will probably be > a little more involved than dealing with days, but perhaps one could use > your existent WeekdayLocator class to simplify the problem. I added a quick and dirty version of this WeekMultiLocator that handles cases when the time range is many weeks but less than 5 months (say 17 weeks) and the ticks get over-crowded. Ideally one could have the weeks always start on some particular day - say Monday, but for me it doesnt really matter, and with the simple code below, thing seem to come out quite nice. In axes.py need: Line ~19: from ticker import YearLocator, MonthLocator, WeekdayLocator, \ DayLocator, HourLocator, MinuteLocator, DateFormatter, DayMultiLocator, WeekMultiLocator Line ~1475: def plot_date(self, d, y, converter, fmt='bo', **kwargs): """ plot_date(d, y, converter, fmt='bo', **kwargs) d is a sequence of dates; converter is a dates.DateConverter instance that converts your dates to seconds since the epoch for plotting. y are the y values at those dates. fmt is a plot format string. kwargs are passed on to plot. See plot for more information. pass converter = None if your dates are already in epoch format """ if not self._hold: self.cla() if converter is not None: e = array([converter.epoch(thisd) for thisd in d]) else: e = d assert(len(e)) ret = self.plot(e, y, fmt, **kwargs) span = self.dataLim.intervalx().span() if span==0: span = SEC_PER_HOUR minutes = span/SEC_PER_MIN hours = span/SEC_PER_HOUR days = span/SEC_PER_DAY weeks = span/SEC_PER_WEEK months = span/(SEC_PER_DAY*31) # approx years = span/(SEC_PER_WEEK*52) # approx numticks = 5 if years>numticks: locator = YearLocator(math.ceil(years/numticks)) fmt = '%Y' elif months>numticks: locator = MonthLocator(math.ceil(months/numticks)) fmt = '%b %Y' elif weeks>numticks: locator = WeekMultiLocator(math.ceil(weeks/numticks)) fmt = '%a, %b %d' elif days>numticks: locator = DayMultiLocator(math.ceil(days/numticks)) fmt = '%b %d' elif hours>numticks: locator = HourLocator(math.ceil(hours/numticks)) fmt = '%H:%M\n%b %d' elif minutes>numticks: locator = MinuteLocator(math.ceil(minutes/numticks)) fmt = '%H:%M:%S' else: locator = MinuteLocator(1) fmt = '%H:%M:%S' formatter = DateFormatter(fmt) self.xaxis.set_major_locator(locator) self.xaxis.set_major_formatter(formatter) self.autoscale_view() return ret In ticks.py: Need to add: class WeekMultiLocator(MultipleLocator): """ Make ticks on day which are multiples of base """ def __init__(self, base): MultipleLocator.__init__(self, base*SEC_PER_WEEK) -- Peter Groszkowski Gemini Observatory Tel: +1 808 974-2509 670 N. A'ohoku Place Fax: +1 808 935-9235 Hilo, Hawai'i 96720, USA |
From: John H. <jdh...@ac...> - 2004-06-13 02:40:45
|
>>>>> "Peter" == Peter Groszkowski <pio...@ho...> writes: Peter> I found another issue with plot_date. Dont have a simple Peter> example yet, and hope that this is something 'obvious' and Peter> I don't have to bother. There is clearly something wrong with the autoscale function of one of the date tick locators. It would help to know which one. plot_date looks at the range of your date data and tries to pick the appropriate date tick locator based on that range (ie a YearLocator, MonthLocator, MinuteLocator, etc). If I knew which tick locator was behaving badly, it would help me fix the problem. If you print ax.xaxis._majorLocator after the call to plot_date, and let me know which locator it is, I can probably figure out where the problem is. To simplify, don't explicitly set the date xlim range when you do this. On a side note, in your example code you call ax.viewLim.intervalx().set_bounds(minXValueImPlotting, maxXValueImPlotting) I assume you did this to narrow down the possible causes of problems. As you know, this is the call that ax.set_xlim makes under the hood. But in general, it's safest to stick to the axes API, ie, call ax.set_xlim(minXValueImPlotting, maxXValueImPlotting) since this interface is guaranteed to be stable. JDH |
From: Peter G. <pgr...@ge...> - 2004-06-15 03:26:44
|
Hi John: > plot_date looks at the range of your date data and tries to pick the > appropriate > date tick locator based on that range (ie a YearLocator, MonthLocator, > MinuteLocator, etc). It does?! Do you mean that this is done automatically? Can you show me an example of this using only the time module (since I use python2.2, dont have datetime)? I thought that I had to manually set things up and tell matplotlib whether to use YearLocator, MonthLocator, etc.. via calls to: axes.xaxis.set_minor_locator(), axes.xaxis.set_major_locator(), axes.xaxis.set_major_formatter(). In other words for every plot, check the time range of my data, figure out how many ticks I want, and decide whether to use months, days, hours, etc... In fact, because I was getting some inconsistent results with using the above, I decided that for the most part (excluding a few special cases), I would print the time ticks myself 'manually'. The script below shows what I mean. On the other note, regarding the weird scaling that I talked about (and showed pretty pics for) in my last mail, I finally put together a small script that exposes the problem. It is a bit rough because I ripped bits and pieces from here and there, but shows the issue. Use the 'wantBadPlot' and 'wantStandardDateTics' to see how things go wrong. -------------------------------- #!/usr/bin/env python import time from matplotlib.dates import EpochConverter from matplotlib.matlab import * from matplotlib.ticker import FuncFormatter, NullLocator, MinuteLocator, DayLocator, HourLocator, MultipleLocator, DateFormatter wantBadPlot=1 wantStandardDateTics=1 wantLegend=1 if wantBadPlot: time1=[1087192789.89] data1=[-65.54] else: time1=[1087192289.89, 1087193789.89] data1=[-44.343, -65.54] time2=[ 1087161589.89 , 1087192289.0, 1087192389.0, 1087192489.0, 1087192589.0, 1087192689.0, 1087192789.89 , 1087192889.0, 1087192989.0, 1087193089.0, 1087193189.0, 1087193289.0, 1087238100.0 , ] data2=[ -55.44 -64.54 , -66.54 , -61.54 , -69.54 , -45.66, -55.54 , -77.54, -65.54 , -49.54 , -57.54 , -68.54 , -55.54 , -23.44 ] ax = subplot(111) p1Size=len(time1) p2Size=len(time2) p1=plot_date(time1, data1, None, '-', color='r') p2=plot_date(time2, data2, None, '-', color='b') if wantStandardDateTics: fmt=DateFormatter('%H:%M') hours=HourLocator(4) ax.xaxis.set_minor_locator(NullLocator()) ax.xaxis.set_major_locator(hours) ax.xaxis.set_major_formatter(fmt) ax.autoscale_view() else: #Manually display dates for tick-labels. Technically could use plot() and #get the same result. now=time2[-1] then=time2[0] deltaSec=now-then deltaTickSec=deltaSec/7.0 tickList=[item for item in list(arange(then, now, deltaTickSec))] def tickString(x, pos): return time.strftime("%H:%M:%S", time.localtime(x)) formatter = FuncFormatter(tickString) ax.set_xticks(tickList) ax.xaxis.set_major_formatter(formatter) ax.xaxis.set_minor_locator(NullLocator()) ax.autoscale_view() #This will fix the problem!! #ax.set_xlim((then, now)) if wantLegend: legend((p1, p2), ('small data set (%d)' % p1Size, 'large data set (%d)' % p2Size)) xlabel('time') grid(True) show() #savefig('./blah.png') ------------------------------- Any ideas? Finally, just want to verify (form my last email) that in axes.py: def get_ylim(self): "Get the y axis range [ymin, ymax]" return self.viewLim.intervalx().get_bounds() should intervax() be intervaly()?? Thanks, -- Peter Groszkowski Gemini Observatory Tel: +1 808 974-2509 670 N. A'ohoku Place Fax: +1 808 935-9235 Hilo, Hawai'i 96720, USA John Hunter wrote: >>>>>> "Peter" == Peter Groszkowski <pio...@ho...> writes: >>>>>> >>>>> > > Peter> I found another issue with plot_date. Dont have a simple > Peter> example yet, and hope that this is something 'obvious' and > Peter> I don't have to bother. > > There is clearly something wrong with the autoscale function of one of > the date tick locators. It would help to know which one. plot_date > looks at the range of your date data and tries to pick the appropriate > date tick locator based on that range (ie a YearLocator, MonthLocator, > MinuteLocator, etc). If I knew which tick locator was behaving badly, > it would help me fix the problem. > > If you > print ax.xaxis._majorLocator > > after the call to plot_date, and let me know which locator it is, I > can probably figure out where the problem is. To simplify, don't > explicitly set the date xlim range when you do this. > > On a side note, in your example code you call > > ax.viewLim.intervalx().set_bounds(minXValueImPlotting, > maxXValueImPlotting) > > I assume you did this to narrow down the possible causes of problems. > As you know, this is the call that ax.set_xlim makes under the hood. > But in general, it's safest to stick to the axes API, ie, call > > ax.set_xlim(minXValueImPlotting, maxXValueImPlotting) > > since this interface is guaranteed to be stable. > > JDH > > > ------------------------------------------------------- > This SF.Net email is sponsored by the new InstallShield X. > From Windows to Linux, servers to mobile, InstallShield X is the > one installation-authoring solution that does it all. Learn more and > evaluate today! http://www.installshield.com/Dev2Dev/0504 > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > |