Permalink
Browse files

Merge pull request #1636 from mdboom/hexbin-log

hexbin log scale is broken in matplotlib 1.2.0
  • Loading branch information...
2 parents 78fa072 + 2f1fda6 commit 084a94f912b0d9123c3756a09a2eaf43e4fbaa1c @dmcdougall dmcdougall committed Jan 4, 2013
View
@@ -5443,7 +5443,7 @@ def errorbar(self, x, y, yerr=None, xerr=None,
lines_kw['transform'] = kwargs['transform']
if 'zorder' in kwargs:
lines_kw['zorder'] = kwargs['zorder']
-
+
# arrays fine here, they are booleans and hence not units
if not iterable(lolims):
lolims = np.asarray([lolims]*len(x), bool)
@@ -6432,32 +6432,39 @@ def hexbin(self, x, y, C = None, gridsize = 100, bins = None,
offsets = offsets[good_idxs,:]
accum = accum[good_idxs]
- if xscale=='log':
- offsets[:,0] = 10**(offsets[:,0])
- xmin = 10**xmin
- xmax = 10**xmax
- self.set_xscale('log')
- if yscale=='log':
- offsets[:,1] = 10**(offsets[:,1])
- ymin = 10**ymin
- ymax = 10**ymax
- self.set_yscale('log')
-
polygon = np.zeros((6, 2), float)
polygon[:,0] = sx * np.array([ 0.5, 0.5, 0.0, -0.5, -0.5, 0.0])
polygon[:,1] = sy * np.array([-0.5, 0.5, 1.0, 0.5, -0.5, -1.0]) / 3.0
if edgecolors=='none':
edgecolors = 'face'
- collection = mcoll.PolyCollection(
- [polygon],
- edgecolors = edgecolors,
- linewidths = linewidths,
- offsets = offsets,
- transOffset = mtransforms.IdentityTransform(),
- offset_position = "data"
- )
+ if xscale == 'log' or yscale == 'log':
+ polygons = np.expand_dims(polygon, 0) + np.expand_dims(offsets, 1)
+ if xscale == 'log':
+ polygons[:, :, 0] = 10.0 ** polygons[:, :, 0]
+ xmin = 10.0 ** xmin
+ xmax = 10.0 ** xmax
+ self.set_xscale(xscale)
+ if yscale == 'log':
+ polygons[:, :, 1] = 10.0 ** polygons[:, :, 1]
+ ymin = 10.0 ** ymin
+ ymax = 10.0 ** ymax
+ self.set_yscale(yscale)
+ collection = mcoll.PolyCollection(
+ polygons,
+ edgecolors=edgecolors,
+ linewidths=linewidths,
+ )
+ else:
+ collection = mcoll.PolyCollection(
+ [polygon],
+ edgecolors=edgecolors,
+ linewidths=linewidths,
+ offsets=offsets,
+ transOffset=mtransforms.IdentityTransform(),
+ offset_position="data"
+ )
if isinstance(norm, mcolors.LogNorm):
if (accum==0).any():
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -419,6 +419,21 @@ def test_hexbin_extent():
ax.hexbin(x, y, extent=[.1, .3, .6, .7])
+@image_comparison(baseline_images=['hexbin_log'],
+ remove_text=True,
+ extensions=['png'])
+def test_hexbin_log():
+ # Issue #1636
+ fig = plt.figure()
+
+ np.random.seed(0)
+ n = 100000
+ x = np.random.standard_normal(n)
+ y = 2.0 + 3.0 * x + 4.0 * np.random.standard_normal(n)
+ y = np.power(2, y * 0.5)
+ ax = fig.add_subplot(111)
+ ax.hexbin(x, y, yscale='log')
+
@cleanup
def test_inverted_limits():
# Test gh:1553

0 comments on commit 084a94f

Please sign in to comment.