Skip to content

Commit 4498f71

Browse files
yvonnefroehlichseismanmichaelgrund
authored
DOC/tutorial "Plotting lines": General improvements (#3587)
Co-authored-by: Dongdong Tian <[email protected]> Co-authored-by: Michael Grund <[email protected]>
1 parent 40edcf7 commit 4498f71

File tree

1 file changed

+50
-80
lines changed

1 file changed

+50
-80
lines changed

examples/tutorials/basics/lines.py

+50-80
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Plotting lines
33
==============
44
5-
Plotting lines is handled by :meth:`pygmt.Figure.plot`.
5+
Plotting lines is handled by the :meth:`pygmt.Figure.plot` method.
66
"""
77

88
# %%
@@ -12,123 +12,93 @@
1212
# Plot lines
1313
# ----------
1414
#
15-
# Create a Cartesian figure using ``projection`` parameter and set the axis
16-
# scales using ``region`` (in this case, each axis is 0-10). Pass a list of
17-
# ``x`` and ``y`` values to be plotted as a line.
15+
# Create a Cartesian figure using the :meth:`pygmt.Figure.basemap` method. Pass lists
16+
# containing two values to the ``x`` and ``y`` parameters of the
17+
# :meth:`pygmt.Figure.plot` method. By default, a 0.25-points thick, black, solid
18+
# line is drawn between these two data points.
1819

1920
fig = pygmt.Figure()
20-
fig.plot(
21-
region=[0, 10, 0, 10],
22-
projection="X15c/10c",
23-
frame="a",
24-
x=[1, 8],
25-
y=[5, 9],
26-
pen="1p,black",
27-
)
21+
fig.basemap(region=[0, 10, 0, 10], projection="X15c/10c", frame=True)
22+
23+
fig.plot(x=[1, 5], y=[5, 9])
24+
2825
fig.show()
2926

3027
# %%
31-
# Additional line segments can be added by including additional values for
32-
# ``x`` and ``y``.
28+
# Additional line segments can be added by including more data points in the lists
29+
# passed to ``x`` and ``y``.
3330

3431
fig = pygmt.Figure()
35-
fig.plot(
36-
region=[0, 10, 0, 10],
37-
projection="X15c/10c",
38-
frame="a",
39-
x=[1, 6, 9],
40-
y=[5, 7, 4],
41-
pen="1p,black",
42-
)
32+
fig.basemap(region=[0, 10, 0, 10], projection="X15c/10c", frame=True)
33+
34+
fig.plot(x=[1, 5, 8], y=[5, 9, 4])
35+
4336
fig.show()
4437

4538
# %%
46-
# To plot multiple lines, :meth:`pygmt.Figure.plot` needs to be used for each
47-
# additional line. Parameters such as ``region``, ``projection``, and ``frame``
48-
# do not need to be repeated in subsequent uses.
39+
# To plot multiple lines, :meth:`pygmt.Figure.plot` needs to be used for each line
40+
# separately.
4941

5042
fig = pygmt.Figure()
51-
fig.plot(
52-
region=[0, 10, 0, 10],
53-
projection="X15c/10c",
54-
frame="a",
55-
x=[1, 6, 9],
56-
y=[5, 7, 4],
57-
pen="2p,blue",
58-
)
59-
fig.plot(x=[2, 4, 10], y=[3, 8, 9], pen="2p,red")
43+
fig.basemap(region=[0, 10, 0, 10], projection="X15c/10c", frame=True)
44+
45+
fig.plot(x=[1, 5, 8], y=[5, 9, 4])
46+
fig.plot(x=[2, 4, 9], y=[3, 7, 5])
47+
6048
fig.show()
6149

6250

6351
# %%
6452
# Change line attributes
6553
# ----------------------
6654
#
67-
# The line attributes can be set by the ``pen`` parameter. ``pen`` takes a
68-
# string argument with the optional values *width*,\ *color*,\ *style*.
69-
#
70-
# In the example below, the pen width is set to ``5p``, and with ``black`` as
71-
# the default color and ``solid`` as the default style.
55+
# The line attributes can be set by the ``pen`` parameter which takes a string
56+
# argument with the optional values *width*,\ *color*,\ *style*.
7257

7358
fig = pygmt.Figure()
74-
fig.plot(
75-
region=[0, 10, 0, 10],
76-
projection="X15c/10c",
77-
frame="a",
78-
x=[1, 8],
79-
y=[3, 9],
80-
pen="5p",
81-
)
59+
fig.basemap(region=[0, 10, 0, 10], projection="X15c/10c", frame=True)
60+
61+
# Set the pen width to "5p" (5 points), and use the default color "black" and the
62+
# default style "solid"
63+
fig.plot(x=[1, 8], y=[3, 9], pen="5p")
64+
8265
fig.show()
8366

8467
# %%
8568
# The line color can be set and is added after the line width to the ``pen``
86-
# parameter. In the example below, the line color is set to ``red``.
69+
# parameter.
8770

8871
fig = pygmt.Figure()
89-
fig.plot(
90-
region=[0, 10, 0, 10],
91-
projection="X15c/10c",
92-
frame="a",
93-
x=[1, 8],
94-
y=[3, 9],
95-
pen="5p,red",
96-
)
72+
fig.basemap(region=[0, 10, 0, 10], projection="X15c/10c", frame=True)
73+
74+
# Set the line color to "red", use the default style "solid"
75+
fig.plot(x=[1, 8], y=[3, 9], pen="5p,red")
76+
9777
fig.show()
9878

9979
# %%
10080
# The line style can be set and is added after the line width or color to the
101-
# ``pen`` parameter. In the example below, the line style is set to
102-
# ``..-`` (*dot dot dash*), and the default color ``black`` is used.
81+
# ``pen`` parameter.
10382

10483
fig = pygmt.Figure()
105-
fig.plot(
106-
region=[0, 10, 0, 10],
107-
projection="X15c/10c",
108-
frame="a",
109-
x=[1, 8],
110-
y=[3, 9],
111-
pen="5p,..-",
112-
)
84+
fig.basemap(region=[0, 10, 0, 10], projection="X15c/10c", frame=True)
85+
86+
# Set the line style to "..-" (dot dot dash), use the default color "black"
87+
fig.plot(x=[1, 8], y=[3, 9], pen="5p,..-")
88+
11389
fig.show()
11490

11591
# %%
116-
# The line width, color, and style can all be set in the same ``pen``
117-
# parameter. In the example below, the line width is set to ``7p``, the color
118-
# is set to ``green``, and the line style is ``-.-`` (*dash dot dash*).
119-
#
120-
# For a gallery showing other ``pen`` settings, see
92+
# The line width, color, and style can all be set in the same ``pen`` parameter.
93+
# For a gallery example showing other ``pen`` settings, see
12194
# :doc:`/gallery/lines/linestyles`.
12295

12396
fig = pygmt.Figure()
124-
fig.plot(
125-
region=[0, 10, 0, 10],
126-
projection="X15c/10c",
127-
frame="a",
128-
x=[1, 8],
129-
y=[3, 9],
130-
pen="7p,green,-.-",
131-
)
97+
fig.basemap(region=[0, 10, 0, 10], projection="X15c/10c", frame=True)
98+
99+
# Draw a 7-points thick, green line with style "-.-" (dash dot dash)
100+
fig.plot(x=[1, 8], y=[3, 9], pen="7p,green,-.-")
101+
132102
fig.show()
133103

134-
# sphinx_gallery_thumbnail_number = 3
104+
# sphinx_gallery_thumbnail_number = 6

0 commit comments

Comments
 (0)