From ef03bdc10023a264cf3b29cb73d358212f3aecff Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Tue, 5 Nov 2024 20:46:21 +0100 Subject: [PATCH 1/4] Improve tutorial for plotting lines --- examples/tutorials/basics/lines.py | 129 +++++++++++------------------ 1 file changed, 49 insertions(+), 80 deletions(-) diff --git a/examples/tutorials/basics/lines.py b/examples/tutorials/basics/lines.py index 9445ca94e13..b42d4bcc7c7 100644 --- a/examples/tutorials/basics/lines.py +++ b/examples/tutorials/basics/lines.py @@ -2,7 +2,7 @@ Plotting lines ============== -Plotting lines is handled by :meth:`pygmt.Figure.plot`. +Plotting lines is handled by the method :meth:`pygmt.Figure.plot`. """ # %% @@ -12,51 +12,38 @@ # Plot lines # ---------- # -# Create a Cartesian figure using ``projection`` parameter and set the axis -# scales using ``region`` (in this case, each axis is 0-10). Pass a list of -# ``x`` and ``y`` values to be plotted as a line. +# Create a Cartesian figure using the :meth:`pygmt.Figure.basemap` method. Pass lists +# of two values to the ``x`` and ``y`` parameters. By default, a 0.25-points thick, +# black, solid line is drawn between these two data points. fig = pygmt.Figure() -fig.plot( - region=[0, 10, 0, 10], - projection="X15c/10c", - frame="a", - x=[1, 8], - y=[5, 9], - pen="1p,black", -) +fig.basemap(region=[0, 10, 0, 10], projection="X15c/10c", frame=True) + +fig.plot(x=[1, 5], y=[5, 9]) + fig.show() # %% -# Additional line segments can be added by including additional values for -# ``x`` and ``y``. +# Additional line segments can be added by including more data points in the lists +# passed to ``x`` and ``y``. fig = pygmt.Figure() -fig.plot( - region=[0, 10, 0, 10], - projection="X15c/10c", - frame="a", - x=[1, 6, 9], - y=[5, 7, 4], - pen="1p,black", -) +fig.basemap(region=[0, 10, 0, 10], projection="X15c/10c", frame=True) + +fig.plot(x=[1, 5, 8], y=[5, 9, 4]) + fig.show() # %% -# To plot multiple lines, :meth:`pygmt.Figure.plot` needs to be used for each -# additional line. Parameters such as ``region``, ``projection``, and ``frame`` -# do not need to be repeated in subsequent uses. +# To plot multiple lines, :meth:`pygmt.Figure.plot` needs to be used for each line +# separately. fig = pygmt.Figure() -fig.plot( - region=[0, 10, 0, 10], - projection="X15c/10c", - frame="a", - x=[1, 6, 9], - y=[5, 7, 4], - pen="2p,blue", -) -fig.plot(x=[2, 4, 10], y=[3, 8, 9], pen="2p,red") +fig.basemap(region=[0, 10, 0, 10], projection="X15c/10c", frame=True) + +fig.plot(x=[1, 5, 8], y=[5, 9, 4]) +fig.plot(x=[2, 4, 9], y=[3, 7, 5]) + fig.show() @@ -64,71 +51,53 @@ # Change line attributes # ---------------------- # -# The line attributes can be set by the ``pen`` parameter. ``pen`` takes a -# string argument with the optional values *width*,\ *color*,\ *style*. -# -# In the example below, the pen width is set to ``5p``, and with ``black`` as -# the default color and ``solid`` as the default style. +# The line attributes can be set by the ``pen`` parameter. ``pen`` takes a string +# argument with the optional values *width*,\ *color*,\ *style*. fig = pygmt.Figure() -fig.plot( - region=[0, 10, 0, 10], - projection="X15c/10c", - frame="a", - x=[1, 8], - y=[3, 9], - pen="5p", -) +fig.basemap(region=[0, 10, 0, 10], projection="X15c/10c", frame=True) + +# Set the pen width to "5p" (5 points), and use the default color "black" and the +# default style "solid" +fig.plot(x=[1, 8], y=[3, 9], pen="5p") + fig.show() # %% # The line color can be set and is added after the line width to the ``pen`` -# parameter. In the example below, the line color is set to ``red``. +# parameter. fig = pygmt.Figure() -fig.plot( - region=[0, 10, 0, 10], - projection="X15c/10c", - frame="a", - x=[1, 8], - y=[3, 9], - pen="5p,red", -) +fig.basemap(region=[0, 10, 0, 10], projection="X15c/10c", frame=True) + +# Set the line color to "red", use the default style "solid" +fig.plot(x=[1, 8], y=[3, 9], pen="5p,red") + fig.show() # %% # The line style can be set and is added after the line width or color to the -# ``pen`` parameter. In the example below, the line style is set to -# ``..-`` (*dot dot dash*), and the default color ``black`` is used. +# ``pen`` parameter. fig = pygmt.Figure() -fig.plot( - region=[0, 10, 0, 10], - projection="X15c/10c", - frame="a", - x=[1, 8], - y=[3, 9], - pen="5p,..-", -) +fig.basemap(region=[0, 10, 0, 10], projection="X15c/10c", frame=True) + +# Set the line style to "..-" (dot dot dash), use the default color "black" +fig.plot(x=[1, 8], y=[3, 9], pen="5p,..-") + fig.show() # %% -# The line width, color, and style can all be set in the same ``pen`` -# parameter. In the example below, the line width is set to ``7p``, the color -# is set to ``green``, and the line style is ``-.-`` (*dash dot dash*). -# -# For a gallery showing other ``pen`` settings, see +# The line width, color, and style can all be set in the same ``pen`` parameter. +# For a gallery example showing other ``pen`` settings, see # :doc:`/gallery/lines/linestyles`. fig = pygmt.Figure() -fig.plot( - region=[0, 10, 0, 10], - projection="X15c/10c", - frame="a", - x=[1, 8], - y=[3, 9], - pen="7p,green,-.-", -) +fig.basemap(region=[0, 10, 0, 10], projection="X15c/10c", frame=True) + +# Draw a 7-points thick, green line with style "-.-" (dash dot dash) +fig.plot(x=[1, 8], y=[3, 9], pen="7p,green,-.-") + fig.show() -# sphinx_gallery_thumbnail_number = 3 +# sphinx_gallery_thumbnail_number = 6 From e0bab7242a92dc963737c70f7cee30648798c91f Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Tue, 5 Nov 2024 21:02:34 +0100 Subject: [PATCH 2/4] Improve documentation --- examples/tutorials/basics/lines.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/tutorials/basics/lines.py b/examples/tutorials/basics/lines.py index b42d4bcc7c7..c7dca88faea 100644 --- a/examples/tutorials/basics/lines.py +++ b/examples/tutorials/basics/lines.py @@ -13,8 +13,9 @@ # ---------- # # Create a Cartesian figure using the :meth:`pygmt.Figure.basemap` method. Pass lists -# of two values to the ``x`` and ``y`` parameters. By default, a 0.25-points thick, -# black, solid line is drawn between these two data points. +# containing two values to the ``x`` and ``y`` parameters of the +# :meth:`pygmt.Figure.plot` method. By default, a 0.25-points thick, black, solid +# line is drawn between these two data points. fig = pygmt.Figure() fig.basemap(region=[0, 10, 0, 10], projection="X15c/10c", frame=True) From e4a38d2a161ffe84ecf189b4d7bef6b0875774a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= <94163266+yvonnefroehlich@users.noreply.github.com> Date: Wed, 6 Nov 2024 08:44:03 +0100 Subject: [PATCH 3/4] Move word 'method' Co-authored-by: Dongdong Tian --- examples/tutorials/basics/lines.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tutorials/basics/lines.py b/examples/tutorials/basics/lines.py index c7dca88faea..f3567b33ced 100644 --- a/examples/tutorials/basics/lines.py +++ b/examples/tutorials/basics/lines.py @@ -2,7 +2,7 @@ Plotting lines ============== -Plotting lines is handled by the method :meth:`pygmt.Figure.plot`. +Plotting lines is handled by the :meth:`pygmt.Figure.plot` method. """ # %% From a846d7bb08dce4bc05dcfa4fe5129ddb894293e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= <94163266+yvonnefroehlich@users.noreply.github.com> Date: Wed, 6 Nov 2024 08:44:46 +0100 Subject: [PATCH 4/4] Combine to one sentence Co-authored-by: Michael Grund <23025878+michaelgrund@users.noreply.github.com> --- examples/tutorials/basics/lines.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tutorials/basics/lines.py b/examples/tutorials/basics/lines.py index f3567b33ced..c0cbabbdd75 100644 --- a/examples/tutorials/basics/lines.py +++ b/examples/tutorials/basics/lines.py @@ -52,7 +52,7 @@ # Change line attributes # ---------------------- # -# The line attributes can be set by the ``pen`` parameter. ``pen`` takes a string +# The line attributes can be set by the ``pen`` parameter which takes a string # argument with the optional values *width*,\ *color*,\ *style*. fig = pygmt.Figure()