-
Notifications
You must be signed in to change notification settings - Fork 228
Add a tutorial for plotting vectors #1070
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
Changes from 9 commits
Commits
Show all changes
92 commits
Select commit
Hold shift + click to select a range
5941e33
create vectors file from lines, add example
ff9e0f8
Fix code snippet syntax
65e8607
Update index.rst to include vectors.py in Guide
noorbuchi 69b9296
Added circular vector example to vectors.py
nathandloria 5bae9b6
Merge branch 'master' into master
noorbuchi b333429
re-formatted vectors.py using makefile
nathandloria 4593cd3
Changed verbage in vectors.py for ploting circular vectors
nathandloria e54db50
Attempt to fix formatting.
cklima616 adb3b66
Edited vector specification to accomadate code style
nathandloria 39ef01e
Merge branch 'master' into master
cklima616 5d2c272
Duplicate examples. Change format
d3d489a
add four total examples
fb4c82b
change formatting to use # symbol instead of """
9d87fb7
change more formatting
3803d44
Merge branch 'master' into Cartesian
noorbuchi c1dee1d
fromat using black
066dffb
add two new examples. Description needed
d2ab6f9
Fix style issues
87e3da1
Merge branch 'master' into master
noorbuchi c3f9cbb
Add unit descriptions
bba843a
add description to vectors over maps
afc2662
Merge pull request #2 from noorbuchi/Cartesian
noorbuchi a34570f
update method reference to use :meth:
6cf3419
remove whitespace to fix style issue
6015371
remove italics, clarify projection parameter
noorbuchi d7aaad5
change example projection to 10 X 4
bf53a8d
Updated diameter to radius to fix previous mistake
nathandloria 01a87e6
Merge branch 'master' into circular
nathandloria ad213ea
Add some geographic vectors to test
5b73109
try sphinx reference fix
4321fb5
Updated example description
nathandloria a3ec8cd
Erase lines and move around geo vectors
ecbed60
Added multiple vector example
nathandloria 74556ab
Added multiple vector example
nathandloria 94c8968
Added style description to paragraph rather than a comment.
nathandloria 7d626ac
delete first untitled file
noorbuchi d5a320c
Delete Untitled1.ipynb
noorbuchi e9f16fc
Delete Untitled.ipynb
noorbuchi 0a2bc71
Merge branch 'master' into master
noorbuchi 7249ac5
Added new example plotting two vectors using different units
nathandloria f0fa6ad
Add description and vector
16c3a7f
Merge branch 'geographic' of github.com:noorbuchi/pygmt into geographic
4b4a094
Fix descriptions
ca85046
fix typos, remove imports, fix graph
1f451bb
Merge pull request #1 from noorbuchi/circular
nathandloria e3ad0ca
Merge branch 'master' into geographic
noorbuchi 7c4d4ed
Merge pull request #3 from noorbuchi/geographic
noorbuchi 6276e2a
Removed extra # from plot circular vectors heading
nathandloria 43ebc6f
Re-formatted vectors.py with black
nathandloria afd6267
Fixed bug where fig was not reset after #2
nathandloria 031c597
Add gallery thumbnail number, remove TODO
noorbuchi 5e10413
Update examples/tutorials/vectors.py with contributor suggestion
cklima616 1f0b273
fix backtics and add other requested changes
0680c5d
Merge branch 'master' into master
noorbuchi cba9457
add . and other grammar fixes
ac502e4
Merge branch 'master' of github.com:noorbuchi/pygmt
0a78355
add grammar fixes
f9a7a9c
Update examples/tutorials/vectors.py
nathandloria 908b983
Update examples/tutorials/vectors.py
nathandloria cf578fb
Updated formatting of examples/tutorials/vectors.py
nathandloria 1cb8a39
Update examples/tutorials/vectors.py
nathandloria fd2e152
Removed extra line after line 436
nathandloria cbca270
Update examples/tutorials/vectors.py
noorbuchi 2f90190
reduce projection size
e0aaed5
Merge branch 'master' of github.com:noorbuchi/pygmt
b3426b6
Remove backticks from numpy. Add angle description
562e95f
Apply suggestions from code review
noorbuchi 0559e9e
switch style and direction order
5a43914
switch area_thress and shorelines
87db34e
fix first paragraph
e9cf9cd
Fix plot, remove unnecessary numpy
1e9aea0
Revise wording around numpy
79a01bc
Add styling description
31ca200
Update examples/tutorials/vectors.py
cklima616 6dd5a25
Update examples/tutorials/vectors.py
nathandloria cdf4cfc
Update examples/tutorials/vectors.py
nathandloria 1bb8301
Update examples/tutorials/vectors.py
nathandloria f479599
Update examples/tutorials/vectors.py
nathandloria e10a7ee
Made changes to circular examples per @core-man reccomendations
nathandloria 5a61cdf
re-formatted with black
nathandloria c6eadbe
MAde changes to comment section around lines 169
4629862
Fixed wording in paragraphs
196d6d0
Add general fixes and clarifications
c30015a
Add fixes, restructure order
5f97054
Remove doc link and unneeded example
92563cb
Add minor typo and comment fixes
541fed0
Add clarification to example, explain +s
38f68a6
Add minor typo fixes
8f4e2d6
Merge branch 'master' into master
noorbuchi 4116816
Apply suggestions from code review
noorbuchi cce6ad9
Merge branch 'master' into master
noorbuchi 39d61aa
Merge branch 'master' into master
noorbuchi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
""" | ||
Plot vectors | ||
========== | ||
|
||
Plotting vectors is handled by :meth:`pygmt.Figure.plot`. | ||
|
||
.. note:: | ||
|
||
This tutorial assumes the use of a Python notebook, such as IPython or Jupyter Notebook. | ||
To see the figures while using a Python script instead, use | ||
``fig.show(method="external")`` to display the figure in the default PDF viewer. | ||
|
||
To save the figure, use ``fig.savefig("figname.pdf")`` where ``"figname.pdf"`` | ||
is the desired name and file extension for the saved figure. | ||
""" | ||
# TODO: change this number to reflect the correct thumbnail | ||
# sphinx_gallery_thumbnail_number = 3 | ||
|
||
import numpy as np | ||
import pygmt | ||
|
||
####################################################################################### | ||
# Plot vectors | ||
# ---------- | ||
# | ||
# Create a Cartesian figure using ``projection`` parameter and set the axis scales | ||
# using ``region`` (in this case, each axis is 0-25). Pass a ``numpy`` array object | ||
# that contains lists of all vectors to be plotted. | ||
noorbuchi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Vector specifications are structured as: [x_start, y_start, direction_degrees, magnitude] | ||
noorbuchi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
vector_1 = [2, 3, 45, 4] | ||
vector_2 = [7.5, 8.3, -120.5, 7.2] | ||
# Create a list of lists that include each vector information. | ||
data = np.array([vector_1] + [vector_2]) | ||
|
||
fig = pygmt.Figure() | ||
fig.plot( | ||
region=[0, 10, 0, 10], | ||
projection="X10c/10c", | ||
frame="a", | ||
data=data, | ||
style="v0.6c+e", | ||
pen="2p", | ||
color="red3", | ||
) | ||
fig.show() | ||
|
||
######################################################################################## | ||
# Circular vectors can be plotted using an ``x`` and ``y`` value to specify | ||
# where the origin of the circle will be located on the plane. The variable | ||
# ``diam`` is used to specify the diameter of the circle while the ``startDeg`` | ||
# and ``stopDeg`` specify at what angle the arc will begin and end respectively. | ||
|
||
fig = pygmt.Figure() | ||
|
||
reg_x_lowbound = 0 | ||
reg_x_upperbound = 8 | ||
reg_y_lowbound = -15 | ||
reg_y_upperbound = 15 | ||
|
||
noorbuchi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fig.basemap( | ||
region=[reg_x_lowbound, reg_x_upperbound, reg_y_lowbound, reg_y_upperbound], | ||
projection="X15c/10c", | ||
frame=True, | ||
) | ||
|
||
x = 4 | ||
y = 0 | ||
diam = 4 | ||
noorbuchi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
startDeg = 90 | ||
stopDeg = 270 | ||
|
||
data = np.array([[x, y, diam, startDeg, stopDeg]]) | ||
fig.plot(data=data, style="m0.5c+ea", color="red3", pen="1.5p,black") | ||
fig.show() | ||
|
||
######################################################################################## | ||
# Additional line segments can be added by including additional values for ``x`` | ||
# and ``y``. | ||
|
||
fig = pygmt.Figure() | ||
fig.plot( | ||
region=[0, 10, 0, 10], | ||
projection="X25c/20c", | ||
frame="a", | ||
x=[1, 6, 9], | ||
y=[5, 7, 4], | ||
pen="1p,black", | ||
) | ||
fig.show() | ||
|
||
######################################################################################## | ||
# To plot multiple lines, :meth:`pygmt.Figure.plot` needs to be used for each | ||
# additional line. Arguments such as ``region``, ``projection``, and ``frame`` do | ||
# not need to be repeated in subsequent uses. | ||
|
||
fig = pygmt.Figure() | ||
fig.plot( | ||
region=[0, 10, 0, 10], | ||
projection="X25c/20c", | ||
frame="a", | ||
x=[1, 6, 9], | ||
y=[5, 7, 4], | ||
pen="2p,blue", | ||
) | ||
fig.plot(x=[2, 4, 10], y=[3, 8, 9], pen="2p,red") | ||
fig.show() | ||
|
||
######################################################################################## | ||
# Change line attributes | ||
# ---------------------- | ||
# | ||
# The line attributes can be set by the ``pen`` parameter. ``pen`` takes a string | ||
# argument with the optional values *width*,\ *color*,\ *style*. | ||
# | ||
# In the example below, the pen width is set to ``5p``, and with ``black`` as the | ||
# default color and ``solid`` as the default style. | ||
|
||
fig = pygmt.Figure() | ||
fig.plot( | ||
region=[0, 10, 0, 10], | ||
projection="X25c/20c", | ||
frame="a", | ||
x=[1, 8], | ||
y=[3, 9], | ||
pen="5p", | ||
) | ||
fig.show() | ||
|
||
######################################################################################## | ||
# The line color can be set and is added after the line width to the ``pen`` parameter. | ||
# In the example below, the line color is set to ``red``. | ||
|
||
fig = pygmt.Figure() | ||
fig.plot( | ||
region=[0, 10, 0, 10], | ||
projection="X25c/20c", | ||
frame="a", | ||
x=[1, 8], | ||
y=[3, 9], | ||
pen="5p,red", | ||
) | ||
fig.show() | ||
|
||
######################################################################################## | ||
# The line style can be set and is added after the line width or color to the | ||
# ``pen`` parameter. In the example below, the line style is set to | ||
# ``..-`` (*dot dot dash*), and the default color ``black`` is used. | ||
|
||
fig = pygmt.Figure() | ||
fig.plot( | ||
region=[0, 10, 0, 10], | ||
projection="X25c/20c", | ||
frame="a", | ||
x=[1, 8], | ||
y=[3, 9], | ||
pen="5p,..-", | ||
) | ||
fig.show() | ||
|
||
######################################################################################## | ||
# The line width, color, and style can all be set in the same ``pen`` parameter. In the | ||
# example below, the line width is set to ``7p``, the color is set to ``green``, and the | ||
# line style is ``-.-`` (*dash dot dash*). | ||
# | ||
# For a gallery showing other ``pen`` settings, see :doc:`/gallery/lines/linestyles`. | ||
|
||
fig = pygmt.Figure() | ||
fig.plot( | ||
region=[0, 10, 0, 10], | ||
projection="X25c/20c", | ||
frame="a", | ||
x=[1, 8], | ||
y=[3, 9], | ||
pen="7p,green,-.-", | ||
) | ||
fig.show() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.