Skip to content

Move towards having get_shared_{x,y}_axes return immutable views. #21584

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 1 commit into from
Jun 2, 2022

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Nov 10, 2021

Directly calling join() on the Groupers is not sufficient to share axes,
anyways, so don't let users do that.

See https://gitter.im/matplotlib/matplotlib?at=618bf31f9d20982e4f10df53.

PR Summary

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

Directly calling join() on the Groupers is not sufficient to share axes,
anyways, so don't let users do that.
@jklymak jklymak merged commit 925b056 into matplotlib:main Jun 2, 2022
@anntzer anntzer deleted the gmf branch June 2, 2022 16:41
tylerjereddy added a commit to tylerjereddy/darshan that referenced this pull request Sep 28, 2022
* when using latest stable matplotlib our testsuite
produces hundreds of warnings like this:

```
tests/test_data_access_by_filesystem.py: 54 warnings
tests/test_summary.py: 99 warnings
  /home/tyler/python_310_darshan_venv/lib/python3.10/site-packages/darshan/experimental/plots/data_access_by_filesystem.py:536:
MatplotlibDeprecationWarning: The join function was deprecated in
Matplotlib 3.6 and will be removed two minor releases later.
    ax_filesystem_counts.get_shared_x_axes().join(ax_filesystem_counts,
list_count_axes[row - 1])
```

* this originates from this upstream PR:
matplotlib/matplotlib#21584

* turn this warning into an error in our CI, to prevent
further introductions of the deprecated functionality,
and fix it up where we already use it, based on the
directions in the PR above
@jklymak
Copy link
Member

jklymak commented Mar 24, 2023

Hmmmm, not sure about this now. What is the equivalent of ax.get_shared_x_axes().remove(ax) to take an axes out of a share group? https://stackoverflow.com/questions/54915124/how-to-unset-sharex-or-sharey-from-two-axes-in-matplotlib

@anntzer
Copy link
Contributor Author

anntzer commented Apr 11, 2023

I don't really want to support unsharing, see e.g. #15287 and especially #9923: the semantics are not trivial.
Admittedly the linked case is well defined (the removed axes is not shared with anyone else and all other shares remain), but if we want to support that we should have a better API that makes clear what happen when, in a state where A shares B and B shares C, we remove B from the group (does A stay shared with C?). (This is discussed at length in #9923.)

PS: Feel free to re-ping me on old issues/prs if needed, I tend to unsubscribe from them once they are closed/merged.

@cvanelteren
Copy link

cvanelteren commented Apr 17, 2025

@anntzer I am running into an issue where I need the ability to unshare axes. I have been messing around with the api for a while to get it to work but can't seem to toggle the ticklabels back on. Is there some hacky way to get the ticklabels to behave independently again?

This is what I was playing around with

code
import ultraplot as uplt
from matplotlib import cbook
import numpy as np
from matplotlib import ticker as mticker
from matplotlib.axis import Ticker 
fig, ax = uplt.subplots(ncols = 2, nrows = 2, wspace = 5, hspace = 5)

# ax[0]._shared_axes["x"] = cbook.Grouper()
print(list(ax[0]._shared_axes.keys()))

data = np.random.rand(2, 100)
for axi in range(0, 4):
    d = data + axi * 100
    ax[axi].scatter(*d)

print(ax[0].xaxis.offsetText)
# print(ax[0].xaxis._ticks.
for idx in range(4):
    axi = ax[idx]
    axi._shared_axes["y"] = cbook.Grouper()
    axi._shared_axes["x"] = cbook.Grouper()
    axi._shared_axes["z"] = cbook.Grouper()
    axi._shared_axes["view"] = cbook.Grouper()

for idx in range(4):
    axi = ax[idx]
    axi.xaxis.reset_ticks()
    axi.yaxis.reset_ticks()
    axi.xaxis.major = Ticker()
    axi.yaxis.major = Ticker()
    axi.yaxis.minor = Ticker()
    axi.xaxis.minor = Ticker()
    axi.xaxis._set_scale(uplt.scale.LinearScale())
    axi.yaxis._set_scale(uplt.scale.LinearScale())

    axi.xaxis.offsetText.set_visible(True)
    axi.yaxis.offsetText.set_visible(True)
    axi.xaxis.offsetText.set_text("hello world")

    major_locs = axi.yaxis.get_majorticklocs()
    major_ticks = axi.yaxis.get_major_ticks()
    major_labels = axi.yaxis.major.formatter.format_ticks(major_locs)
    axi.tick_params(
        left = True,
        # right = True,
        bottom = True,
        # top = True,
        # labelleft = True, 
        # labelright = True,
        # labelbottom = True,
        # labeltop = True, 
        which = "both",
        axis = "both",
    )

    print(axi.yaxis.get_tick_params())
    for tick, loc, label in zip(major_ticks, major_locs, major_labels):
        tick.update_position(loc)
        tick.label1.set_text(label)
        tick.label2.set_text(label)
        


    axi.xaxis.set_major_locator(mticker.AutoLocator())
    axi.xaxis.set_major_formatter(mticker.ScalarFormatter())
    axi.xaxis.set_minor_locator(mticker.AutoMinorLocator())
    axi.xaxis.set_minor_formatter(mticker.NullFormatter())

    axi.yaxis.set_major_locator(mticker.AutoLocator())
    axi.yaxis.set_minor_locator(mticker.AutoMinorLocator())
    axi.xaxis.set_minor_formatter(mticker.NullFormatter())
    axi.yaxis.set_major_formatter(mticker.ScalarFormatter())

    axi.autoscale_view()



# ax[1].scatter(*data)
    # for axj in axi:
        # print(axj.number)/

any help would be appreciated!

@anntzer
Copy link
Contributor Author

anntzer commented Apr 17, 2025

Unsharing is complicated to say the least, see e.g. #9923

@cvanelteren
Copy link

@anntzer I read up on the issue spread across multiple pages on matplotlib. The one you listed is very helpful indeed. In my case I'm not interested in maintaining the transitive properties and merely would like to isolate the axes. I just can't figure out why the axes label behave so strangy.

From the API I can see that we get shallow copy of the minor and major tickets which I believe I reset here. Is there a way to rebuild them that would achieve an axis isolation procedure?

@anntzer
Copy link
Contributor Author

anntzer commented Apr 18, 2025

I don't have a quick reply available, you may have more luck opening a new issue to discuss your problem.

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

Successfully merging this pull request may close these issues.

4 participants