Skip to content

pygmt.Figure.subplot: "frame", "sharex", and "sharey" do not work correctly with "pygmt.Figure.set_panel" #2365

@yvonnefroehlich

Description

@yvonnefroehlich

Using the pygmt.Figure.subplot method the x and y axis labels set via the sharex and sharey parameters do not always show up.

First mentioned by @weiji14 in #2354 (review):

Been trying to set a subtitle using sharex="b+lNormalize" and sharey="l+lAzimuth" but it doesn't show up. Wondering if the +l is broken, or if there's some setting overriding the label...

Original post by @yvonnefroehlich at #2354 (comment):

There seems to be a difference between using with fig.set_panel(panel=index): and panel=True, which is probably not intended.

(1) with fig.set_panel(panel=index): -> Does NOT add x and y labels
Example code:

import pygmt

nrows = 1
ncols = 2

fig = pygmt.Figure()

with fig.subplot(
    nrows=nrows,
    ncols=ncols,
    figsize=("10c", "5c"),
    sharex="b+llabel_x",
    sharey="l+llabel_y",
):

    for i in range(nrows):
        for j in range(ncols):
            index = i * nrows + j

            # does NOT add x and y labels
            with fig.set_panel(panel=index):
                fig.basemap(region=[0, 10, 0, 10], projection="X?")

fig.show()
# fig.savefig(fname="issue_labels_doubleloop.png")

Output figure:
issue_labels_doubleloop

(2) panel=True -> DOES add x and y labels
Example code:

import pygmt

nrows = 1
ncols = 2

fig = pygmt.Figure()

with fig.subplot(
    nrows=nrows,
    ncols=ncols,
    figsize=("10c", "5c"),
    sharex="b+llabel_x",
    sharey="l+llabel_y",
):

    for i in range(nrows):
        for j in range(ncols):
                        
            # DOES add x and y labels
            fig.basemap(region=[0, 10, 0, 10], projection="X?", panel=True)

fig.show()
# fig.savefig(fname="issue_labels_panelTrue.png")

Output figure:
issue_labels_panelTrue

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions