Ok, fair enough. Let's use that:

------------------
import numpy as np
import matplotlib.cm as cm
import  matplotlib.pyplot as plt

n = 100000
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 <jdh2358@gmail.com> wrote:
On Wed, Jun 17, 2009 at 5:31 PM, Alexandar Hansen<viochemist@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 = 100000
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()