Skip to content

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

Closed

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

Activity

  1. added
    bug
    on Feb 13, 2023
  2. added this to the 0.9.0 milestone on Feb 13, 2023
  3. yvonnefroehlich commented on Feb 18, 2023

    @yvonnefroehlich
    MemberAuthor

    This issue is also relevant for the frame parameter and affects annotations, ticks and, gridlines.

    (1) with fig.set_panel(panel=index): -> Does NOT add x and y labels, and does NOT adjust frame settings
    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",
        frame="a1f0.5g2",
    ):
    
        for i in range(nrows):
            for j in range(ncols):
                index = i * nrows + j
    
                # does NOT add x and y labels, 
                # does NOT adjust frame settings
                with fig.set_panel(panel=index):
                    fig.basemap(region=[0, 10, 0, 10], projection="X?")
    
    fig.show()
    # fig.savefig(fname="issue_frame_doubleloop.png")

    Output figure:
    issue_frame_doubleloop

    (2) panel=True -> Does add x and y axis labels and does adjust frame settings
    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",
        frame="a1f0.5g2",
    ):
    
        for i in range(nrows):
            for j in range(ncols):
                            
                # does add x and y labels, 
                # does adjust frame settings
                fig.basemap(region=[0, 10, 0, 10], projection="X?", panel=True)
    
    fig.show()
    # fig.savefig(fname="issue_frame_panelTrue.png")

    Output figure:
    issue_frame_panelTrue

  4. changed the title [-]pygmt.Figure.subplot: x and y axis labels set via "sharex" and "sharey" partly not shown[/-] [+]pygmt.Figure.subplot: "frame", "sharex", and "sharey" do not work correctly with "pygmt.Figure.set_panel"[/+] on Feb 18, 2023
  5. yvonnefroehlich commented on Feb 19, 2023

    @yvonnefroehlich
    MemberAuthor

    The problem is related to using pygmt.Figure.basemap directly after pygmt.Figure.set_panel (please see case (1a) vs. case (1b)). For this case, it "works" only if the frame parameter is set again in the same way (please see case (1c)). So, probably the [default] argument passed through the frame parameter of pygmt.Figure.basemap is overwriting the settings via the parameters of pygmt.Figure.subplot.

    (1a) pygmt.Figure.set_panel: + using pygmt.Figure.basemap
    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",
        frame="a1f0.5g2",
    ):
    
        for ip in range(nrows*ncols):
    
            with fig.set_panel(panel=ip):
                
                fig.basemap(region=[0, 10, 0, 10], projection="X?")
    
    fig.show()
    # fig.savefig(fname="issue_frame_panelTrue_basemap.png")

    Output figure
    issue_frame_panelTrue_basemap

    (1b) pygmt.Figure.set_panel: + NOT using pygmt.Figure.basemap
    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",
        frame="a1f0.5g2",
    ):
    
        for ip in range(nrows*ncols):
    
            with fig.set_panel(panel=ip):
                
                fig.plot(
                    region=[0, 10, 0, 10],
                    projection="X?",
                    x=[3,2,5], # some random data
                    y=[6,1,8],
                    style="c0.2c",
                )
    
    fig.show()
    # fig.savefig(fname="issue_frame_doubleloop_plot.png")

    Output figure
    issue_frame_doubleloop_plot

    (1c) pygmt.Figure.set_panel: + using pygmt.Figure.basemap WITH setting the frame parameter again
    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",
        frame="a1f0.5g2",
    ):
    
        for ip in range(nrows*ncols):
    
            with fig.set_panel(panel=ip):
                
                fig.basemap(
                    region=[0, 10, 0, 10],
                    projection="X?",
                    frame="a1f0.5g5", "x+llabel_x", "y+llabel_y",  # >>> CHANGED gridlines, rest the same
                )
    
    fig.show()
    # fig.savefig(fname="issue_frame_panelTrue_basemap_frame.png")

    Output figure
    issue_frame_panelTrue_basemap_frame

  6. seisman commented on Mar 13, 2023

    @seisman
    Member

    I think this is the side-effect of the following two lines:

    if not args_in_kwargs(args=["B", "L", "Td", "Tm", "c"], kwargs=kwargs):
    kwargs["B"] = True # Plotting frames if required arguments not given

    @yvonnefroehlich Could you please try remove these two lines and see if everything works as expected?

  7. yvonnefroehlich commented on Mar 13, 2023

    @yvonnefroehlich
    MemberAuthor

    I think this is the side-effect of the following two lines:

    if not args_in_kwargs(args=["B", "L", "Td", "Tm", "c"], kwargs=kwargs):
    kwargs["B"] = True # Plotting frames if required arguments not given

    @yvonnefroehlich Could you please try remove these two lines and see if everything works as expected?

    Thanks for pointing this out @seisman!
    Please see PR #2417.

  8. seisman commented on Mar 27, 2023

    @seisman
    Member

    Closed by #2417.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions