Skip to content

Improve basic tutorial "Plotting lines" #3747

Open

Description

@yvonnefroehlich

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

Activity

  1. added
    documentationImprovements or additions to documentation
    discussionsNeed more discussion before taking further actions
    on Jan 5, 2025
  2. added this to the 0.15.0 milestone on Jan 5, 2025
  3. yvonnefroehlich commented on Jan 5, 2025

    @yvonnefroehlich
    MemberAuthor

    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

  4. seisman commented on Jan 6, 2025

    @seisman
    Member

    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.

  5. modified the milestones: 0.15.0, 0.16.0 on Mar 23, 2025
  6. removed
    discussionsNeed more discussion before taking further actions
    on Mar 24, 2025
  7. removed this from the 0.16.0 milestone on Apr 1, 2025
  8. AisunZa commented on Nov 8, 2026

    @AisunZa

    Hi! I'd like to work on improving the "Plotting lines" tutorial.

    I read the discussion about keeping the basic tutorial focused on common situations. My proposal is to add one concise example showing how straight_line="x" and straight_line="y" differ from the default direct connection between points.

    I'd keep the change limited to examples/tutorials/basics/lines.py, without restructuring the rest of the tutorial.

    Would this be an appropriate scope for the basic tutorial, or would you prefer the example in an advanced tutorial?

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions