From: Simson Garfinkel <simsong@ac...>  20090112 06:33:44

Hi. It's me again, asking about dates again. is there any easy way to a collection using dates on the X axes? I've taken the collection example from the website and adopted it so that there is a use_dates flag. Set it to False and spirals demo appears. Set it to True and I get this error: Traceback (most recent call last): File "mpl_collection2.py", line 51, in <module> ax.add_collection(col, autolim=True) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/sitepackages/matplotlib/axes.py", line 1312, in add_collection self.update_datalim(collection.get_datalim(self.transData)) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/sitepackages/matplotlib/collections.py", line 144, in get_datalim offsets = transOffset.transform_non_affine(offsets) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/sitepackages/matplotlib/transforms.py", line 1914, in transform_non_affine self._a.transform(points)) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/sitepackages/matplotlib/transforms.py", line 1408, in transform return affine_transform(points, mtx) ValueError: Invalid vertices array. The code is below. Thanks! ========================= import matplotlib import matplotlib.pyplot from matplotlib import collections, transforms from matplotlib.colors import colorConverter import numpy as N import datetime use_dates = False nverts = 50 npts = 100 # Make some spirals r = N.array(range(nverts)) theta = N.array(range(nverts)) * (2*N.pi)/(nverts1) xx = r * N.sin(theta) yy = r * N.cos(theta) spiral = zip(xx,yy) # Make some offsets rs = N.random.RandomState([12345678]) if not use_dates: xo = [i for i in range(0,100)] else: xo = [datetime.date(1990,1,1)+datetime.timedelta(10)*i for i in range(0,100)] # new version yo = rs.randn(npts) xyo = zip(xo, yo) colors = [colorConverter.to_rgba(c) for c in ('r','g','b','c','y','m','k')] fig = matplotlib.pyplot.figure() ax = fig.add_subplot(1,1,1) if use_dates: import matplotlib.dates as mdates years = mdates.YearLocator() # every year months = mdates.MonthLocator() # every month yearsFmt = mdates.DateFormatter('%Y') ax.xaxis.set_major_locator(years) ax.xaxis.set_major_formatter(yearsFmt) ax.set_xlim(datetime.date(1990,1,1),datetime.date(1992,12,31)) col = collections.LineCollection([spiral], offsets=xyo, transOffset=ax.transData) trans = fig.dpi_scale_trans + transforms.Affine2D().scale(1.0/72.0) col.set_transform(trans) # the points to pixels transform ax.add_collection(col, autolim=True) col.set_color(colors) ax.autoscale_view() ax.set_title('LineCollection using offsets') matplotlib.pyplot.show() 
From: Eric Firing <efiring@ha...>  20090112 19:53:32

Simson Garfinkel wrote: > Hi. It's me again, asking about dates again. > > is there any easy way to a collection using dates on the X axes? > I've taken the collection example from the website and adopted it so > that there is a use_dates flag. Set it to False and spirals demo > appears. Set it to True and I get this error: Yes, it looks like a bug in the handling of units in the Collection base class; unit conversion is done at drawing time, but needs either to be done earlier, or to be done independently in the get_datalim method. Maybe one of the unitssupport experts will pick this up and fix it. I can't do more now. Eric > > Traceback (most recent call last): > File "mpl_collection2.py", line 51, in <module> > ax.add_collection(col, autolim=True) > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/sitepackages/matplotlib/axes.py", line 1312, in > add_collection > self.update_datalim(collection.get_datalim(self.transData)) > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/sitepackages/matplotlib/collections.py", line 144, in > get_datalim > offsets = transOffset.transform_non_affine(offsets) > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/sitepackages/matplotlib/transforms.py", line 1914, in > transform_non_affine > self._a.transform(points)) > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/sitepackages/matplotlib/transforms.py", line 1408, in > transform > return affine_transform(points, mtx) > ValueError: Invalid vertices array. > > > The code is below. > > Thanks! > > ========================= > import matplotlib > import matplotlib.pyplot > from matplotlib import collections, transforms > from matplotlib.colors import colorConverter > import numpy as N > > import datetime > > use_dates = False > > nverts = 50 > npts = 100 > > # Make some spirals > r = N.array(range(nverts)) > theta = N.array(range(nverts)) * (2*N.pi)/(nverts1) > xx = r * N.sin(theta) > yy = r * N.cos(theta) > spiral = zip(xx,yy) > > # Make some offsets > rs = N.random.RandomState([12345678]) > > if not use_dates: > xo = [i for i in range(0,100)] > else: > xo = [datetime.date(1990,1,1)+datetime.timedelta(10)*i for i in > range(0,100)] # new version > > yo = rs.randn(npts) > xyo = zip(xo, yo) > colors = [colorConverter.to_rgba(c) for c in > ('r','g','b','c','y','m','k')] > > fig = matplotlib.pyplot.figure() > ax = fig.add_subplot(1,1,1) > > if use_dates: > import matplotlib.dates as mdates > years = mdates.YearLocator() # every year > months = mdates.MonthLocator() # every month > yearsFmt = mdates.DateFormatter('%Y') > ax.xaxis.set_major_locator(years) > ax.xaxis.set_major_formatter(yearsFmt) > ax.set_xlim(datetime.date(1990,1,1),datetime.date(1992,12,31)) > > col = collections.LineCollection([spiral], offsets=xyo, > transOffset=ax.transData) > trans = fig.dpi_scale_trans + transforms.Affine2D().scale(1.0/72.0) > col.set_transform(trans) # the points to pixels transform > ax.add_collection(col, autolim=True) > col.set_color(colors) > > ax.autoscale_view() > ax.set_title('LineCollection using offsets') > matplotlib.pyplot.show() > > >  > Check out the new SourceForge.net Marketplace. > It is the best place to buy or sell services for > just about anything Open Source. > http://p.sf.net/sfu/Xq1LFB > _______________________________________________ > Matplotlibusers mailing list > Matplotlibusers@... > https://lists.sourceforge.net/lists/listinfo/matplotlibusers 
From: Eric Firing <efiring@ha...>  20090113 02:56:02

