Skip to content
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

Wrap subplot #412

Closed
wants to merge 3 commits into from
Closed

Wrap subplot #412

wants to merge 3 commits into from

Conversation

weiji14
Copy link
Member

@weiji14 weiji14 commented Apr 11, 2020

Description of proposed changes

Wrapping the subplot function! Preview the tutorial at https://pygmt-git-subplot.gmt.now.sh/tutorials/subplots.html, translated and adapted from https://docs.gmt-china.org/latest/tutorial/subplot/ (in Chinese).

Original GMT subplot function can be found at https://docs.generic-mapping-tools.org/latest/subplot.html. Current implementation has a 'directive' statement to tell subplot whether to 'begin', 'set' or 'end' a subplot, and the position/number of row(s) and column(s) can be set too.

Example code:

import pygmt

fig = pygmt.Figure()
fig.subplot(directive="begin", row=1, col=2, dimensions="f6c/3c")
fig.subplot(directive="set", row=0, col=0)
fig.basemap(region=[0, 3, 0, 3], frame=True)
fig.subplot(directive="set", row=0, col=1)
fig.basemap(region=[0, 3, 0, 3], frame=True)
fig.subplot(directive="end")
fig.show()

Produces:

Basic PyGMT subplot figure

Also cross-referencing Julia wrapper/implementation at https://www.generic-mapping-tools.org/GMT.jl/latest/#GMT.subplot.

Parameters/Aliases to wrap:

  • F = dims/dimensions/size/sizes
  • A = autolabel/fixedlabel
  • B = frame
  • C = clearance
  • J = projection
  • M = margins
  • R = region
  • SC/SR = row_axes | col_axes
  • T= title

Note: this initial implementation is based on a thin wrapper I've been using for a while now (see here), but I think it's time to get it properly into PyGMT! Happy to consider other suggestions though, e.g. Would it be better to create it using a with subplot(...): style functionality?

Fixes #20

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 adding new functionality, add an example to docstrings or tutorials.

@weiji14 weiji14 requested a review from a team April 11, 2020 00:50
@weiji14 weiji14 added this to the 0.2.0 milestone Apr 17, 2020
@vercel vercel bot temporarily deployed to Preview May 12, 2020 00:36 Inactive
@seisman
Copy link
Member

seisman commented May 12, 2020

import pygmt

fig = pygmt.Figure()
fig.subplot(directive="begin", row=1, col=2, dimensions="f6c/3c")
fig.subplot(directive="set", row=0, col=0)
fig.basemap(region=[0, 3, 0, 3], frame=True)
fig.subplot(directive="set", row=0, col=1)
fig.basemap(region=[0, 3, 0, 3], frame=True)
fig.subplot(directive="end")
fig.show()

@weiji14 I'm not sure if this is a good implementation for subplot. The directive argument looks a little weird for matplotlib users. Your implementation may become difficult to read for nested subplots (currently GMT doesn't support nested subplot, but I think it will, see GenericMappingTools/gmt#1280). My first thought is using context manager, but maybe it's more complicated.

@weiji14
Copy link
Member Author

weiji14 commented May 12, 2020

The directive argument looks a little weird for matplotlib users.

Yeah I totally agree with you. I was trying to come up with a way to have a syntax like fig.subplot.begin, fig.subplot.set and fig.subplot.end, but it's tricky implementing it directly in the BasePlotting class. Also looked at matplotlib.subplot, but their codebase is huge...

