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

Add a new method to shift plot origins #289

Merged
merged 6 commits into from
Mar 12, 2019
Merged

Add a new method to shift plot origins #289

merged 6 commits into from
Mar 12, 2019

Conversation

seisman
Copy link
Member

@seisman seisman commented Feb 28, 2019

Description of proposed changes

Add Figure.shift_origin() to shift plot origins.

Fixes #267.

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.

@seisman
Copy link
Member Author

seisman commented Mar 1, 2019

@leouieda Can you help review it?

pygmt/figure.py Outdated
@@ -284,6 +284,27 @@ def show(self, dpi=300, width=500, method="static"):
img = Image(data=png, width=width)
return img

def shift_origin(self, xshift=None, yshift=None): # pylint: disable=no-self-use
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def shift_origin(self, xshift=None, yshift=None): # pylint: disable=no-self-use
def shift_origin(self, xshift=None, yshift=None):

@seisman you still need to call self._preprocess() to make sure we're plotting to the right figure. This is not a great design, granted. But the only other I can think of for calling the figure module automatically is through a metaclass, which I'm not eager to do.

pygmt/figure.py Outdated
@@ -284,6 +284,27 @@ def show(self, dpi=300, width=500, method="static"):
img = Image(data=png, width=width)
return img

def shift_origin(self, xshift=None, yshift=None): # pylint: disable=no-self-use
"""
Shift origins in x and/or y directions.
Copy link
Member

Choose a reason for hiding this comment

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

Some more information here would be great.

Copy link
Member

@leouieda leouieda left a comment

Choose a reason for hiding this comment

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

Thanks @seisman! Could you also add a gallery plot that uses this method? Maybe plotting an inset or something. It would be great to use it in this tutorial instead of X: https://github.com/GenericMappingTools/pygmt/blob/master/examples/tutorials/coastlines.py#L63

to the fixed lower left corner of the page, or prepend **r** [Default] to
move the origin relative to its current location.

Detailed usage at https://gmt.soest.hawaii.edu/doc/latest/GMT_Docs.html#plot-positioning-and-layout-the-x-y-options
Copy link
Member Author

Choose a reason for hiding this comment

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

What's the best way to reference the official GMT documentation?

Copy link
Member

Choose a reason for hiding this comment

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

I still don't know of a good way to do this yet. I'm open to suggestions. It would be best to have this as a variable somewhere and input into the docstring somehow.

Copy link
Member Author

Choose a reason for hiding this comment

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

@leouieda Can we rename the gmt_module_docs decorator to something like gmt_docs, which supports following conversions:

{gmt_docs basemap} => https://gmt.soest.hawaii.edu/doc/latest/basemap.html
{gmt_docs gmt xy-full} => https://gmt.soest.hawaii.edu/doc/latest/gmt.html#xy-full

Copy link
Member

Choose a reason for hiding this comment

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

I would actually like to get rid of most of those decorators in favor of something simpler to maintain. But I don't think there is a good way to format the docstring without using a decorator. We could certainly add that functionality. But we should be using the https://www.generic-mapping-tools.org/gmt/latest/ domain now.

Copy link
Member Author

@seisman seisman Mar 12, 2019

Choose a reason for hiding this comment

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

How about putting the raw links in the docstrings, without using a decorator or any substitutions? If someday the GMT documentation site changes, it's still easy to update all the links.

@seisman
Copy link
Member Author

seisman commented Mar 11, 2019

Could you also add a gallery plot that uses this method? Maybe plotting an inset or something.

I have no idea what to add in the gallery. We should use the inset module for inset plots and subplot for multi-panel plots (both are not implemented yet). I think Figure.shift_origin() should only be used for multi-panel plots with some irregular layout.

@seisman seisman requested a review from leouieda March 11, 2019 02:26
@leouieda
Copy link
Member

@seisman you're right about the inset. The usage in the tutorial is good as that is the intended use of the method. Thanks!

@leouieda leouieda merged commit 98b17ba into master Mar 12, 2019
@leouieda leouieda deleted the shift_origin branch March 12, 2019 04:28
@weiji14 weiji14 mentioned this pull request Feb 6, 2021
21 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a new method to Figure to shift the plot
2 participants