Simson Garfinkel wrote: > > On Jan 12, 2009, at 11:53 AM, Eric Firing wrote: > >> Simson Garfinkel wrote: >>> Hi. It's me again, asking about dates again. >>> is there any easy way to a collection using dates on the X axes? >>> I've taken the collection example from the website and adopted it so >>> that there is a use_dates flag. Set it to False and spirals demo >>> appears. Set it to True and I get this error: >> >> Yes, it looks like a bug in the handling of units in the Collection >> base class; unit conversion is done at drawing time, but needs either >> to be done earlier, or to be done independently in the get_datalim >> method. >> >> Maybe one of the unitssupport experts will pick this up and fix it. >> I can't do more now. > > Hi, Eric. > > Ah. Just my luck. I always push this stuff in new and unexpected ways. > > Here's what I'm trying to do  I want to plot a graph of circles where > the size of the circle and color are determined by the data, where the X > axis is year/month/day, and the Y axis is just day. (So a lot of "1" > values would be a lot of slightly diagonal lines.) > > Any idea how to do this within the current matplotlib, or should I just > hack it by hand? Simson, The scatter function or Axes method is designed for exactly this, but units support was broken in two places. I have fixed it in 6781 on the 98.5 maintenance branch, merged to the trunk in 6782. So, please update to one of these and try scatter(). (Watch out for the odd definition of the "s" kwarg for size: area in points squared.) Eric > > Thanks. > 
From: Simson Garfinkel <simsong@ac...>  20090114 04:00:35

>> Hi, Eric. >> Ah. Just my luck. I always push this stuff in new and unexpected >> ways. >> Here's what I'm trying to do  I want to plot a graph of circles >> where the size of the circle and color are determined by the data, >> where the X axis is year/month/day, and the Y axis is just day. (So >> a lot of "1" values would be a lot of slightly diagonal lines.) >> Any idea how to do this within the current matplotlib, or should I >> just hack it by hand? > > Simson, > > The scatter function or Axes method is designed for exactly this, > but units support was broken in two places. I have fixed it in 6781 > on the 98.5 maintenance branch, merged to the trunk in 6782. So, > please update to one of these and try scatter(). (Watch out for the > odd definition of the "s" kwarg for size: area in points squared.) > > Eric Hm. So this means I need to switch from the .tar.gz releases to the subversion releases? > > > >> Thanks. > 
From: Eric Firing <efiring@ha...>  20090114 04:00:52

Simson Garfinkel wrote: >>> Hi, Eric. >>> Ah. Just my luck. I always push this stuff in new and unexpected ways. >>> Here's what I'm trying to do  I want to plot a graph of circles >>> where the size of the circle and color are determined by the data, >>> where the X axis is year/month/day, and the Y axis is just day. (So a >>> lot of "1" values would be a lot of slightly diagonal lines.) >>> Any idea how to do this within the current matplotlib, or should I >>> just hack it by hand? >> >> Simson, >> >> The scatter function or Axes method is designed for exactly this, but >> units support was broken in two places. I have fixed it in 6781 on >> the 98.5 maintenance branch, merged to the trunk in 6782. So, please >> update to one of these and try scatter(). (Watch out for the odd >> definition of the "s" kwarg for size: area in points squared.) >> >> Eric > > Hm. So this means I need to switch from the .tar.gz releases to the > subversion releases? Yes. I don't know when a release will be made from the 98.5 maintenance branch. Eric 
From: Eric Firing <efiring@ha...>  20090114 05:34:27

Simson Garfinkel wrote: >>> Hi, Eric. >>> Ah. Just my luck. I always push this stuff in new and unexpected >>> ways. >>> Here's what I'm trying to do  I want to plot a graph of circles >>> where the size of the circle and color are determined by the data, >>> where the X axis is year/month/day, and the Y axis is just day. (So >>> a lot of "1" values would be a lot of slightly diagonal lines.) >>> Any idea how to do this within the current matplotlib, or should I >>> just hack it by hand? >> Simson, >> >> The scatter function or Axes method is designed for exactly this, >> but units support was broken in two places. I have fixed it in 6781 >> on the 98.5 maintenance branch, merged to the trunk in 6782. So, >> please update to one of these and try scatter(). (Watch out for the >> odd definition of the "s" kwarg for size: area in points squared.) >> >> Eric > > Hm. So this means I need to switch from the .tar.gz releases to the > subversion releases? You could try ftp://currents.soest.hawaii.edu/pub/outgoing/matplotlib0.98.6svn.tar.gz which I made from my svn trunk checkout using "python setup.py sdist". No guarantees. It is huge; it must have a lot of files that are not in the standard *.tar.gz. I won't leave it there for more than a day or two, so if you want to try it, grab it now. We would like to have buildbots making and posting daily svn packages, but we aren't there yet. Eric > > > > >> >> >>> Thanks. > > >  > This SF.net email is sponsored by: > SourcForge Community > SourceForge wants to tell your story. > http://p.sf.net/sfu/sfspreadtheword > _______________________________________________ > Matplotlibusers mailing list > Matplotlibusers@... > https://lists.sourceforge.net/lists/listinfo/matplotlibusers 