SourceForge logo
SourceForge logo
Menu

matplotlib-users — Discussion related to using matplotlib

You can subscribe to this list here.

2003 Jan
Feb
Mar
Apr
May
(3)
Jun
Jul
Aug
(12)
Sep
(12)
Oct
(56)
Nov
(65)
Dec
(37)
2004 Jan
(59)
Feb
(78)
Mar
(153)
Apr
(205)
May
(184)
Jun
(123)
Jul
(171)
Aug
(156)
Sep
(190)
Oct
(120)
Nov
(154)
Dec
(223)
2005 Jan
(184)
Feb
(267)
Mar
(214)
Apr
(286)
May
(320)
Jun
(299)
Jul
(348)
Aug
(283)
Sep
(355)
Oct
(293)
Nov
(232)
Dec
(203)
2006 Jan
(352)
Feb
(358)
Mar
(403)
Apr
(313)
May
(165)
Jun
(281)
Jul
(316)
Aug
(228)
Sep
(279)
Oct
(243)
Nov
(315)
Dec
(345)
2007 Jan
(260)
Feb
(323)
Mar
(340)
Apr
(319)
May
(290)
Jun
(296)
Jul
(221)
Aug
(292)
Sep
(242)
Oct
(248)
Nov
(242)
Dec
(332)
2008 Jan
(312)
Feb
(359)
Mar
(454)
Apr
(287)
May
(340)
Jun
(450)
Jul
(403)
Aug
(324)
Sep
(349)
Oct
(385)
Nov
(363)
Dec
(437)
2009 Jan
(500)
Feb
(301)
Mar
(409)
Apr
(486)
May
(545)
Jun
(391)
Jul
(518)
Aug
(497)
Sep
(492)
Oct
(429)
Nov
(357)
Dec
(310)
2010 Jan
(371)
Feb
(657)
Mar
(519)
Apr
(432)
May
(312)
Jun
(416)
Jul
(477)
Aug
(386)
Sep
(419)
Oct
(435)
Nov
(320)
Dec
(202)
2011 Jan
(321)
Feb
(413)
Mar
(299)
Apr
(215)
May
(284)
Jun
(203)
Jul
(207)
Aug
(314)
Sep
(321)
Oct
(259)
Nov
(347)
Dec
(209)
2012 Jan
(322)
Feb
(414)
Mar
(377)
Apr
(179)
May
(173)
Jun
(234)
Jul
(295)
Aug
(239)
Sep
(276)
Oct
(355)
Nov
(144)
Dec
(108)
2013 Jan
(170)
Feb
(89)
Mar
(204)
Apr
(133)
May
(142)
Jun
(89)
Jul
(160)
Aug
(180)
Sep
(69)
Oct
(136)
Nov
(83)
Dec
(32)
2014 Jan
(71)
Feb
(90)
Mar
(161)
Apr
(117)
May
(78)
Jun
(94)
Jul
(60)
Aug
(83)
Sep
(102)
Oct
(132)
Nov
(154)
Dec
(96)
2015 Jan
(45)
Feb
(138)
Mar
(176)
Apr
(132)
May
(119)
Jun
(124)
Jul
(77)
Aug
(31)
Sep
(34)
Oct
(22)
Nov
(23)
Dec
(9)
2016 Jan
(26)
Feb
(17)
Mar
(10)
Apr
(8)
May
(4)
Jun
(8)
Jul
(6)
Aug
(5)
Sep
(9)
Oct
(4)
Nov
Dec
2017 Jan
(5)
Feb
(7)
Mar
(1)
Apr
(5)
May
Jun
(3)
Jul
(6)
Aug
(1)
Sep
Oct
(2)
Nov
(1)
Dec
2018 Jan
Feb
Mar
Apr
(1)
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
2020 Jan
Feb
Mar
Apr
May
(1)
Jun
Jul
Aug
Sep
Oct
Nov
Dec
2025 Jan
(1)
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
S M T W T F S


1
(4)
2
(8)
3
(3)
4
(4)
5
6
7
(3)
8
(8)
9
(6)
10
(8)
11
(5)
12
(2)
13
(4)
14
(2)
15
(12)
16
(11)
17
(3)
18
19
(1)
20
21
(2)
22
(13)
23
(4)
24
(6)
25
26
(2)
27
28
(2)
29
(8)
30
(2)



Showing 2 results of 2

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年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/
1 message has been excluded from this view by a project administrator.

Showing 2 results of 2

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 によって変換されたページ (->オリジナル) /