8000 hexbin log scale is broken in matplotlib 1.2.0 by mdboom · Pull Request #1636 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

hexbin log scale is broken in matplotlib 1.2.0 #1636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 4, 2013
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Closes #1636. When plotting a hexbin on a log scale, the "trick" to r…
…euse the polygons can't work, so revert to the old method where each polygon is independent.
  • Loading branch information
mdboom committed Jan 4, 2013
commit 588f0e20fe629504b17826adfecad2a89efa950f
45 changes: 26 additions & 19 deletions lib/matplotlib/axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP8: Spaces after commas in indices.

xmin = 10.0 ** xmin
xmax = 10.0 ** xmax
self.set_xscale(xscale)
if yscale == 'log':
polygons[:,:,1] = 10.0 ** polygons[:,:,1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here.

ymin = 10.0 ** ymin
ymax = 10.0 ** ymax
self.set_yscale(yscale)
collection = mcoll.PolyCollection(
polygons,
edgecolors = edgecolors,
linewidths = linewidths,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP8: Remove spaces around = for kwargs.

)
else:
collection = mcoll.PolyCollection(
[polygon],
edgecolors = edgecolors,
linewidths = linewidths,
offsets = offsets,
transOffset = mtransforms.IdentityTransform(),
offset_position = "data"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These look like kwargs. Could you remove the spaces surrounding =?

)

if isinstance(norm, mcolors.LogNorm):
if (accum==0).any():
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,20 @@ 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()

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)
plt.hexbin(x,y,yscale='log')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP8: Space after the commas.


@cleanup
def test_inverted_limits():
# Test gh:1553
Expand Down
0