|
2 | 2 | Plotting lines
|
3 | 3 | ==============
|
4 | 4 |
|
5 |
| -Plotting lines is handled by :meth:`pygmt.Figure.plot`. |
| 5 | +Plotting lines is handled by the :meth:`pygmt.Figure.plot` method. |
6 | 6 | """
|
7 | 7 |
|
8 | 8 | # %%
|
|
12 | 12 | # Plot lines
|
13 | 13 | # ----------
|
14 | 14 | #
|
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. |
18 | 19 |
|
19 | 20 | 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 | + |
28 | 25 | fig.show()
|
29 | 26 |
|
30 | 27 | # %%
|
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``. |
33 | 30 |
|
34 | 31 | 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 | + |
43 | 36 | fig.show()
|
44 | 37 |
|
45 | 38 | # %%
|
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. |
49 | 41 |
|
50 | 42 | 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 | + |
60 | 48 | fig.show()
|
61 | 49 |
|
62 | 50 |
|
63 | 51 | # %%
|
64 | 52 | # Change line attributes
|
65 | 53 | # ----------------------
|
66 | 54 | #
|
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*. |
72 | 57 |
|
73 | 58 | 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 | + |
82 | 65 | fig.show()
|
83 | 66 |
|
84 | 67 | # %%
|
85 | 68 | # 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. |
87 | 70 |
|
88 | 71 | 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 | + |
97 | 77 | fig.show()
|
98 | 78 |
|
99 | 79 | # %%
|
100 | 80 | # 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. |
103 | 82 |
|
104 | 83 | 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 | + |
113 | 89 | fig.show()
|
114 | 90 |
|
115 | 91 | # %%
|
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 |
121 | 94 | # :doc:`/gallery/lines/linestyles`.
|
122 | 95 |
|
123 | 96 | 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 | + |
132 | 102 | fig.show()
|
133 | 103 |
|
134 |
| -# sphinx_gallery_thumbnail_number = 3 |
| 104 | +# sphinx_gallery_thumbnail_number = 6 |
0 commit comments