GenericMappingTools / pygmt

A Python interface for the Generic Mapping Tools.
https://www.pygmt.org
BSD 3-Clause "New" or "Revised" License
747 stars 216 forks source link

Add examples for plotting lines #493

Closed seisman closed 3 years ago

seisman commented 4 years ago

Description of the desired feature

There are already have nice tutorials for plotting data points of various sizes and colors, but no examples for plotting lines.

It would be good to add some examples showing

Unfortunately, PyGMT currently can't handle multi-segments data as in GMT. To plot multiple lines, we still have to call fig.plot() multiple times.

seisman commented 3 years ago

https://github.com/GenericMappingTools/pygmt/pull/604#issuecomment-709696963

Also, was just looking at the GMT.jl AGU gallery examples at https://www.generic-mapping-tools.org/GMT.jl/latest/gallery/tables/, looks like there's a lot of decorated arrows/curved line examples we can follow.

image

willschlitzer commented 3 years ago

I'll work on this.

willschlitzer commented 3 years ago

I'm trying to figure out how to add a specific CPT, but I'm not getting it to plot on the actual line. I tried setting a specific CPT to cmap, and also tried adding "red,green" to add specific colors, but no luck.

weiji14 commented 3 years ago

Yeah it's complicated, took me a while to figure it out recently too. Try this for inspiration:

import pygmt
import numpy as np

fig = pygmt.Figure()
fig.basemap(frame=["WSne", "af"], region=[20, 30, -10, 10])
pygmt.makecpt(cmap="batlow", series=[0, 10, 1])
x = np.arange(start=20, stop=30, step=0.2)
for zvalue in range(0, 10):
    y = zvalue * np.sin(x)
    fig.plot(x=x, y=y, cmap=True, zvalue=zvalue, pen=f"thick,+z,-")

fig.show()

sine curve with different colors

willschlitzer commented 3 years ago

@weiji14 Impressive find, but that seems like a big step up in complexity from the rest of the tutorial. I've been out of geoscience for 8+ years so I don't keep up with what people want in their plots, but this seems out of place for a basic "How to plot lines" tutorial. My opinion is something like this belongs in a gallery example.

willschlitzer commented 3 years ago

@seisman Are you looking to have anything else added to these line plotting examples before closing the issue? As stated above, I think the custom CPT example provided by @weiji14 may be a bit advanced for a basic tutorial.

seisman commented 3 years ago

@weiji14's example is pretty good and could be added to the gallery (https://www.pygmt.org/dev/gallery/index.html#lines).

willschlitzer commented 3 years ago

@weiji14 Are you planning on adding your code to the gallery? I can submit a pull request for it if you're too busy.

weiji14 commented 3 years ago

I literally came up with that in 5 minutes :sweat_smile:, but yeah, feel free to adapt it into the gallery.

willschlitzer commented 3 years ago

Sounds good! Didn't want to step on your toes; I'll type it up in the next day or so.

willschlitzer commented 3 years ago

@seisman Are we good to close this issue now that #741 and #774 have been merged?

seisman commented 3 years ago

@seisman Are we good to close this issue now that #741 and #774 have been merged?

There are some lines/arrows we may want to add in the gallery. See https://github.com/GenericMappingTools/pygmt/issues/493#issuecomment-709697692

core-man commented 3 years ago

So we still want more line examples?

Which one is on the top priority? @seisman

seisman commented 3 years ago

I'm closing the issue, because I feel that the Figure.plot() method is becoming too complicated and may need some re-design. I prefer NOT to add more complicated (and less used) examples (e.g., decorated text) before we have some more discussions about Figure.plot().