Your implementation may become difficult to read for nested subplots (currently GMT doesn't support nested subplot, but I think it will, see GenericMappingTools/gmt#1280). My first thought is using context manager, but maybe it's more complicated.

I did think of going the context manager route, similar to what you did in #293. Will need to experiment a bit. Open to any suggestions.

@weiji14 weiji14 added the feature Brand new feature label Jun 21, 2020
@seisman seisman mentioned this pull request Jul 25, 2020
3 tasks
@weiji14 weiji14 mentioned this pull request Sep 6, 2020
11 tasks
@weiji14 weiji14 modified the milestones: 0.2.x, v0.3.x Sep 7, 2020
Wrapping the `subplot` function! Original GMT `subplot` function can be found at https://docs.generic-mapping-tools.org/latest/subplot.html. Current implementation has a 'directive' statement to tell subplot whether to 'begin', 'set' or 'end' a subplot, and the position/number of row(s) and column(s) can be set too. Also created an alias for dimensions (F).
Include test to check that map frame setting is applied to all subplot figures when using 'begin' subplot directive.
@vercel vercel bot temporarily deployed to Preview September 20, 2020 11:44 Inactive
Translated and adapted from https://github.com/gmt-china/GMT_Docs/blob/master/source/tutorial/subplot.rst. Covers basics of using pygmt subplot begin, set and end. Still need to handle gmt "set" using index instead of just row and col.
weiji14 added a commit that referenced this pull request Jan 30, 2021
Wrapping the `subplot` function, in a `with` statement!
Original GMT `subplot` function can be found at
https://docs.generic-mapping-tools.org/6.1/subplot.html.
This is my 3rd attempt at implementing `subplot` in PyGMT,
with commits heavily re-adapted/cherry-picked from
#412 and
#427.
@weiji14 weiji14 mentioned this pull request Jan 30, 2021
21 tasks
weiji14 added a commit that referenced this pull request Jan 30, 2021
Wrapping the `subplot` function, in a `with` statement!
Original GMT `subplot` function can be found at
https://docs.generic-mapping-tools.org/6.1/subplot.html.
This is my 3rd attempt at implementing `subplot` in PyGMT,
with commits heavily re-adapted/cherry-picked from
#412 and
#427.
@weiji14 weiji14 closed this in #822 Feb 14, 2021
weiji14 added a commit that referenced this pull request Feb 14, 2021
Wrapping the `subplot` function, in a `with` statement!
Original GMT `subplot` function can be found at
https://docs.generic-mapping-tools.org/6.1/subplot.html.
This is the 3rd attempt at implementing `subplot` in PyGMT,
with commits heavily re-adapted/cherry-picked from
#412 and
#427.

* Add fig.subplot and fig.set_panel to API docs
* Alias fixedlabel (A), clearance (C), verbose (V) for set_panel
* Turn fig.set_panel into a context manager
* Alias projection (J), region (R), verbose (V), x/yshift (X/Y) for subplot
* Allow for spaces in title and labels without needing double quotes

Mitigates against #247.

* Allow for list inputs into fig.set_panel(panel=...)
* Rename sca to set_panel and ax to panel
* Fix bug that prevented boolean to -A from working
* Add note that subplot panel is activated until further notice
* Validate subplot nrows/ncols and figsize/subsize argument inputs
* Revise advanced subplot layout subsection to use two subplots calls

Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
@seisman seisman deleted the subplot branch March 14, 2021 17:38
sixy6e pushed a commit to sixy6e/pygmt that referenced this pull request Dec 21, 2022
Wrapping the `subplot` function, in a `with` statement!
Original GMT `subplot` function can be found at
https://docs.generic-mapping-tools.org/6.1/subplot.html.
This is the 3rd attempt at implementing `subplot` in PyGMT,
with commits heavily re-adapted/cherry-picked from
GenericMappingTools#412 and
GenericMappingTools#427.

* Add fig.subplot and fig.set_panel to API docs
* Alias fixedlabel (A), clearance (C), verbose (V) for set_panel
* Turn fig.set_panel into a context manager
* Alias projection (J), region (R), verbose (V), x/yshift (X/Y) for subplot
* Allow for spaces in title and labels without needing double quotes

Mitigates against GenericMappingTools#247.

* Allow for list inputs into fig.set_panel(panel=...)
* Rename sca to set_panel and ax to panel
* Fix bug that prevented boolean to -A from working
* Add note that subplot panel is activated until further notice
* Validate subplot nrows/ncols and figsize/subsize argument inputs
* Revise advanced subplot layout subsection to use two subplots calls

Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Brand new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement subplot command
2 participants