GenericMappingTools / GenericMappingTools/pygmt

Improve basic tutorial "Plotting lines"

Open
#3,747 2 comments 0 reactions 0 assignees View on GitHub
documentation
Dominant language
Python
Stars
874
Forks
255
Avg merge
1d 21h
Merged PRs (30d)
40

Description

I feel the basic tutorial ["Plotting lines"](https://www.pygmt.org/dev/tutorials/basics/lines.html) 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"](https://www.pygmt.org/dev/tutorials/basics/lines.html#change-line-attributes) is actually quite similar to the [Gallery example "Line styles"](https://www.pygmt.org/dev/gallery/lines/linestyles.html). 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 https://github.com/GenericMappingTools/pygmt/pull/3593#issuecomment-2475457511 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**
```python
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**
```python
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](https://github.com/user-attachments/assets/1559f713-5fe4-49d9-86b8-dd27ab74e33e) | ![fig_lines_seperat](https://github.com/user-attachments/assets/6f152b06-82cd-4638-8805-59506bdd59ec) |

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.