From: <ef...@us...> - 2008-04-28 18:27:25
|
Revision: 5093 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5093&view=rev Author: efiring Date: 2008-04-28 11:26:08 -0700 (Mon, 28 Apr 2008) Log Message: ----------- Add hexbin_demo, and use log10 for log in hexbin Modified Paths: -------------- trunk/matplotlib/examples/backend_driver.py trunk/matplotlib/lib/matplotlib/axes.py Added Paths: ----------- trunk/matplotlib/examples/hexbin_demo.py Modified: trunk/matplotlib/examples/backend_driver.py =================================================================== --- trunk/matplotlib/examples/backend_driver.py 2008-04-28 16:52:44 UTC (rev 5092) +++ trunk/matplotlib/examples/backend_driver.py 2008-04-28 18:26:08 UTC (rev 5093) @@ -49,6 +49,7 @@ 'fill_demo.py', 'finance_demo.py', 'fonts_demo_kw.py', + 'hexbin_demo.py', 'histogram_demo.py', 'hline_demo.py', 'image_demo.py', Added: trunk/matplotlib/examples/hexbin_demo.py =================================================================== --- trunk/matplotlib/examples/hexbin_demo.py (rev 0) +++ trunk/matplotlib/examples/hexbin_demo.py 2008-04-28 18:26:08 UTC (rev 5093) @@ -0,0 +1,34 @@ +''' +hexbin is an axes method or pyplot function that is essentially +a pcolor of a 2-D histogram with hexagonal cells. It can be +much more informative than a scatter plot; in the first subplot +below, try substituting 'scatter' for 'hexbin'. +''' + +from matplotlib.pyplot import * +import numpy as np + +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() + +subplot(121) +hexbin(x,y) +axis([xmin, xmax, ymin, ymax]) +title("Hexagon binning") +cb = colorbar() +cb.set_label('counts') + +subplot(122) +hexbin(x,y,bins='log') +axis([xmin, xmax, ymin, ymax]) +title("With a log color scale") +cb = colorbar() +cb.set_label('log10(N)') + +show() + Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2008-04-28 16:52:44 UTC (rev 5092) +++ trunk/matplotlib/lib/matplotlib/axes.py 2008-04-28 18:26:08 UTC (rev 5093) @@ -4447,7 +4447,7 @@ each hexagon directly corresponds to its count value. bins='log' : Use a logarithmic scale for the color map. - Internally, log(count+1) is used to determine + Internally, log10(count+1) is used to determine the hexagon color. bins=<integer> : Divide the counts in the specified number of bins, and color the hexagons accordingly @@ -4456,10 +4456,10 @@ to be used. * xscale = 'linear' | 'log': - Use a logarithmic scale on the horizontal axis. + Use a log10 scale on the horizontal axis. * yscale = 'linear' | 'log': - Use a logarithmic scale on the vertical axis. + Use a log10 scale on the vertical axis. Other keyword args; the color mapping and normalization arguments. @@ -4516,9 +4516,9 @@ x = npy.array(x, float) y = npy.array(y, float) if xscale=='log': - x = npy.log(x) + x = npy.log10(x) if yscale=='log': - y = npy.log(y) + y = npy.log10(y) xmin = min(x) xmax = max(x) ymin = min(y) @@ -4574,14 +4574,14 @@ polygons[:,:,1] += py if xscale=='log': - polygons[:,:,0] = npy.exp(polygons[:,:,0]) - xmin = math.exp(xmin) - xmax = math.exp(xmax) + polygons[:,:,0] = 10**(polygons[:,:,0]) + xmin = 10**xmin + xmax = 10**xmax self.set_xscale('log') if yscale=='log': - polygons[:,:,1] = npy.exp(polygons[:,:,1]) - ymin = math.exp(ymin) - ymax = math.exp(ymax) + polygons[:,:,1] = 10**(polygons[:,:,1]) + ymin = 10**ymin + ymax = 10**ymax self.set_yscale('log') class HexagonBinCollection(mcoll.PolyCollection): @@ -4607,7 +4607,7 @@ # Transform the counts if needed if bins=='log': - counts = npy.log(counts+1) + counts = npy.log10(counts+1) elif bins!=None: if not iterable(bins): minimum, maximum = min(counts), max(counts) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |