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 gallery example for plotting Cartesian, circular and geographic vectors #950

Merged
merged 24 commits into from
Mar 2, 2021
Merged

Conversation

kmaterna
Copy link
Contributor

Contributing a gallery plot with vectors on a map. Feel free to make any and all changes. I thought it would be good to have vector example since not everyone knows the new 'plot' options in GMT6.

@kmaterna
Copy link
Contributor Author

/format

@weiji14
Copy link
Member

weiji14 commented Feb 22, 2021

Hi @kmaterna, welcome back! Appreciate your Pull Request, just wanted to note that we added a gallery example for vectors yesterday (#890) at https://www.pygmt.org/dev/gallery/line/vector-heads-tails.html#sphx-glr-gallery-line-vector-heads-tails-py. So sorry if you missed that!

If you want, you can take a look at https://github.com/GenericMappingTools/pygmt/blob/master/examples/gallery/line/vector-heads-tails.py and see if there's anything you would like to add to that example. Or, you can make a full tutorial for plotting vectors instead (see #892). Ping @michaelgrund who might be interested in working together on a full vector plotting tutorial.

@weiji14
Copy link
Member

weiji14 commented Feb 22, 2021

Actually, forget what I said above. Issue #892 also mentions we should add a tutorial for "How to plot Cartesian, circular and geographic vectors/arrows". Should be good to focus on that, I see your example covers plotting geographic arrows over continental US.

@kmaterna
Copy link
Contributor Author

Oh wow, that's wonderful. Funny timing. I missed that. Feel free to close the PR, looks like the tutorial has it all covered.

The only thing that might be nice is the +z option with direction=[dx,dy] for us geodesists who didn't know about all of PYGMT's features. Definitely not urgent. I might play around and try another PR later. Thanks to Michael for the nice demo.

@kmaterna
Copy link
Contributor Author

Yes, or keep. Up to maintainers. +1 for the idea of an example with cartesian vectors.

@weiji14
Copy link
Member

weiji14 commented Feb 22, 2021

@michaelgrund might be able to advice. I'd say keep this open for a while, it's easier to modify an already open Pull Request than to start a new one!

@weiji14 weiji14 added the documentation Improvements or additions to documentation label Feb 22, 2021
@michaelgrund
Copy link
Member

Oh wow, that's wonderful. Funny timing. I missed that. Feel free to close the PR, looks like the tutorial has it all covered.

The only thing that might be nice is the +z option with direction=[dx,dy] for us geodesists who didn't know about all of PYGMT's features. Definitely not urgent. I might play around and try another PR later. Thanks to Michael for the nice demo.

Hey @kmaterna, great that you work on this. Besides the example provided in https://github.com/GenericMappingTools/pygmt/blob/master/examples/gallery/line/vector-heads-tails.py (which only shows different options for heads and tails) in #892 we decided to add another gallery example showing cartesian, circular and geographic vectors. So you covered 1/3 😉 Maybe you can add the two remaining ones in any way? Here's some content I pre-produced for the circular vectors (not comitted so far) you may add:

import pygmt
import numpy as np

fig = pygmt.Figure()
fig.basemap(region=[0, 6, -15, 15], projection="X15c/10c", frame=True)

# plot math angle arcs with different radii
x=3
y=0
startdir=90
stopdir=180
radius=4
pen="1.5p,black",
xtext=24.5

arcstyles = np.repeat("m0.5c+ea", 7)

for arcstyle in arcstyles:
    data = np.array([[x, y, radius, startdir, stopdir]])
    fig.plot(data=data, 
             style=arcstyle, 
             color="red3", 
             pen=pen)
    
    stopdir+=40
    radius-=0.5 

fig.show()

circ_vec

Additonally, a full tutorial on vectors is planned.

@kmaterna
Copy link
Contributor Author

Nice, I like those circular vectors. By cartesian, do you mean regular vectors (i.e., an x-y plot with vectors given by magnitude/angle)? They're no different from geographic vectors except they're not on maps, right? I can work on something that shows all 3.

@seisman
Copy link
Member

seisman commented Feb 22, 2021

By cartesian, do you mean regular vectors (i.e., an x-y plot with vectors given by magnitude/angle)? They're no different from geographic vectors except they're not on maps, right?

I think what you're plotting (using style="v") is Cartesian vectors, although they're plotted on maps.

Geographic vectors (using style="=") should be vectors along great circle paths.

See https://docs.generic-mapping-tools.org/latest/cookbook/features.html#the-drawing-of-vectors for details.

@kmaterna
Copy link
Contributor Author

/format

@kmaterna
Copy link
Contributor Author

I made an example with circular/cartesian/geographic vectors - you guys can decide whether you think it's appropriate for the gallery. Output looks like this.
plot

@seisman
Copy link
Member

seisman commented Feb 23, 2021

Nice example!

@seisman seisman added this to the 0.3.1 milestone Feb 23, 2021
examples/gallery/plot/vectors.py Outdated Show resolved Hide resolved
examples/gallery/plot/vectors.py Outdated Show resolved Hide resolved
examples/gallery/plot/vectors.py Outdated Show resolved Hide resolved
examples/gallery/plot/vectors.py Outdated Show resolved Hide resolved
@michaelgrund michaelgrund self-requested a review February 23, 2021 07:31
Copy link
Member

@michaelgrund michaelgrund left a comment

Choose a reason for hiding this comment

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

Made some minor suggestions, all in all the example looks good to me.

examples/gallery/plot/vectors.py Outdated Show resolved Hide resolved
examples/gallery/plot/vectors.py Outdated Show resolved Hide resolved
examples/gallery/plot/vectors.py Outdated Show resolved Hide resolved
@kmaterna
Copy link
Contributor Author

/format

examples/gallery/line/vectors.py Outdated Show resolved Hide resolved
examples/gallery/line/vectors.py Outdated Show resolved Hide resolved
@seisman seisman marked this pull request as ready for review February 26, 2021 20:28
@seisman
Copy link
Member

seisman commented Feb 26, 2021

The example looks pretty good and is close to merging.

@GenericMappingTools/python @GenericMappingTools/python-maintainers Do you have any further comments?

Copy link
Member

@weiji14 weiji14 left a comment

Choose a reason for hiding this comment

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

This is coming along really nicely. Just a few recommendations on documenting what the various modifiers in the style string represent (e.g. +e, etc).

examples/gallery/line/vectors.py Outdated Show resolved Hide resolved
examples/gallery/line/vectors.py Outdated Show resolved Hide resolved
examples/gallery/line/vectors.py Outdated Show resolved Hide resolved
examples/gallery/line/vectors.py Outdated Show resolved Hide resolved
examples/gallery/line/vectors.py Outdated Show resolved Hide resolved
@kmaterna
Copy link
Contributor Author

kmaterna commented Mar 1, 2021

/format

examples/gallery/line/vectors.py Outdated Show resolved Hide resolved
examples/gallery/line/vectors.py Outdated Show resolved Hide resolved
@weiji14 weiji14 merged commit 339805e into GenericMappingTools:master Mar 2, 2021
@weiji14
Copy link
Member

weiji14 commented Mar 2, 2021

Thanks @kmaterna for this amazing example (and to @michaelgrund and @seisman for the helpful review suggestions)!

Feel free to suggest any new ideas if you have any, and do consider adding your name to AUTHORS.md when you have time 😄

@weiji14 weiji14 mentioned this pull request Mar 14, 2021
9 tasks
sixy6e pushed a commit to sixy6e/pygmt that referenced this pull request Dec 21, 2022
… vectors (GenericMappingTools#950)

Gallery figure showing how to plot Cartesian/Circular/Geographic
vector lines. Example is situated over the continental US,
showing how lines of different styles ranging from straight
Cartesian lines to Circular arcs and Curved geographic ones
(e.g. lines connecting different cities) can be plotted.

Co-authored-by: Michael Grund <[email protected]>
Co-authored-by: Dongdong Tian <[email protected]>
Co-authored-by: Wei Ji <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants