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

Improve basic tutorial "Plotting lines" #3747

Open
yvonnefroehlich opened this issue Jan 5, 2025 · 2 comments
Open

Improve basic tutorial "Plotting lines" #3747

yvonnefroehlich opened this issue Jan 5, 2025 · 2 comments
Labels
discussions Need more discussion before taking further actions documentation Improvements or additions to documentation
Milestone

Comments

@yvonnefroehlich
Copy link
Member

yvonnefroehlich commented Jan 5, 2025

I feel the basic tutorial "Plotting lines" can be improved by covering different ways of connecting data points (please see the code examples and images below).

  1. Include the +s modifier of the pen parameter
  2. Include the straight_line parameter
  3. The second part "Change line attributes" is actually quite similar to the Gallery example "Line styles". Both cover adjusting the pen attributes width,color,style. Maybe we can summarise these three plots into one? And decide for using the same term, i.e. either "line attributes" or line styles. I prefer "line attributes" as this matches with pen attributes and “style” is actually one of the attributes.
  4. Following DOC: Add basic tutorial "Plotting polygons" #3593 (comment) by @seisman, using a more complicated line/curve like sine/cosine functions besides lines with two or more data points to make the tutorial more eye-catching.

Combined plot

import pygmt

size = 5
x = [-4, -3.5, -2, 1, 4]
y = [-3, 1, 2, 1, 4]

fig = pygmt.Figure()
fig.basemap(region=[-size, size] * 2, projection=f"X{size * 2}c", frame=1)

fig.plot(x=x, y=y, style="c0.25c", fill="gray30", label="data point")
fig.plot(x=x, y=y, pen="1p,brown", label="linear spline")
fig.plot(x=x, y=y, pen="1p,orange+s", label="Bezier cubic spline")
fig.plot(x=x, y=y, pen="1p,red", straight_line="x", label="stairs via x first")
fig.plot(x=x, y=y, pen="1p,purple", straight_line="y", label="stairs via y first")

fig.legend(position="jRB")
fig.show()

Seperat plots

import pygmt

size = 5
x = [-4, -3.5, -2, 1, 4]
y = [-3, 1, 2, 1, 4]

fig = pygmt.Figure()

args_basemap = {"region": [-size, size, -size, size], "projection": f"X{size * 2}c", "frame": 1}
args_data = {"x": x, "y": y, "style": "c0.25c", "fill": "gray30", "label": "data point"}

fig.basemap(**args_basemap)
fig.plot(**args_data)
fig.plot(x=x, y=y, pen="1p,brown", label="linear spline")
fig.legend(position="jRB")

fig.shift_origin(xshift="w+1c")
fig.basemap(**args_basemap)
fig.plot(**args_data)
fig.plot(x=x, y=y, pen="1p,orange+s", label="Bezier cubic spline")
fig.legend(position="jRB")

fig.shift_origin(xshift="-w-1c", yshift="-h-1c")
fig.basemap(**args_basemap)
fig.plot(**args_data)
fig.plot(x=x, y=y, pen="1p,red", straight_line="x", label="stairs via x first")
fig.legend(position="jRB")

fig.shift_origin(xshift="w+1c")
fig.basemap(**args_basemap)
fig.plot(**args_data)
fig.plot(x=x, y=y, pen="1p,purple", straight_line="y", label="stairs via y first")
fig.legend(position="jRB")

fig.show()
Combined plot Separat plots
fig_lines_combined fig_lines_seperat
@yvonnefroehlich yvonnefroehlich added documentation Improvements or additions to documentation discussions Need more discussion before taking further actions labels Jan 5, 2025
@yvonnefroehlich yvonnefroehlich added this to the 0.15.0 milestone Jan 5, 2025
@yvonnefroehlich
Copy link
Member Author

It's only indirectly related to this issue, but I just realized, that the +s modifier of pen is ignored for the outline of a polygon in case fill is used. Wondering / have to check if this is the expected behaviour.

import numpy as np
import pygmt

x = np.array([-2, 1, 3, 0, -4, -2])
y = np.array([-3, -1, 1, 3, 2, -3])

args_basemap = {"region": [-5, 5, -5, 5], "projection": "X5c", "frame": True}
args_data = {"x": x, "y": y, "style": "c0.2c", "fill": "red"}

fig = pygmt.Figure()
fig.basemap(**args_basemap)
fig.plot(**args_data)
fig.plot(x=x, y=y, pen="1p")

fig.shift_origin(xshift="w+1c")
fig.basemap(**args_basemap)
fig.plot(**args_data)
fig.plot(x=x, y=y, pen="1p+s")

fig.shift_origin(xshift="w+1c")
fig.basemap(**args_basemap)
fig.plot(**args_data)
fig.plot(x=x, y=y, pen="1p+s", fill="gray")  # +s modifier to pen is ignored with fill

fig.show()

fig_polygon_pen_plus_s_ignored_with_fill

@seisman
Copy link
Member

seisman commented Jan 6, 2025

Need to note this is just a "basic" tutorial, and it's better to focus on common situations only. More advanced line plottings can be in an "advanced" tutorial instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussions Need more discussion before taking further actions documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants