[Matplotlib-users] Pre-defined binning with hexbin ... impossible?

2009-06-30 Thread Alexandar Hansen
Hello,

I've been struggling with this for a while now and have effectively two
issues. One, how can I define the range over which hexbin ... bins? And two,
how do I change the background color of a plot? The latter I thought would
be trivial, but nothing I've tried has worked.  Let's take the example:

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()
xmin = 0
xmax = 10
ymin = 0
ymax = 30

plt.hexbin(x,y, cmap=cm.jet)
#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.show()


Let's say i'm only interested in the positive quadrant of the data, so I
only want to bin data in the range of 0-10 in x and 0-30 in y.  The first
thing I tried was to use the extent option to only bin the specified range
of data, but that gives these errors:

[tesla:~/NMR/500-Tupp/IM7][349] HexBin.py
Traceback (most recent call last):
  File HexBin.py, line 28, in module
plt.hexbin(x,y, cmap=cm.jet, extent=[xmin, xmax, ymin, ymax])
  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


After that, I just set the plt.axis range to what I'm interested in.
However, the range not binned by hexbin shows up as white, instead of the
0-count blue. I've tried adding facecolor, edgecolor, axisbg, and who knows
what else as part of plt.hexbin, plt.axis, and plt.savefig, But most have no
consequence on the plot. plt.savefig(myname, facecolor='blue') successfully
changed everything blue except the white region within the plot.

So, where am I going wrong? I'm finding myself out of options and would
ideally not like to trim or add false points to my data just to get the axis
and colors correct.

Best,
Alex
--
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] hexbin extent Attribute Error

2009-06-25 Thread Alexandar Hansen
Does this code work for anyone else?


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()


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


Best,
Alex



On Thu, Jun 18, 2009 at 11:27 AM, Alexandar Hansen viochem...@gmail.comwrote:

 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()



--
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] hexbin extent Attribute Error

2009-06-18 Thread Alexandar Hansen
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


[Matplotlib-users] hexbin extent Attribute Error

2009-06-17 Thread Alexandar Hansen
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:

#  import matplotlib.pyplot as plt

#  plt.hexbin(x,y, cmap=cm.hot, gridsize=(50,50))
#  plt.axis([xmin, xmax, ymin, ymax])
#  plt.title(2D Histogram)
#  cb = plt.colorbar()
#  cb.set_label('counts')

#  plt.show()

where xmin, etc are a fixed range. If my data sets span sizeably different
ranges, then the hexagon sizes come out completely different. I'd like to
avoid increasing the gridsize in one or both dimensions too much as that
would require very large grids in some instances.

I thought my solution to the problems would be to use the extent function in
hexbin but when I try, for instance:

#  plt.hexbin(x,y, cmap=cm.hot, gridsize=(50,50),
extent=[xmin,xmax,ymin,ymax])

I get these strange errors:

  File HexPlotLog.py, line 64, in module
plt.hexbin(x,y, cmap=cm.hot, gridsize=(50,50), extent=[xmin, xmax, ymin,
ymax])
  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 other thing I'd like to do is to set the background color of the plot to
black, or otherwise the same color as a bin of zero. I imagine this is
something I can find in the manuals, but since I'm asking questions, may as
well include it :)

I appreciate any help that can be offered.

Best,

Alex
--
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