From 10f7cc695d1dcab8e5c94e70b832df7d1890ab89 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 16 Oct 2020 04:12:33 -0400 Subject: [PATCH 1/4] Improve the gallery example for line styles --- examples/gallery/line/linestyles.py | 38 +++++++++++++++++++---------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/examples/gallery/line/linestyles.py b/examples/gallery/line/linestyles.py index d0a1f1daa52..028dda7e02b 100644 --- a/examples/gallery/line/linestyles.py +++ b/examples/gallery/line/linestyles.py @@ -20,23 +20,35 @@ import numpy as np import pygmt -# Generate a sample line for plotting -x = np.linspace(0, 10, 500) -y = np.sin(x) +# Generate a two-point line for plotting +x = np.array([0, 7]) +y = np.array([9, 9]) fig = pygmt.Figure() -fig.basemap(region=[0, 10, -3, 3], projection="X15c/8c", frame=["xaf", "yaf", "WSrt"]) +fig.basemap(region=[0, 10, 0, 10], projection="X15c/8c", frame='+t"Line Styles"') # Plot the line using the default line style fig.plot(x=x, y=y) - -# Plot the lines using different line styles -fig.plot(x=x, y=y + 1.5, pen="1p,red,-") -fig.plot(x=x, y=y + 1.0, pen="2p,blue,.") -fig.plot(x=x, y=y + 0.5, pen="1p,red,-.") - -fig.plot(x=x, y=y - 0.5, pen="2p,blue,..-") -fig.plot(x=x, y=y - 1.0, pen="3p,tomato,--.") -fig.plot(x=x, y=y - 1.5, pen="3p,tomato,4_2:2p") +fig.text(x=x[-1], y=y[-1], text="solid (default)", justify="ML", offset="0.2c/0c") + +# plot the line using different line styles +for linestyle in [ + "1p,red,-", # dashed line + "1p,blue,.", # dotted line + "1p,lightblue,-.", # dash-dotted line + "2p,blue,..-", # dot-dot-dashed line + "2p,tomato,--.", # dash-dash-dotted line + "2p,tomato,4_2:2p", # A pattern of 4-point-long line segment and 2-point-gap between segment +]: + y -= 1 # Move the current line down + fig.plot(x=x, y=y, pen=linestyle) + fig.text(x=x[-1], y=y[-1], text=linestyle, justify="ML", offset="0.2c/0c") + +# plot the line just like a railway track (black/white) +y -= 1 +for linestyle in ["5p,black", "4p,white,20p_20p"]: + fig.plot(x=x, y=y, pen=linestyle) +fig.text(x=x[-1], y=y[-1], text="5p,black", justify="ML", offset="0.2c/0.2c") +fig.text(x=x[-1], y=y[-1], text="4p,white,20p_20p", justify="ML", offset="0.2c/-0.2c") fig.show() From 5c828a8022f627302f8a4b97f32924a20d62aa3c Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Thu, 22 Oct 2020 21:56:05 -0400 Subject: [PATCH 2/4] Improve the comment --- examples/gallery/line/linestyles.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/gallery/line/linestyles.py b/examples/gallery/line/linestyles.py index 028dda7e02b..86e62238d88 100644 --- a/examples/gallery/line/linestyles.py +++ b/examples/gallery/line/linestyles.py @@ -44,7 +44,8 @@ fig.plot(x=x, y=y, pen=linestyle) fig.text(x=x[-1], y=y[-1], text=linestyle, justify="ML", offset="0.2c/0c") -# plot the line just like a railway track (black/white) +# plot the line like a railway track (black/white) +# the trick here is plotting the same line twice but with different line styles y -= 1 for linestyle in ["5p,black", "4p,white,20p_20p"]: fig.plot(x=x, y=y, pen=linestyle) From 1550022422fde9ae4b5cf237142cc66df97249c6 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Thu, 22 Oct 2020 22:34:42 -0400 Subject: [PATCH 3/4] Update examples/gallery/line/linestyles.py Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- examples/gallery/line/linestyles.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/gallery/line/linestyles.py b/examples/gallery/line/linestyles.py index 86e62238d88..195171d04ff 100644 --- a/examples/gallery/line/linestyles.py +++ b/examples/gallery/line/linestyles.py @@ -47,8 +47,8 @@ # plot the line like a railway track (black/white) # the trick here is plotting the same line twice but with different line styles y -= 1 -for linestyle in ["5p,black", "4p,white,20p_20p"]: - fig.plot(x=x, y=y, pen=linestyle) +fig.plot(x=x, y=y, pen="5p,black") +fig.plot(x=x, y=y, pen="4p,white,20p_20p") fig.text(x=x[-1], y=y[-1], text="5p,black", justify="ML", offset="0.2c/0.2c") fig.text(x=x[-1], y=y[-1], text="4p,white,20p_20p", justify="ML", offset="0.2c/-0.2c") From 99fb1db638388ffc733b7fc5fb5a497ef7fb21c5 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Sat, 24 Oct 2020 07:53:27 -0400 Subject: [PATCH 4/4] Fix a typo and add more comment --- examples/gallery/line/linestyles.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/gallery/line/linestyles.py b/examples/gallery/line/linestyles.py index 195171d04ff..3b4a3d348cf 100644 --- a/examples/gallery/line/linestyles.py +++ b/examples/gallery/line/linestyles.py @@ -31,7 +31,7 @@ fig.plot(x=x, y=y) fig.text(x=x[-1], y=y[-1], text="solid (default)", justify="ML", offset="0.2c/0c") -# plot the line using different line styles +# Plot the line using different line styles for linestyle in [ "1p,red,-", # dashed line "1p,blue,.", # dotted line @@ -44,9 +44,9 @@ fig.plot(x=x, y=y, pen=linestyle) fig.text(x=x[-1], y=y[-1], text=linestyle, justify="ML", offset="0.2c/0c") -# plot the line like a railway track (black/white) -# the trick here is plotting the same line twice but with different line styles -y -= 1 +# Plot the line like a railway track (black/white). +# The trick here is plotting the same line twice but with different line styles +y -= 1 # move the current line down fig.plot(x=x, y=y, pen="5p,black") fig.plot(x=x, y=y, pen="4p,white,20p_20p") fig.text(x=x[-1], y=y[-1], text="5p,black", justify="ML", offset="0.2c/0.2c")