Re: [Matplotlib-users] Basemap: Removing white space in savefig
On Tue, 10 Nov 2009 13:13 -0500, George Bonev george...@gmail.com wrote: Hello, I am plotting a fig in Basemap, but I don't need the extra while space on the sides of the figure when I use savfig(). I tried axes([0,0,1,1]) but that just gave me a blank white screen with some ticks on the sides. Is there another way to do it with Basemap? Please help! Thank you, George B. George: If you want to preserve the aspect ratio of the map, you need to calculate it ahead of time and make sure that you create a figure with the same aspect ratio and define an axes with no white space. For example, for a global cylindrical equidistant projection, the aspect ration should be 2:1, so you would create a figure like this from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np fig = plt.figure(figsize=(10,5)) ax = plt.axes([0,0,1,1]) m = Basemap(projection='cyl',lon_0=180) m.drawcoastlines() m.fillcontinents() m.drawparallels(np.arange(-60,61,30)) m.drawmeridians(np.arange(60,301,60)) plt.savefig('nowhite.png') plt.show() Note that you need to create the axes instance before the Basemap instance. If you don't care about the aspect ratio of the map being correct, you can set fix_aspect='False', create a map of any size you like, and use an axes with no white space. For example, from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np fig = plt.figure(figsize=(8,8)) ax = plt.axes([0,0,1,1]) m = Basemap(projection='cyl',lon_0=180,fix_aspect=False) m.drawcoastlines() m.fillcontinents() m.drawparallels(np.arange(-60,61,30)) m.drawmeridians(np.arange(60,301,60)) plt.savefig('nowhite2.png') plt.show() If you don't set fix_aspect=False in this example, you'll get a map with a 2:1 aspect ratio and lots of white space on the top and bottom of the plot. -Jeff -- Jeffrey S. Whitaker Phone: (303)497-6313 FAX: (303)497-6449 NOAA/OAR/CDC R/CDC1 325 Broadway, Boulder, CO, USA 80305-3328 http://www.cdc.noaa.gov/people/jeffrey.s.whitaker -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] function to create netcdf file
Hello, I'm trying to write a function to create a 'vanilla' NetCDF file to which I can add data. So far I have created the following, which is designed to set up a netcdf file for the addition of global or at least lat/lon datasets. My question has to do with attribute setting. Is it valid to do what I'm doing below nco.attribute = attributevalue or do you have to use the setattr function as outlined in some tutorials? Thanks! def default_netcdf(nco_filename, lon0=-179.5,lat0=-89.5, nx=720,ny=360, dx=0.5,dy=0.5): add default attributes and dimensions to the nc file nco = NetCDFFile(nco_filename,'w') nco.author = Some One nco.createdate = dt.datetime.now().ctime() nco.contact = some@python.com nco.Conventions = CF-1.4 nco.createDimension('lon',nx) nco.createDimension('lat',ny) nco.createVariable('lat','d',('lat',)) nco.createVariable('lon','d',('lon',)) lon = np.arange(lon0,lon0+(nx*dx),dx) lat = np.arange(lat0,lat0+(ny*dy),dy) nco.variables['lat'][:] = lat nco.variables['lon'][:] = lon nco.createVariable('data','d',('lon','lat')) return nco -- View this message in context: http://old.nabble.com/function-to-create-netcdf-file-tp26301238p26301238.html Sent from the matplotlib - users mailing list archive at Nabble.com. -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] matplotlib slow compared to gnuplot?
Hi all, Previously I was a user of gnuplot but have been giving matplotlib a try. One thing I've run in to right away is that matplotlib appears to be significantly slower. A script to produce a dozen plots was taking me ~1 second with gnuplot, and now takes me ~18 seconds with matplotlib. I'm curious if anyone knows how to speed things up. To figure out what is taking most of the time, I've used cProfile and pstats and below is the top 15 functions taking the most time. (note: plotStackedJobsVsTime is my function that uses matplotlib.) Wed Nov 11 08:43:52 2009fooprof 3069840 function calls (3009711 primitive calls) in 17.658 CPU seconds Ordered by: cumulative time List reduced from 873 to 15 due to restriction 15 ncalls tottime percall cumtime percall filename:lineno(function) 10.0000.000 17.658 17.658 string:1(module) 10.0070.007 17.658 17.658 /cms/cmsprod/bin/ prodJobMonitorPlots_matplotlib.py:151(main) 130.6200.048 17.6471.357 /cms/cmsprod/bin/ prodJobMonitorPlots_matplotlib.py:54(plotStackedJobsVsTime) 130.0000.000 10.0870.776 /afs/hep.wisc.edu/cms/ sw/python/x86_64/2.5.4/lib/python2.5/site-packages/ matplotlib-0.99.1.1_r0-py2.5-linux-x86_64.egg/matplotlib/figure.py:959 (savefig) 130.0280.002 10.0860.776 /afs/hep.wisc.edu/cms/ sw/python/x86_64/2.5.4/lib/python2.5/site-packages/ matplotlib-0.99.1.1_r0-py2.5-linux-x86_64.egg/matplotlib/ backend_bases.py:1372(print_figure) 130.0280.0029.8470.757 /afs/hep.wisc.edu/cms/ sw/python/x86_64/2.5.4/lib/python2.5/site-packages/ matplotlib-0.99.1.1_r0-py2.5-linux-x86_64.egg/matplotlib/backends/ backend_agg.py:357(print_png) 130.0000.0009.2430.711 /afs/hep.wisc.edu/cms/ sw/python/x86_64/2.5.4/lib/python2.5/site-packages/ matplotlib-0.99.1.1_r0-py2.5-linux-x86_64.egg/matplotlib/backends/ backend_agg.py:307(draw) 3206/130.0400.0009.2220.709 /afs/hep.wisc.edu/cms/ sw/python/x86_64/2.5.4/lib/python2.5/site-packages/ matplotlib-0.99.1.1_r0-py2.5-linux-x86_64.egg/matplotlib/artist.py:44 (draw_wrapper) 130.0010.0009.2220.709 /afs/hep.wisc.edu/cms/ sw/python/x86_64/2.5.4/lib/python2.5/site-packages/ matplotlib-0.99.1.1_r0-py2.5-linux-x86_64.egg/matplotlib/figure.py:729 (draw) 130.0050.0009.2000.708 /afs/hep.wisc.edu/cms/ sw/python/x86_64/2.5.4/lib/python2.5/site-packages/ matplotlib-0.99.1.1_r0-py2.5-linux-x86_64.egg/matplotlib/axes.py:1632 (draw) 260.0290.0015.6240.216 /afs/hep.wisc.edu/cms/ sw/python/x86_64/2.5.4/lib/python2.5/site-packages/ matplotlib-0.99.1.1_r0-py2.5-linux-x86_64.egg/matplotlib/axis.py:727 (draw) 1533/13250.0780.0003.6630.003 /afs/hep.wisc.edu/cms/sw/ python/x86_64/2.5.4/lib/python2.5/site-packages/matplotlib-0.99.1.1_r0- py2.5-linux-x86_64.egg/matplotlib/axis.py:61(__init__) 8110.0350.0003.0570.004 /afs/hep.wisc.edu/cms/ sw/python/x86_64/2.5.4/lib/python2.5/site-packages/ matplotlib-0.99.1.1_r0-py2.5-linux-x86_64.egg/matplotlib/axis.py:181 (draw) 130.0010.0002.6190.201 /afs/hep.wisc.edu/cms/ sw/python/x86_64/2.5.4/lib/python2.5/site-packages/ matplotlib-0.99.1.1_r0-py2.5-linux-x86_64.egg/matplotlib/legend.py:342 (draw) 1065/9610.0120.0002.5430.003 /afs/hep.wisc.edu/cms/ sw/python/x86_64/2.5.4/lib/python2.5/site-packages/ matplotlib-0.99.1.1_r0-py2.5-linux-x86_64.egg/matplotlib/axis.py:1207 (_get_tick) My script, for the curious, is at http://www.hep.wisc.edu/cms/comp/routerqMonitor/prodJobMonitorPlots_matplotlib.py and produces these plots: http://www.hep.wisc.edu/cms/comp/routerqMonitor/index.html Any hints at what I can do to speed up my script? Or is it out of my hands because it's all in matplotlib? Thanks for any help, Mike -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] function to create netcdf file
On Wed, Nov 11, 2009 at 7:31 AM, John [H2O] washa...@gmail.com wrote: Hello, I'm trying to write a function to create a 'vanilla' NetCDF file to which I can add data. So far I have created the following, which is designed to set up a netcdf file for the addition of global or at least lat/lon datasets. My question has to do with attribute setting. Is it valid to do what I'm doing below nco.attribute = attributevalue or do you have to use the setattr function as outlined in some tutorials? Thanks! def default_netcdf(nco_filename, lon0=-179.5,lat0=-89.5, nx=720,ny=360, dx=0.5,dy=0.5): add default attributes and dimensions to the nc file nco = NetCDFFile(nco_filename,'w') nco.author = Some One nco.createdate = dt.datetime.now().ctime() nco.contact = some@python.com nco.Conventions = CF-1.4 nco.createDimension('lon',nx) nco.createDimension('lat',ny) nco.createVariable('lat','d',('lat',)) nco.createVariable('lon','d',('lon',)) lon = np.arange(lon0,lon0+(nx*dx),dx) lat = np.arange(lat0,lat0+(ny*dy),dy) nco.variables['lat'][:] = lat nco.variables['lon'][:] = lon nco.createVariable('data','d',('lon','lat')) return nco That should work fine for settings attributes. Are you having a problem? If so, can you paste the actual traceback? Ryan -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] function to create netcdf file
No problem.. just wanted to make sure it would work and is 'pythonic'. I guess the biggest concern is that for others using the netcdf file, say from matlab or somewhere else, will be able to access the attributes. It seemed so easy to do it this way, I was curious why the tutorials suggest using setattr(), and I wonder if perhaps what I'm setting is not 'global' or perhaps wouldn't match some ISO or otherwise NetCDF standard?? Thanks! On Wed, Nov 11, 2009 at 4:03 PM, Ryan May rma...@gmail.com wrote: On Wed, Nov 11, 2009 at 7:31 AM, John [H2O] washa...@gmail.com wrote: Hello, I'm trying to write a function to create a 'vanilla' NetCDF file to which I can add data. So far I have created the following, which is designed to set up a netcdf file for the addition of global or at least lat/lon datasets. My question has to do with attribute setting. Is it valid to do what I'm doing below nco.attribute = attributevalue or do you have to use the setattr function as outlined in some tutorials? Thanks! def default_netcdf(nco_filename, lon0=-179.5,lat0=-89.5, nx=720,ny=360, dx=0.5,dy=0.5): add default attributes and dimensions to the nc file nco = NetCDFFile(nco_filename,'w') nco.author = Some One nco.createdate = dt.datetime.now().ctime() nco.contact = some@python.com nco.Conventions = CF-1.4 nco.createDimension('lon',nx) nco.createDimension('lat',ny) nco.createVariable('lat','d',('lat',)) nco.createVariable('lon','d',('lon',)) lon = np.arange(lon0,lon0+(nx*dx),dx) lat = np.arange(lat0,lat0+(ny*dy),dy) nco.variables['lat'][:] = lat nco.variables['lon'][:] = lon nco.createVariable('data','d',('lon','lat')) return nco That should work fine for settings attributes. Are you having a problem? If so, can you paste the actual traceback? Ryan -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma -- Configuration `` Plone 2.5.3-final, CMF-1.6.4, Zope (Zope 2.9.7-final, python 2.4.4, linux2), Five 1.4.1, Python 2.4.4 (#1, Jul 3 2007, 22:58:17) [GCC 4.1.1 20070105 (Red Hat 4.1.1-51)], PIL 1.1.6 Mailman 2.1.9 Postfix 2.4.5 Procmail v3.22 2001/09/10 -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] function to create netcdf file
On Wed, Nov 11, 2009 at 9:26 AM, John washa...@gmail.com wrote: No problem.. just wanted to make sure it would work and is 'pythonic'. I guess the biggest concern is that for others using the netcdf file, say from matlab or somewhere else, will be able to access the attributes. It seemed so easy to do it this way, I was curious why the tutorials suggest using setattr(), and I wonder if perhaps what I'm setting is not 'global' or perhaps wouldn't match some ISO or otherwise NetCDF standard?? It's actually just a nice part of the python language, setattr(a, 'foo', 'bar') is the same code as a.foo = bar. When working with NetCDF, the only time I've needed to use setarr (or getattr) is when the name of the attribute I want isn't a valid python identifier (like if an attribute has a - in it, e.g. 'unit-type'). Ryan -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] function to create netcdf file
It's actually just a nice part of the python language, setattr(a, 'foo', 'bar') is the same code as a.foo = bar. When working with NetCDF, the only time I've needed to use setarr (or getattr) is when the name of the attribute I want isn't a valid python identifier (like if an attribute has a - in it, e.g. 'unit-type'). Slick! Another great reason for python. Thanks for the rapid response. -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] differnet colormaps with pcolormesh
Hi, Is there a way to somehow squeeze two datasets with two different color maps into one pcolormesh? Say one dataset occupies one triangle (e. g. numpy.triu(dataset1, 1)) and the second dataset a different area (e. g. numpy.tril(dataset2, -1)) and then paste the two datasets in one pcolormesh (e.g. pylab.pcolormesh(numpy.triu(dataset1, 1) + numpy.tril(dataset2, -1)) ). This will obviously share one colormap. But does anybody know a trick to use two different ones? TIA Christian PS Forgot to thank Eric Firing for his tip last time I asked. Thank you Eric: You solved my problem! -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] contoured slice in 3D scatterplot
Hi, I'm running matplotlib v 0.99.0. I can create a 3D scatterplot, like this: import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D fig = plt.figure() ax = Axes3D(fig) ax.scatter( ... ) so far so good. Now, say I want to add a 2D contourplot (a slice of the 3D scatter contoured). Is there some way how I can specify along which coordinates the contourplot is plotted, or is it always plotted on the (x,y) plane? How I have tried this is by from matplotlib.mlab import griddata fi = griddata( ... ) ax.contourf(x,z,fi, ... ) # even though I specify z, it plots the contourf along the y axis. Thank you all for any pointers, Cheers, Claus -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] parsing tab separated files into dictionaries - alternative to genfromtxt?
hi all, i've been using genfromtxt to parse tab separated files for plotting purposes in matplotlib. the problem is that genfromtxt seems to give only two ways to access the contents of the file: one is by column, where you can use: d = genfromtxt(...) and then do d['header_name1'] to access the column named by 'header_name1', d['header_name2'] to access the column named by 'header_name2', etc. Or it will allow you to traverse the file line by line, and then access each header by number, i.e. for line in d: field1 = d[0] field2 = d[1] # etc. the problem is that the second method relies on knowing the order of the fields rather than just their name, and the first method does not allow line by line iteration. ideally what i would like is to be able to traverse each line of the parsed file, and then refer to each of its fields by header name, so that if the column order in the file changes my program will be unaffected: for line in d: field1 = ['header_name1'] field2 = ['header_name2'] is there a way to do this using standard matplotlib/numpy/scipy utilities? i could write my own code to do this but it seems like something somebody probably already thought of a good representation for and has implemented a more optimized version than i could write on my own. does such a thing exist? thanks very much -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] parsing tab separated files into dictionaries - alternative to genfromtxt?
ideally what i would like is to be able to traverse each line of the parsed file, and then refer to each of its fields by header name, so that if the column order in the file changes my program will be unaffected: What you want is a DictReader. For a quick example of me using that, -- aReader = csv.DictReader(open(inputFilename, 'r'), delimiter='\t') yValues = {} # Will be a dictionary of lists (these are lists of y- values) xValues = [] # List of x values (timestamps) for row in aReader: xValues.append(datetime.datetime(*(time.strptime(row ['TimeStamp'],timeStampFormat)[0:6]))) for field in sorted(row,reverse=True): # Read from last to first in field list if field=='TimeStamp': continue # Column of x-data if not field in yValues.keys(): yValues[field] = [nt(row[field])] # Start list of the values in this column else: yValues[field].append(int(row[field])) # Add to list of values in this column -- Mike -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] [Numpy-discussion] parsing tab separated files into dictionaries - alternative to genfromtxt?
On Wed, Nov 11, 2009 at 11:53 AM, per freem perfr...@gmail.com wrote: hi all, i've been using genfromtxt to parse tab separated files for plotting purposes in matplotlib. the problem is that genfromtxt seems to give only two ways to access the contents of the file: one is by column, where you can use: d = genfromtxt(...) and then do d['header_name1'] to access the column named by 'header_name1', d['header_name2'] to access the column named by 'header_name2', etc. Or it will allow you to traverse the file line by line, and then access each header by number, i.e. for line in d: field1 = d[0] field2 = d[1] # etc. the problem is that the second method relies on knowing the order of the fields rather than just their name, and the first method does not allow line by line iteration. ideally what i would like is to be able to traverse each line of the parsed file, and then refer to each of its fields by header name, so that if the column order in the file changes my program will be unaffected: for line in d: field1 = ['header_name1'] field2 = ['header_name2'] is there a way to do this using standard matplotlib/numpy/scipy utilities? i could write my own code to do this but it seems like something somebody probably already thought of a good representation for and has implemented a more optimized version than i could write on my own. does such a thing exist? thanks very much I have a constructor class to read space-delimited ASCII files. class NasaFile(object): def __init__(self, filename): ... # Reading data _data = np.loadtxt(filename, dtype='float', skiprows=self.NLHEAD).T # Read using data['Time'] syntax self.data = dict(zip(self.VDESC, _data)) ... There is a meta-header in this type of data and NLHEAD is the variable telling me how many lines to skip to reach the actual data. VDESC tells me what each columns are (starting with Time variable and many other different measurement results.) There is not any column dependence in this case, and generically read any length specifically formatted data. For instance: from nasafile import NasaFile c = NasaFile(mydata) c.data['Time'] gets me the whole Time column as an ndarray . Why do you think dictionaries are not sufficient for your case? I was using locals() to create automatic names but that was not a very wise approach. ___ NumPy-Discussion mailing list numpy-discuss...@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion -- Gökhan -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] overriding Collections.get_transform weirdness
Hi, Awhile back, Jae-Joon helped me transform collection sizes from points to data values by overriding the `get_transform` method of a RegularPolyCollection (see example code below). When I tried the code today, the collection didn't appear on the plot. Removing the get_transform method below brings the collection back, but of course, the sizes are not what I want. Some simple testing suggests that changing the transform returned by `get_transform` changes the offsets of the collection items. In other words, the transform originally (i.e. in some older revision) modified only the scale of collection items, but now appears to modify both the scale and offset. Is there a way to modify only the scale of collection items? Thanks, -Tony BTW, I'm on svn r7950. #- # The squares will not show up with the code below # Comment out the get_transform method to see squares # Change scale_x and scale_y to values close to 1 to see how they change both scale and offset class SquareCollection(collections.RegularPolyCollection): Return a collection of squares. def __init__(self, **kwargs): super(SquareCollection, self).__init__(4, rotation=np.pi/4., **kwargs) def get_transform(self): Return transform scaling circle areas to data space. ax = self.axes pts2pixels = 72.0 / ax.figure.dpi scale_x = pts2pixels * ax.bbox.width / ax.viewLim.width scale_y = pts2pixels * ax.bbox.height / ax.viewLim.height return transforms.Affine2D().scale(scale_x, scale_y) ax = plt.gca() circle_areas = np.pi * np.ones(4) xy = [(0, 0), (0, 1), (1, 0), (1, 1)] squares = SquareCollection(sizes=circle_areas, offsets=xy, transOffset=ax.transData, facecolor='black') ax.add_collection(squares, autolim=True) plt.axis([-0.5, 1.5, -0.5, 1.5]) plt.show() -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] overriding Collections.get_transform weirdness
Which older revision (or release) worked as you expected? Mike Tony S Yu wrote: Hi, Awhile back, Jae-Joon helped me transform collection sizes from points to data values by overriding the `get_transform` method of a RegularPolyCollection (see example code below). When I tried the code today, the collection didn't appear on the plot. Removing the get_transform method below brings the collection back, but of course, the sizes are not what I want. Some simple testing suggests that changing the transform returned by `get_transform` changes the offsets of the collection items. In other words, the transform originally (i.e. in some older revision) modified only the scale of collection items, but now appears to modify both the scale and offset. Is there a way to modify only the scale of collection items? Thanks, -Tony BTW, I'm on svn r7950. #- # The squares will not show up with the code below # Comment out the get_transform method to see squares # Change scale_x and scale_y to values close to 1 to see how they change both scale and offset class SquareCollection(collections.RegularPolyCollection): Return a collection of squares. def __init__(self, **kwargs): super(SquareCollection, self).__init__(4, rotation=np.pi/4., **kwargs) def get_transform(self): Return transform scaling circle areas to data space. ax = self.axes pts2pixels = 72.0 / ax.figure.dpi scale_x = pts2pixels * ax.bbox.width / ax.viewLim.width scale_y = pts2pixels * ax.bbox.height / ax.viewLim.height return transforms.Affine2D().scale(scale_x, scale_y) ax = plt.gca() circle_areas = np.pi * np.ones(4) xy = [(0, 0), (0, 1), (1, 0), (1, 1)] squares = SquareCollection(sizes=circle_areas, offsets=xy, transOffset=ax.transData, facecolor='black') ax.add_collection(squares, autolim=True) plt.axis([-0.5, 1.5, -0.5, 1.5]) plt.show() -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Michael Droettboom Science Software Branch Operations and Engineering Division Space Telescope Science Institute Operated by AURA for NASA -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] matplotlib slow compared to gnuplot?
It looks like you are storing your source data in a python list. Matplotlib runs much faster if you store your data using a numpy array instead. I'm no expert, but it certianly sped up my graph drawing. -Tom Message: 5 Date: Wed, 11 Nov 2009 08:53:58 -0600 From: Mike Anderson mbander...@wisc.edu Subject: [Matplotlib-users] matplotlib slow compared to gnuplot? To: matplotlib-users@lists.sourceforge.net Message-ID: ae4d4739-44be-43f2-9e56-daedbe990...@wisc.edu Content-Type: text/plain; charset=us-ascii; format=flowed; delsp=yes Hi all, Previously I was a user of gnuplot but have been giving matplotlib a try. One thing I've run in to right away is that matplotlib appears to be significantly slower. A script to produce a dozen plots was taking me ~1 second with gnuplot, and now takes me ~18 seconds with matplotlib. I'm curious if anyone knows how to speed things up. To figure out what is taking most of the time, I've used cProfile and pstats and below is the top 15 functions taking the most time. (note: plotStackedJobsVsTime is my function that uses matplotlib.) My script, for the curious, is at http://www.hep.wisc.edu/cms/comp/routerqMonitor/prodJobMonitorPlots_matplotlib.py and produces these plots: http://www.hep.wisc.edu/cms/comp/routerqMonitor/index.html Any hints at what I can do to speed up my script? Or is it out of my hands because it's all in matplotlib? Thanks for any help, Mike -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] overriding Collections.get_transform weirdness
On Nov 11, 2009, at 1:33 PM, Michael Droettboom wrote: Which older revision (or release) worked as you expected? After some digging, I think this issue is caused by an error in the macosx backend (everything works fine with tkagg, qt4agg, and agg). Oddly enough, calling savefig(), instead of show(), with the macosx backend creates the correct plot, but calling savefig() after show() does not. I'm actually not sure if my code worked for older revisions of the macosx backend (I may have had a different default backend before). The transform code doesn't work with revisions between 7950 and 7625; older versions break the macosx backend on my system (OS X 10.6.1). -Tony Mike Tony S Yu wrote: Hi, Awhile back, Jae-Joon helped me transform collection sizes from points to data values by overriding the `get_transform` method of a RegularPolyCollection (see example code below). When I tried the code today, the collection didn't appear on the plot. Removing the get_transform method below brings the collection back, but of course, the sizes are not what I want. Some simple testing suggests that changing the transform returned by `get_transform` changes the offsets of the collection items. In other words, the transform originally (i.e. in some older revision) modified only the scale of collection items, but now appears to modify both the scale and offset. Is there a way to modify only the scale of collection items? Thanks, -Tony BTW, I'm on svn r7950. #- # The squares will not show up with the code below # Comment out the get_transform method to see squares # Change scale_x and scale_y to values close to 1 to see how they change both scale and offset class SquareCollection(collections.RegularPolyCollection): Return a collection of squares. def __init__(self, **kwargs): super(SquareCollection, self).__init__(4, rotation=np.pi/ 4., **kwargs) def get_transform(self): Return transform scaling circle areas to data space. ax = self.axes pts2pixels = 72.0 / ax.figure.dpi scale_x = pts2pixels * ax.bbox.width / ax.viewLim.width scale_y = pts2pixels * ax.bbox.height / ax.viewLim.height return transforms.Affine2D().scale(scale_x, scale_y) ax = plt.gca() circle_areas = np.pi * np.ones(4) xy = [(0, 0), (0, 1), (1, 0), (1, 1)] squares = SquareCollection(sizes=circle_areas, offsets=xy, transOffset=ax.transData, facecolor='black') ax.add_collection(squares, autolim=True) plt.axis([-0.5, 1.5, -0.5, 1.5]) plt.show() -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Michael Droettboom Science Software Branch Operations and Engineering Division Space Telescope Science Institute Operated by AURA for NASA -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Unwanted lines between contourf() contour levels
Hello, In my filled contour plot: http://imgur.com/vXoCL.png There are faint lines between the contour levels. I think they are yellow since they disappear in the yellow parts of the graph and are most obvious in the red areas. Is there any way to get rid of these lines? The number of contour levels is arbitrary, and I don't need them emphasized with a moire pattern. Thank you, -Ryan -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Noob confusion: Pcolor
Thanks for your reply, Giorgio. I had a look at the documentation for pcolor but unfortunately, I can't pick out where I have gone wrong. I have attached my data array as a txt file. In ipython, I use the 'loadtxt' command to load the dataset and then assigned the variables x,y, and z to the first, second and third columns respectively. I then specified the meshgrid X,Y from the x and y arrays of my data and used pcolor(X,Y,z) to try and plot the color map. Thanks a lot! On Thu, Nov 12, 2009 at 4:36 AM, Giorgio_Luciano giorgio_luci...@libero.itwrote: Can you send and example of the matrix you are using ? Are you sure to have specified correct input according to http://matplotlib.sourceforge.net/api/pyplot_api.html?highlight=pcolor#matplotlib.pyplot.pcolor Cheers Giorgio 0 0 195.552 -13.2 9 107.092 -13.2 11.6421 158.136 -13.2 14.2842 105.09 -13.2 16.9263 123.106 -13.2 19.5684 133.114 -13.2 22.2105 93.0799 -13.2 24.8526 91.0782 -13.2 27.4947 83.0713 -13.2 30.1368 89.0765 -13.2 32.7789 97.0834 -13.2 35.4211 89.0765 -13.2 38.0632 93.0799 -13.2 40.7053 92.0791 -13.2 43.3474 86.0739 -13.2 45.9895 90.0773 -13.2 48.6316 89.0765 -13.2 51.2737 89.0765 -13.2 53.9158 88.0756 -13.2 56.5579 89.0765 -13.2 59.2 81.0696 -10.3895 9 107.092 -10.3895 11.6421 111.095 -10.3895 14.2842 123.106 -10.3895 16.9263 136.117 -10.3895 19.5684 133.114 -10.3895 22.2105 98.0842 -10.3895 24.8526 94.0808 -10.3895 27.4947 96.0825 -10.3895 30.1368 93.0799 -10.3895 32.7789 86.0739 -10.3895 35.4211 91.0782 -10.3895 38.0632 93.0799 -10.3895 40.7053 92.0791 -10.3895 43.3474 82.0705 -10.3895 45.9895 83.0713 -10.3895 48.6316 91.0782 -10.3895 51.2737 97.0834 -10.3895 53.9158 94.0808 -10.3895 56.5579 108.093 -10.3895 59.2 88.0756 -7.57895 9 81.0696 -7.57895 11.6421 83.0713 -7.57895 14.2842 89.0765 -7.57895 16.9263 93.0799 -7.57895 19.5684 87.0748 -7.57895 22.2105 100.086 -7.57895 24.8526 83.0713 -7.57895 27.4947 96.0825 -7.57895 30.1368 85.073 -7.57895 32.7789 94.0808 -7.57895 35.4211 87.0748 -7.57895 38.0632 87.0748 -7.57895 40.7053 100.086 -7.57895 43.3474 94.0808 -7.57895 45.9895 89.0765 -7.57895 48.6316 89.0765 -7.57895 51.2737 98.0842 -7.57895 53.9158 86.0739 -7.57895 56.5579 94.0808 -7.57895 59.2 87.0748 -4.76842 9 92.0791 -4.76842 11.6421 86.0739 -4.76842 14.2842 93.0799 -4.76842 16.9263 89.0765 -4.76842 19.5684 85.073 -4.76842 22.2105 97.0834 -4.76842 24.8526 84.0722 -4.76842 27.4947 98.0842 -4.76842 30.1368 93.0799 -4.76842 32.7789 89.0765 -4.76842 35.4211 79.0679 -4.76842 38.0632 96.0825 -4.76842 40.7053 97.0834 -4.76842 43.3474 91.0782 -4.76842 45.9895 86.0739 -4.76842 48.6316 82.0705 -4.76842 51.2737 104.089 -4.76842 53.9158 100.086 -4.76842 56.5579 97.0834 -4.76842 59.2 91.0782 -1.95789 9 102.088 -1.95789 11.6421 82.0705 -1.95789 14.2842 101.087 -1.95789 16.9263 95.0816 -1.95789 19.5684 82.0705 -1.95789 22.2105 89.0765 -1.95789 24.8526 92.0791 -1.95789 27.4947 103.089 -1.95789 30.1368 85.073 -1.95789 32.7789 81.0696 -1.95789 35.4211 96.0825 -1.95789 38.0632 85.073 -1.95789 40.7053 94.0808 -1.95789 43.3474 85.073 -1.95789 45.9895 94.0808 -1.95789 48.6316 91.0782 -1.95789 51.2737 93.0799 -1.95789 53.9158 87.0748 -1.95789 56.5579 109.094 -1.95789 59.2 90.0773 0.852632 9 103.089 0.852632 11.6421 89.0765 0.852632 14.2842 84.0722 0.852632 16.9263 95.0816 0.852632 19.5684 95.0816 0.852632 22.2105 86.0739 0.852632 24.8526 91.0782 0.852632 27.4947 96.0825 0.852632 30.1368 87.0748 0.852632 32.7789 95.0816 0.852632 35.4211 98.0842 0.852632 38.0632 92.0791 0.852632 40.7053 88.0756 0.852632 43.3474 85.073 0.852632 45.9895 93.0799 0.852632 48.6316 84.0722 0.852632 51.2737 89.0765 0.852632 53.9158 78.067 0.852632 56.5579 100.086 0.852632 59.2 96.0825 3.66316 9 83.0713 3.66316 11.6421 94.0808 3.66316 14.2842 91.0782 3.66316 16.9263 85.073 3.66316 19.5684 90.0773 3.66316 22.2105 90.0773 3.66316 24.8526 81.0696 3.66316 27.4947 94.0808 3.66316 30.1368 100.086 3.66316 32.7789 92.0791 3.66316 35.4211 85.073 3.66316 38.0632 100.086 3.66316 40.7053 92.0791 3.66316 43.3474 80.0687 3.66316 45.9895 91.0782 3.66316 48.6316 88.0756 3.66316 51.2737 94.0808 3.66316 53.9158 96.0825 3.66316 56.5579 86.0739 3.66316 59.2 92.0791 6.47368 9 97.0834 6.47368 11.6421 104.089 6.47368 14.2842 80.0687 6.47368 16.9263 87.0748 6.47368 19.5684 118.101 6.47368 22.2105 120.103 6.47368 24.8526 86.0739 6.47368 27.4947 91.0782 6.47368 30.1368 81.0696 6.47368 32.7789 90.0773 6.47368 35.4211 84.0722 6.47368 38.0632 90.0773 6.47368 40.7053 83.0713 6.47368 43.3474 87.0748 6.47368 45.9895 92.0791 6.47368 48.6316 97.0834 6.47368 51.2737 91.0782 6.47368 53.9158 91.0782 6.47368 56.5579 96.0825 6.47368 59.2 103.089 9.28421 9 104.089 9.28421 11.6421 104.089 9.28421 14.2842 117.101 9.28421 16.9263 93.0799 9.28421 19.5684 106.091 9.28421 22.2105 97.0834 9.28421 24.8526 96.0825 9.28421 27.4947 94.0808 9.28421 30.1368 89.0765 9.28421 32.7789 89.0765 9.28421 35.4211 97.0834 9.28421 38.0632 84.0722 9.28421 40.7053 91.0782 9.28421 43.3474 88.0756 9.28421 45.9895 95.0816 9.28421 48.6316
Re: [Matplotlib-users] Noob confusion: Pcolor
On Wed, Nov 11, 2009 at 3:22 PM, Shrividya Ravi penthesel...@gmail.com wrote: Thanks for your reply, Giorgio. I had a look at the documentation for pcolor but unfortunately, I can't pick out where I have gone wrong. I have attached my data array as a txt file. In ipython, I use the 'loadtxt' command to load the dataset and then assigned the variables x,y, and z to the first, second and third columns respectively. I then specified the meshgrid X,Y from the x and y arrays of my data and used pcolor(X,Y,z) to try and plot the color map. You have to interpolate your 1D data onto a 2D grid -- # first load the data In [504]: x,y,z = np.loadtxt('195pt52_T6.txt', unpack=True) # create evenly sampled x and y vectors to interpolate onto In [505]: xi = np.linspace(x.min(), x.max(), 20) In [506]: yi = np.linspace(y.min(), y.max(), 20) # use griddata to do the 2D interoplation In [507]: Z = mlab.griddata(x, y, z, xi, yi) In [508]: Z.shape Out[508]: (20, 20) # use meshgrid to create 2D grids of your 1D x and 1 data In [509]: X, Y = np.meshgrid(xi, yi) # pass all the 2D arrays to pcolor In [510]: pcolor(X, Y, Z) Out[510]: matplotlib.collections.PolyCollection object at 0x113e6d8c Hope this helps! -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Unwanted lines between contourf() contour levels
Ryan Neve wrote: Hello, In my filled contour plot: http://imgur.com/vXoCL.png There are faint lines between the contour levels. I think they are yellow since they disappear in the yellow parts of the graph and are most obvious in the red areas. Is there any way to get rid of these lines? The number of contour levels is arbitrary, and I don't need them emphasized with a moire pattern. Try experimenting with the antialiased kwarg in your call to contourf. It is a boolean; see if a value of True or False gives a better result. Eric Thank you, -Ryan -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Noob confusion: Pcolor
Tue, 10 Nov 2009 23:45:10 -0800, shriv wrote: I am a very new user to both python and matplotlib so please beware that my questions might be a real no-brainer. Here goes: I have a 3D array of data that I isolated from a much larger dataset. The first two columns are the x and y positions while the third is the intensity at the position (xi, yi). I would like to produce a colour map of the intensity as a function of x and y positions. Numerous tries with pcolor have got me nowhere. I constantly get an error message saying Too many indices. You need to regrid your data on a regular grid, not at scattered positions. See http://matplotlib.sourceforge.net/api/mlab_api.html#matplotlib.mlab.griddata -- Pauli Virtanen -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] differnet colormaps with pcolormesh
I'm not exactly sure what you're trying to do. but I think what you want can be easily achieved by simply using the masked array. Is the example below similar to what you need? a = np.arange(100).reshape((10,10)) m1 = np.triu(a, 1) 0 m2 = np.tril(a, -1) 0 #m2 = ~m1 am1 = np.ma.array(a, mask=m1) am2 = np.ma.array(a, mask=m2) pcolormesh(am1, cmap=plt.cm.jet) pcolormesh(am2, cmap=plt.cm.gray) -JJ On Wed, Nov 11, 2009 at 12:11 PM, Christian Meesters meest...@imbie.uni-bonn.de wrote: Hi, Is there a way to somehow squeeze two datasets with two different color maps into one pcolormesh? Say one dataset occupies one triangle (e. g. numpy.triu(dataset1, 1)) and the second dataset a different area (e. g. numpy.tril(dataset2, -1)) and then paste the two datasets in one pcolormesh (e.g. pylab.pcolormesh(numpy.triu(dataset1, 1) + numpy.tril(dataset2, -1)) ). This will obviously share one colormap. But does anybody know a trick to use two different ones? TIA Christian PS Forgot to thank Eric Firing for his tip last time I asked. Thank you Eric: You solved my problem! -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] bug in set_yscale of bar graphs?
The bar command makes rectangles whose bottom position is 0. The reason that bars disappear when you set log scale is that bottom position of the bar become -infinity. You may * set log scale before calling the bar or * create bar plot but with reasonable (positive) bottom value. Take a look at the docs. Regards, -JJ On Wed, Nov 11, 2009 at 5:25 PM, per freem perfr...@gmail.com wrote: hi all, I am trying to make a simple bar graph that has its yaxis scale set to log. I use the following code: import matplotlib matplotlib.use('PDF') import matplotlib.pyplot as plt from matplotlib import rc rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']}) plt.rcParams['ps.useafm'] = True rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']}) plt.rcParams['pdf.fonttype'] = 42 plt.rcParams['font.size'] = 10 x = range(1, 11) y = [5000, 900, 600, 500, 200, 110, 50, 20, 10, 5] plt.figure(figsize=(5, 5), dpi=300) plt.bar(x, y) plt.gca().set_yscale('log') plt.savefig('test_logscale.pdf') the problem is that the bar graphs do not appear -- instead, i simply get horizontal lines around where the top of the bar graph should appear. Any idea how to fix this? also, sometimes the x axis disappears when i try this. thanks. -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] bug in set_yscale of bar graphs?
On Wed, Nov 11, 2009 at 4:25 PM, per freem perfr...@gmail.com wrote: hi all, I am trying to make a simple bar graph that has its yaxis scale set to log. I use the following code: import matplotlib matplotlib.use('PDF') import matplotlib.pyplot as plt from matplotlib import rc rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']}) plt.rcParams['ps.useafm'] = True rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']}) plt.rcParams['pdf.fonttype'] = 42 plt.rcParams['font.size'] = 10 x = range(1, 11) y = [5000, 900, 600, 500, 200, 110, 50, 20, 10, 5] plt.figure(figsize=(5, 5), dpi=300) plt.bar(x, y) It should work scaling from within the bar() plt.bar(x, y, log=True) # plt.gca().set_yscale('log') plt.savefig('test_logscale.pdf') the problem is that the bar graphs do not appear -- instead, i simply get horizontal lines around where the top of the bar graph should appear. Any idea how to fix this? also, sometimes the x axis disappears when i try this. thanks. -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Gökhan -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] matplotlib with Qt4 backend
I just installed matplotlib on Snow Leopard 10.6 with the Qt4 backend (via macports). However, when I try one of the Qt4 examles: python /opt/local/share/py26-matplotlib/examples/user_interfaces/embedding_in_qt4.py I get the following error message: Traceback (most recent call last): File /opt/local/share/py26-matplotlib/examples/user_interfaces/embedding_in_qt4.py, line 70, in update_figure self.draw() File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/backends/backend_qt4agg.py, line 130, in draw FigureCanvasAgg.draw(self) File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/backends/backend_agg.py, line 314, in draw self.figure.draw(self.renderer) File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/artist.py, line 46, in draw_wrapper draw(artist, renderer, *kl) File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/figure.py, line 773, in draw for a in self.axes: a.draw(renderer) File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/artist.py, line 46, in draw_wrapper draw(artist, renderer, *kl) File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/axes.py, line 1735, in draw a.draw(renderer) File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/artist.py, line 46, in draw_wrapper draw(artist, renderer, *kl) File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/axis.py, line 742, in draw tick.draw(renderer) File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/artist.py, line 46, in draw_wrapper draw(artist, renderer, *kl) File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/axis.py, line 196, in draw self.label1.draw(renderer) File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/text.py, line 515, in draw bbox, info = self._get_layout(renderer) File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/text.py, line 272, in _get_layout 'lp', self._fontproperties, ismath=False) File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/backends/backend_agg.py, line 158, in get_text_width_height_descent font = self._get_agg_font(prop) File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/backends/backend_agg.py, line 195, in _get_agg_font fname = findfont(prop) File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/font_manager.py, line 1308, in findfont _rebuild() File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/font_manager.py, line 1292, in _rebuild fontManager = FontManager() File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/font_manager.py, line 984, in __init__ self.ttffiles = findSystemFonts(paths) + findSystemFonts() File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/font_manager.py, line 341, in findSystemFonts for f in get_fontconfig_fonts(fontext): File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/font_manager.py, line 303, in get_fontconfig_fonts status, output = commands.getstatusoutput(fc-list file) File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/commands.py, line 56, in getstatusoutput text = pipe.read() IOError: [Errno 4] Interrupted system call Any ideas on what could be causing this? celil -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Strange event errors with WXAgg + wx
Hello. I'm trying to embed mpl in an wxpython app which is intended to run repeatedly within a single script. (It's a workaround for not being able to use pyplot.show() more than once in a script.) All seems to work as intended when I don't attach any key press events (here to just destroy the app) to canvas, but when I do, as in the script below, for some reason I keep getting errors that appear to indicate that some remnant of the zombie of the previous app instance may be sticking around when they shouldn't exist. Both the script in question and the (typical) error message are shown below in this message. I've tried both on Linux (Debian Lenny) and Mac OS X (Leopard) with Python 2.5 with the latest stable versions of numpy, matplotlib, wxpython and whatnot. I observe similar problems on both environments. What am I doing wrong? Am I not properly handling the cleanup process before destroying the app at each loop? I think wx.App.MainLoop() can be run more than once within a script, so that should be okay, though I'm not sure if mpl is designed to be used this way. A strange thing is that when I close the app by clicking on the 'X' on the Window frame, I don't reproduce the error. If anything, I wonder how to initiate the event that imitates that behavior, but that is probably a question for the wxpython people... I'd appreciate any assistance! Cheers, Taro BEGIN SCRIPT #!/usr/bin/env python import wxversion wxversion.ensureMinimal('2.8') import matplotlib matplotlib.use('WXAgg') from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas from matplotlib.figure import Figure from numpy import arange, sin, pi import wx class CanvasFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, 'CanvasFrame',size=(550,350)) self.figure = Figure() self.axes = self.figure.add_subplot(111) t = arange(0.0, 3.0, 0.01) s = sin(2 * pi * t) self.axes.plot(t, s) self.canvas = FigureCanvas(self, -1, self.figure) self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) self.canvas.mpl_connect('key_press_event', self.key_press) self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) self.SetSizer(self.sizer) self.Fit() def key_press(self, event): self.Close(True) def OnCloseWindow(self, event): print 'Window Closed' self.Destroy() class App(wx.App): def OnInit(self): frame = CanvasFrame() frame.Show(True) return True def run_app(): app = App(redirect=False) app.MainLoop() del app for i in range(10): run_app() END SCRIPT BEGIN ERROR MESSAGE Traceback (most recent call last): File /usr/lib/python2.5/site-packages/matplotlib/backends/backend_wx.py, line 1316, in _onMotion FigureCanvasBase.motion_notify_event(self, x, y, guiEvent=evt) File /usr/lib/python2.5/site-packages/matplotlib/backend_bases.py, line 1244, in motion_notify_event guiEvent=guiEvent) File /usr/lib/python2.5/site-packages/matplotlib/backend_bases.py, line 899, in __init__ LocationEvent.__init__(self, name, canvas, x, y, guiEvent=guiEvent) File /usr/lib/python2.5/site-packages/matplotlib/backend_bases.py, line 817, in __init__ self._update_enter_leave() File /usr/lib/python2.5/site-packages/matplotlib/backend_bases.py, line 844, in _update_enter_leave last.canvas.callbacks.process('axes_leave_event', last) File /usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode/wx/_core.py, line 14314, in __getattr__ raise PyDeadObjectError(self.attrStr % self._name) wx._core.PyDeadObjectError: The C++ part of the FigureCanvasWxAgg object has been deleted, attribute access no longer allowed. END ERROR MESSAGE -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users