Re: [Matplotlib-users] hexbin extent Attribute Error
Ok, fair enough. Let's use that: -- import numpy as np import matplotlib.cm as cm import matplotlib.pyplot as plt n = 10 x = np.random.standard_normal(n) y = 2.0 + 3.0 * x + 4.0 * np.random.standard_normal(n) xmin = x.min() xmax = x.max() ymin = y.min() ymax = y.max() plt.hexbin(x,y, cmap=cm.jet, gridsize=(50,50), extent=[-2,2,-10,10]) plt.axis([xmin, xmax, ymin, ymax]) plt.title(Hexagon binning) cb = plt.colorbar() cb.set_label('counts') plt.show() -- I trimmed this from the example, which works fine. Without the extent option, I get the expected plot of all the data. But, what I'd like is to trim out some of the empty regions. If I just reset xmin, xmax, etc. the binning of the data still occurs over the entire range of the data in x and y, although the plot is correct, but the plot doesn't have the desired 50x50 bins. With the extent option I get these errors: Traceback (most recent call last): File HexBin.py, line 23, in module plt.hexbin(x,y, cmap=cm.jet, extent=[-2,2,-10,10]) File /usr/lib64/python2.5/site-packages/matplotlib/pyplot.py, line 1920, in hexbin ret = gca().hexbin(*args, **kwargs) File /usr/lib64/python2.5/site-packages/matplotlib/axes.py, line 5447, in hexbin collection.update(kwargs) File /usr/lib64/python2.5/site-packages/matplotlib/artist.py, line 548, in update raise AttributeError('Unknown property %s'%k) AttributeError: Unknown property extent The same thing as before. It doesn't know what 'extent' is for some reason. Or, perhaps more accurately, hexbin knows what it is but artist.py doesn't? The only solution i've come up with is to trim the original data that I input, but that is far from ideal. Best, Alex On Wed, Jun 17, 2009 at 7:50 PM, John Hunter jdh2...@gmail.com wrote: On Wed, Jun 17, 2009 at 5:31 PM, Alexandar Hansenviochem...@gmail.com wrote: Hello, I've been having fun using hexbin, but I'd like to have consistent bin sizes and plot ranges for different sets of data. What I'm finding is that the bin sizes are primarily determined by the input data mins and maxes. For instance, I'm plotting data with something like: Instead of a something like could you please post a complete example that we can run so we can replicate the error. This saves us a lot of time. Also, please report any version info, as described at http://matplotlib.sourceforge.net/faq/troubleshooting_faq.html#report-a-problem For example, the following runs for me using mpl svn: import numpy as np import matplotlib.cm as cm import matplotlib.pyplot as plt n = 10 x = np.random.standard_normal(n) y = 2.0 + 3.0 * x + 4.0 * np.random.standard_normal(n) xmin = x.min() xmax = x.max() ymin = y.min() ymax = y.max() plt.subplots_adjust(hspace=0.5) plt.subplot(121) plt.hexbin(x,y, cmap=cm.jet, extent=[xmin, xmax, ymin, ymax]) plt.axis([xmin, xmax, ymin, ymax]) plt.title(Hexagon binning) cb = plt.colorbar() cb.set_label('counts') plt.subplot(122) plt.hexbin(x,y,bins='log', cmap=cm.jet) plt.axis([xmin, xmax, ymin, ymax]) plt.title(With a log color scale) cb = plt.colorbar() cb.set_label('log10(N)') plt.show() -- Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Updating tick labels when using animation
Hi John, I solved the bug. In my application I have several threads. One of the threads updates the graph on a timer and another gets data from the application in order to plot. The thread updating the limits was based on data coming from the application. As I stated this is a two part process where the first part is setting the limits and the second is redrawing the graph (followed by updating the background). The problem is when the thread loses control between these two stages. In this case the background is updated to the old limits although the 'real' limits remain the updated version. The solution is to use a lock to ensure that everything is done atomically. This results in the desired behaviour. IOW it was completely my fault although an interesting bug:) Elan --- Fortunately, the second-to-last bug has just been fixed. - Ray Simard On Wed, Jun 17, 2009 at 7:20 PM, John Hunterjdh2...@gmail.com wrote: On Wed, Jun 17, 2009 at 5:27 PM, Elan Pavlovepav...@gmail.com wrote: Hi, I'm using an animated graph in which most of the time I don't want it to autoscale (due to speed). Once in a while I want it to change the limits of the y-axis. In order to do this I use set_ylim and follow by a canvas.draw(). However it does not actually redraw the canvas and the old tick labels remain (although the scales are reset). When I manually resize the canvas in updates the tick labels. Any ideas what I'm doing wrong? This doesn't sound right -- a call to canvas.draw should redraw the whole canvas cleanly, with the exception of Artists where the animated property is set. Can you reduce your code to a free-standing example that we can run? JDH -- If I knew that a man was coming to my house with the conscious design of doing me good, I should run for my life. - Henry David Thoreau -- Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Tutorial on working with Excel files in Python (without COM and cross platform!) at EuroPython 2009
Hi All, Too many people in the Python community *still* think the only way to work with Excel files in Python is using COM on Windows. To try and correct this, I'm giving a tutorial at this year's EuroPython conference in Birmingham, UK on Monday, 29th June that will cover working with Excel files in Python using the pure-python libraries xlrd, xlwt and xlutils. I'll be looking to cover: - Reading Excel Files Including extracting all the data types, formatting and working with large files. - Writing Excel Files Including formatting, many of the useful frilly extras and writing large excel files. - Modifying and Filtering Excel Files A run through of taking existing Excel files and modifying them in various ways. - Workshop for your problems I'm hoping anyone who attends will get a lot out of this! If you're planning on attending and have a particular problem you'd like to work on in this part of the tutorial, please drop me an email and I'll try and make sure I come prepared! All you need for the tutorial is a working knowledge of Excel and Python, with a laptop as an added benefit, and to be at EuroPython this year: http://www.europython.eu/ I look forward to seeing you all there! Chris -- Simplistix - Content Management, Zope Python Consulting - http://www.simplistix.co.uk -- Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Help with transforms of collections
I'd like to plot a collection and scale the size of the collection elements in relation to the data. My guess is that I need to use the data transformation (ax.transData) since I would like the size of the collection elements altered when zooming in/out. Unfortunately, my attempt has led to weird results: the collection offsets are shifted from the desired coordinates when using ax.transData. Weirder still: the collection elements move *relative to the data coordinates* when panning the figure. I suspect that setting the collection transform to ax.transData is somehow applying some part of the transform twice. Does anyone know what I'm doing wrong here and how I can fix this? Thanks! -Tony Attached is a toy example of what I'm trying to do. The radii of the circles are plotted correctly, but notice the x, y coordinates don't match the circle centers in the plot. Also, try panning the plot and watch as the circles move relative to the tick marks. import matplotlib.pyplot as plt import matplotlib.transforms as transforms import numpy as np fig = plt.figure() ax = fig.add_subplot(111) x = [0.25, 0.75, 0.25, 0.75] y = [0.25, 0.25, 0.75, 0.75] r = 0.1 * np.ones(4) col = plt.scatter(x, y, np.pi*r**2) pts2pixels = transforms.Affine2D().scale(72.0/fig.dpi) col.set_transform(pts2pixels + ax.transData) plt.axis('equal') plt.show() -- Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users