Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 588f0e2

Browse filesBrowse files
committed
Closes #1636. When plotting a hexbin on a log scale, the "trick" to reuse the polygons can't work, so revert to the old method where each polygon is independent.
1 parent 894742b commit 588f0e2
Copy full SHA for 588f0e2

File tree

Expand file treeCollapse file tree

3 files changed

+40
-19
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+40
-19
lines changed

‎lib/matplotlib/axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes.py
+26-19Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6432,32 +6432,39 @@ def hexbin(self, x, y, C = None, gridsize = 100, bins = None,
64326432
offsets = offsets[good_idxs,:]
64336433
accum = accum[good_idxs]
64346434

6435-
if xscale=='log':
6436-
offsets[:,0] = 10**(offsets[:,0])
6437-
xmin = 10**xmin
6438-
xmax = 10**xmax
6439-
self.set_xscale('log')
6440-
if yscale=='log':
6441-
offsets[:,1] = 10**(offsets[:,1])
6442-
ymin = 10**ymin
6443-
ymax = 10**ymax
6444-
self.set_yscale('log')
6445-
64466435
polygon = np.zeros((6, 2), float)
64476436
polygon[:,0] = sx * np.array([ 0.5, 0.5, 0.0, -0.5, -0.5, 0.0])
64486437
polygon[:,1] = sy * np.array([-0.5, 0.5, 1.0, 0.5, -0.5, -1.0]) / 3.0
64496438

64506439
if edgecolors=='none':
64516440
edgecolors = 'face'
64526441

6453-
collection = mcoll.PolyCollection(
6454-
[polygon],
6455-
edgecolors = edgecolors,
6456-
linewidths = linewidths,
6457-
offsets = offsets,
6458-
transOffset = mtransforms.IdentityTransform(),
6459-
offset_position = "data"
6460-
)
6442+
if xscale == 'log' or yscale == 'log':
6443+
polygons = np.expand_dims(polygon, 0) + np.expand_dims(offsets, 1)
6444+
if xscale == 'log':
6445+
polygons[:,:,0] = 10.0 ** polygons[:,:,0]
6446+
xmin = 10.0 ** xmin
6447+
xmax = 10.0 ** xmax
6448+
self.set_xscale(xscale)
6449+
if yscale == 'log':
6450+
polygons[:,:,1] = 10.0 ** polygons[:,:,1]
6451+
ymin = 10.0 ** ymin
6452+
ymax = 10.0 ** ymax
6453+
self.set_yscale(yscale)
6454+
collection = mcoll.PolyCollection(
6455+
polygons,
6456+
edgecolors = edgecolors,
6457+
linewidths = linewidths,
6458+
)
6459+
else:
6460+
collection = mcoll.PolyCollection(
6461+
[polygon],
6462+
edgecolors = edgecolors,
6463+
linewidths = linewidths,
6464+
offsets = offsets,
6465+
transOffset = mtransforms.IdentityTransform(),
6466+
offset_position = "data"
6467+
)
64616468

64626469
if isinstance(norm, mcolors.LogNorm):
64636470
if (accum==0).any():
Loading

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,20 @@ def test_hexbin_extent():
419419

420420
ax.hexbin(x, y, extent=[.1, .3, .6, .7])
421421

422+
@image_comparison(baseline_images=['hexbin_log'],
423+
remove_text=True,
424+
extensions=['png'])
425+
def test_hexbin_log():
426+
# Issue #1636
427+
fig = plt.figure()
428+
429+
n = 100000
430+
x = np.random.standard_normal(n)
431+
y = 2.0 + 3.0 * x + 4.0 * np.random.standard_normal(n)
432+
y = np.power(2, y * 0.5)
433+
ax = fig.add_subplot(111)
434+
plt.hexbin(x,y,yscale='log')
435+
422436
@cleanup
423437
def test_inverted_limits():
424438
# Test gh:1553

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.