Skip to content

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

Open

Description

@pulkin

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

Activity

  1. syrte commented on Aug 29, 2022

    @syrte

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

  2. pulkin commented on Aug 29, 2022

    @pulkin
    Author

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

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

  3. pulkin commented on Sep 3, 2022

    @pulkin
    Author

    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.

  4. added a commit that references this issue on Sep 3, 2022
    acb1cec
  5. pulkin commented on Sep 7, 2022

    @pulkin
    Author

    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.

  6. lukelbd commented on Mar 29, 2023

    @lukelbd
    Collaborator

    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.

  7. changed the title [-]Missing label[/-] [+]Prevent shared-label algorithm from ignoring/overwriting distinct axis labels[/+] on Mar 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions