Skip to content

Commit

Permalink
Backport PR matplotlib#27441: Fix some minor issues with hexbin bins …
Browse files Browse the repository at this point in the history
…argument
  • Loading branch information
oscargus authored and meeseeksmachine committed Dec 5, 2023
1 parent 4d722f5 commit ab26f68
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion galleries/examples/statistics/hexbin_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
hb = ax1.hexbin(x, y, gridsize=50, bins='log', cmap='inferno')
ax1.set(xlim=xlim, ylim=ylim)
ax1.set_title("With a log color scale")
cb = fig.colorbar(hb, ax=ax1, label='log10(N)')
cb = fig.colorbar(hb, ax=ax1, label='counts')

plt.show()

Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5084,10 +5084,10 @@ def reduce_C_function(C: array) -> float
)

# Set normalizer if bins is 'log'
if bins == 'log':
if cbook._str_equal(bins, 'log'):
if norm is not None:
_api.warn_external("Only one of 'bins' and 'norm' arguments "
f"can be supplied, ignoring bins={bins}")
f"can be supplied, ignoring {bins=}")
else:
norm = mcolors.LogNorm(vmin=vmin, vmax=vmax)
vmin = vmax = None
Expand Down
5 changes: 3 additions & 2 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,17 +956,18 @@ def test_hexbin_extent():
ax.hexbin("x", "y", extent=[.1, .3, .6, .7], data=data)


@image_comparison(['hexbin_empty.png', 'hexbin_empty.png'], remove_text=True)
@image_comparison(['hexbin_empty.png'], remove_text=True)
def test_hexbin_empty():
# From #3886: creating hexbin from empty dataset raises ValueError
fig, ax = plt.subplots()
ax.hexbin([], [])
fig, ax = plt.subplots()
# From #23922: creating hexbin with log scaling from empty
# dataset raises ValueError
ax.hexbin([], [], bins='log')
# From #27103: np.max errors when handed empty data
ax.hexbin([], [], C=[], reduce_C_function=np.max)
# No string-comparison warning from NumPy.
ax.hexbin([], [], bins=np.arange(10))


def test_hexbin_pickable():
Expand Down

0 comments on commit ab26f68

Please sign in to comment.