Skip to content

Adding a legend to right of plot can remove y-axis tick labels #694

@chudlerk

Description

@chudlerk

Got a bit of a weird edge case here for you.

If I run the following code to make a subplots instance with three axes and shared y-axis labels, then hide the last one, everything looks good.

fig,axs=uplt.subplots(ncols=3, sharey='labs')
axs[-1].set_visible(False)
for ax in axs[:-1]:
    ax.plot([0, 1], [0, 1], label='line')
Image

However, if I then add a legend to the second axis, the y-axis ticks for that second axis become hidden:
axs[-2].legend(loc='r')

Image

This doesn't happen if I place the legend inside the axis:

fig,axs=uplt.subplots(ncols=3, sharey='labs')
axs[-1].set_visible(False)
for ax in axs[:-1]:
    ax.plot([0, 1], [0, 1], label='line')
axs[-2].legend(loc='lr')
Image

Kind of a niche edge case, although it becomes relevant when I have say 15 plots to show in a figure, and want to make a 4x4 grid and hide the last one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions