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

Prevent shared-label algorithm from ignoring/overwriting distinct axis labels #384

Open
pulkin opened this issue Aug 29, 2022 · 5 comments

Comments

@pulkin
Copy link

pulkin commented Aug 29, 2022

Description

Cannot create a subplot label.

Steps to reproduce

import proplot as p
fig, ax = p.subplots(
        array=[
            (1, 1, 1),
            (1, 1, 1),
            (1, 1, 1),
            (2, 2, 2),
            (3, 3, 3),
            (4, 4, 4),
            (5, 6, 7),
            (8, 9, 10),
        ],
        refwidth=2.5, refheight=1.25, refnum=1,
        abc="(a)", abcloc='ul', sharex=True, sharey=True, titleloc='uc',
        hspace=[None, None, None, 0, 0, None, None],
        wspace=None)
ax[1:4].format(xlabel="ok xlabel", ylabel="ok ylabel")
ax[4:].format(xlabel="ok xlabel", ylabel="not ok ylabel")
fig.savefig("test_proplot.png")

Expected behavior: not ok ylabel should be visible

Actual behavior: not ok ylabel is absent

Proplot version

0.9.5.post332 3.5.2

@syrte
Copy link

syrte commented Aug 29, 2022

Try set p.subplots(..., sharey=False, ...)?

@pulkin
Copy link
Author

pulkin commented Aug 29, 2022

Try set p.subplots(..., sharey=False, ...)?

Labels re-appear in multitudes (i.e. expected behavior).

@pulkin
Copy link
Author

pulkin commented Sep 3, 2022

The problem is this code:

proplot/proplot/figure.py

Lines 1185 to 1206 in 29bc955

for ax in self._subplot_dict.values():
if isinstance(ax, paxes.CartesianAxes):
ax._apply_axis_sharing() # always!
else:
continue
pos = getattr(ax, x + 'axis').get_label_position()
if ax in seen or pos not in ('bottom', 'left'):
continue # already aligned or cannot align
axs = ax._get_span_axes(pos, panels=False) # returns panel or main axes
if any(getattr(ax, '_share' + x) for ax in axs):
continue # nothing to align or axes have parents
seen.update(axs)
if span or align:
if hasattr(self, '_align_label_groups'):
group = self._align_label_groups[x]
else:
group = getattr(self, '_align_' + x + 'label_grp', None)
if group is not None: # fail silently to avoid fragile API changes
for ax in axs[1:]:
group.join(axs[0], ax) # add to grouper
if span:
self._update_axis_label(pos, axs)

ax._get_span_axes(pos, panels=False) returns every axes adjacent to the left edge: 1, 2, 3, 4, 5, 8 to share the same y axis label. I patched it like this:

...
            axs = ax._get_span_axes(pos, panels=False)  # returns panel or main axes
            if any(getattr(ax, '_share' + x) for ax in axs):
                continue  # nothing to align or axes have parents
            _ref_label_text = getattr(ax, x + 'axis').label.get_text()  # PATCH
            axs = list(_ax for _ax in axs if getattr(_ax, x + 'axis').label.get_text() == _ref_label_text)  # PATCH
            seen.update(axs)
...

And the desired effect is kinda achieved.

pulkin added a commit to pulkin/proplot that referenced this issue Sep 3, 2022
@pulkin
Copy link
Author

pulkin commented Sep 7, 2022

There might be another issue on top of this: super-label coordinates are computed incorrectly in ._get_align_coord. The computation is based on some intermediate alignment of axes which is changed afterwards. If I do this

for i in ax:
    pos = i.get_subplotspec().get_position(fig)
    print(f"{i=} {pos=}")

before and after figure is printed I get different results.

@lukelbd
Copy link
Collaborator

lukelbd commented Mar 29, 2023

Thanks for the report and PR #385 -- will take a closer look when I can. Agree this makes sense -- the shared label algorithm should only consider subplots with identical labels. The sharing algorithm is pretty klunky right now.

@lukelbd lukelbd changed the title Missing label Prevent shared-label algorithm from ignoring/overwriting distinct axis labels Mar 29, 2023
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

3 participants