Open
Description
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).
- Include the +s modifier of the
pen
parameter - Include the
straight_line
parameter - 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 withpen
attributes and “style” is actually one of the attributes. - 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 |
---|---|
![]() |
![]() |