Skip to content

Fix setting "sharex", "sharey", and "frame" of Figure.subplot in combination with Figure.basemap #2417

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

Merged
merged 25 commits into from
Mar 27, 2023

Conversation

yvonnefroehlich
Copy link
Member

@yvonnefroehlich yvonnefroehlich commented Mar 13, 2023

Description of proposed changes

For context please see issue #2365

This PR aims to test the suggestion in comment #2365 (comment).

First PR #2418 has to be merged.

Fixes #2365

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If wrapping a new module, open a 'Wrap new GMT module' issue and submit reasonably-sized PRs.
  • If adding new functionality, add an example to docstrings or tutorials.
  • Use underscores (not hyphens) in names of Python files and directories.

Slash Commands

You can write slash commands (/command) in the first line of a comment to perform
specific operations. Supported slash commands are:

  • /format: automatically format and lint the code
  • /test-gmt-dev: run full tests on the latest GMT development version

@yvonnefroehlich
Copy link
Member Author

/format

@yvonnefroehlich
Copy link
Member Author

Based on this rough test I feel setting the x_share, y_share, and frame parameters via pygmt.Figure.subplot work now as expected.

Code example

import pygmt

nrows = 1
ncols = 2

fig = pygmt.Figure()

with fig.subplot(
    nrows=nrows,
    ncols=ncols,
    figsize=("10c", "5c"),
    sharex="b+llabel_x",  # at the bottom
    sharey="l+llabel_y",  # on the left side
    # annotations in steps of 5
    # ticks in steps of 0.5
    # gridlines in steps of 1
    frame="a5f0.5g1",
):

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

            with fig.set_panel(panel=index):
                fig.basemap(region=[0, 10, 0, 10], projection="X?")

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

Output figure:
issue_labels_doubleloop_NEW

@seisman
Copy link
Member

seisman commented Mar 14, 2023

We automatically added -B option when required parameters are not given in c274463 (#1909). Obviously, it has some side effects. I think you can simply revert the changes in c274463 by running:

git revert c27446391ac6097e9610dbb41e750c4ba60f8e82

@github-actions
Copy link
Contributor

github-actions bot commented Mar 14, 2023

Summary of changed images

This is an auto-generated report of images that have changed on the DVC remote

Status Path
added pygmt/tests/baseline/test_basemap_subplot.png
deleted pygmt/tests/baseline/test_basemap_required_args.png

Image diff(s)

Added images

  • pygmt/tests/baseline/test_basemap_subplot.png

Modified images

Path Old New

Report last updated at commit e1ffbdb

@yvonnefroehlich
Copy link
Member Author

We automatically added -B option when required parameters are not given in c274463 (#1909). Obviously, it has some side effects. I think you can simply revert the changes in c274463 by running:

git revert c27446391ac6097e9610dbb41e750c4ba60f8e82

Commit c274463 is reverted in commit 3aa1374.

@maxrjones maxrjones mentioned this pull request Mar 14, 2023
36 tasks
@seisman seisman changed the title POC: Fix setting "x_share" "y_share", and "frame" of pygmt.Figure.subplot in combination with "pygmt.Figure.basemap" Fix setting "sharex", "sharey", and "frame" of Figure.subplot in combination with Figure.basemap Mar 15, 2023
Comment on lines 93 to 96
if not args_in_kwargs(args=["B", "L", "Td", "Tm", "c"], kwargs=kwargs):
kwargs["B"] = True # Plotting frames if required arguments not given
raise GMTInvalidInput(
"At least one of 'frame', 'map_scale', 'compass', 'rose', or 'panel' must be specified."
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, in subplot mode, none of these options are required. For example, the first example in #2365 no longer works after this PR.

Ideally, we should check if it's in subplot mode, and these options are required only when it's NOT in subplot mode. However, currently we can't know it. So I believe we have to remove the checks, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 8e9d4e5.

@yvonnefroehlich yvonnefroehlich self-assigned this Mar 18, 2023
@yvonnefroehlich
Copy link
Member Author

/format

@seisman seisman mentioned this pull request Mar 19, 2023
7 tasks
@seisman seisman added the final review call This PR requires final review and approval from a second reviewer label Mar 27, 2023
@seisman seisman merged commit 8eac8d0 into main Mar 27, 2023
@seisman seisman deleted the fix-subplot-frame branch March 27, 2023 13:29
@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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