Skip to content
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

Fix some minor issues with hexbin bins argument #27441

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -5103,10 +5103,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 @@ -962,17 +962,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