8000 [Bug]: Hexbin hbar and vbar not updating correctly on changed · Issue #28633 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

[Bug]: Hexbin hbar and vbar not updating correctly on changed #28633

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

Open
trygvrad opened this issue Aug 1, 2024 · 0 comments
Open

[Bug]: Hexbin hbar and vbar not updating correctly on changed #28633

trygvrad opened this issue Aug 1, 2024 · 0 comments

Comments

@trygvrad
Copy link
Contributor
trygvrad commented Aug 1, 2024

Bug summary

A hexbar with marginals=True has independent norms on the hexbins and the hbar and vbar unless vmin/vmax is set manually.
However, if the a changed signal is called, the behavior changes, and vmin/vmax is updated on the hbar and vbar to be equal to the vmin/vmax on main.

Aditionally, there is a bug so that the

Code for reproduction

# based on test_axes.py -- test_hexbin_linear()
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(19680801)
n = 100000
x = np.random.standard_normal(n)
y = 2.0 + 3.0 * x + 4.0 * np.random.standard_normal(n)

fig, axes = plt.subplots(2, 1, figsize=(9, 9))
cs = axes[0].hexbin(x, y, gridsize=(10, 5), marginals=True,
          reduce_C_function=np.sum)

fig.colorbar(cs.hbar).set_label('hbar')
fig.colorbar(cs.vbar).set_label('vbar')
fig.colorbar(cs).set_label('main')


cs = axes[1].hexbin(x, y, gridsize=(10, 5), marginals=True,
          reduce_C_function=np.sum)
cs.set_cmap('rainbow')

fig.colorbar(cs.hbar).set_label('hbar')
fig.colorbar(cs.vbar).set_label('vbar')
fig.colorbar(cs).set_label('main')

Actual outcome

image
Only two of three colorbars change, and the limits are changed on the vbar.

Expected outcome

All three colorbars in the lower plot should change, but the limits should not update

Additional information

This bug came up as I was looking at this code in relation to the new data→color pipeline suggested in #28428.
I can find no report on this bug by actual users, so I don't think it needs a quick resolution.

  • If the new data→color pipeline discussed in VectorMappable with data type objects #28428 is approved, this bug will be resolved as part of this.
  • If the new data→color pipeline is not approved, a small bugfix for this issue could be made (good first issue?)

The relevant code is in _axes.py, in the function hexbin() which includes

        def on_changed(collection):
            collection.hbar.set_cmap(collection.get_cmap())
            collection.hbar.set_cmap(collection.get_cmap())
            collection.vbar.set_clim(collection.get_clim())
            collection.vbar.set_clim(collection.get_clim())
        collection.callbacks.connect('changed', on_changed)

where hbar and vbar is used in the wrong order.
However, only updating this will not resolve the issue where changing the colorbar changes the limits on the hbar and vbar in the case where these limits have not been set.

Operating system

No response

Matplotlib Version

3.8.2, matplotlib-dev

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

git checkout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants
0