|
| 1 | +""" |
| 2 | +Plot lines |
| 3 | +========== |
| 4 | +
|
| 5 | +Plotting lines is handled by :meth:`pygmt.Figure.plot`. |
| 6 | +""" |
| 7 | + |
| 8 | +import pygmt |
| 9 | + |
| 10 | +######################################################################################## |
| 11 | +# Plot lines |
| 12 | +# ---------- |
| 13 | +# |
| 14 | +# Create a Cartesian figure using ``projection`` parameter and set the axis scales |
| 15 | +# using ``region`` (in this case, each axis is 0-10). Pass a list of ``x`` and ``y`` |
| 16 | +# values to be plotted as a line. |
| 17 | + |
| 18 | +fig = pygmt.Figure() |
| 19 | +fig.plot( |
| 20 | + region=[0, 10, 0, 10], |
| 21 | + projection="X25c/20c", |
| 22 | + frame="a", |
| 23 | + x=[1, 8], |
| 24 | + y=[5, 9], |
| 25 | + pen="1p,black", |
| 26 | +) |
| 27 | +fig.show() |
| 28 | + |
| 29 | +######################################################################################## |
| 30 | +# Additional line segments can be added by including additional values for ``x`` |
| 31 | +# and ``y``. |
| 32 | + |
| 33 | +fig = pygmt.Figure() |
| 34 | +fig.plot( |
| 35 | + region=[0, 10, 0, 10], |
| 36 | + projection="X25c/20c", |
| 37 | + frame="a", |
| 38 | + x=[1, 6, 9], |
| 39 | + y=[5, 7, 4], |
| 40 | + pen="1p,black", |
| 41 | +) |
| 42 | +fig.show() |
| 43 | + |
| 44 | +######################################################################################## |
| 45 | +# To plot multiple lines, :meth:`pygmt.Figure.plot` needs to be used for each |
| 46 | +# additional line. Parameters such as ``region``, ``projection``, and ``frame`` do |
| 47 | +# not need to be repeated in subsequent uses. |
| 48 | + |
| 49 | +fig = pygmt.Figure() |
| 50 | +fig.plot( |
| 51 | + region=[0, 10, 0, 10], |
| 52 | + projection="X25c/20c", |
| 53 | + frame="a", |
| 54 | + x=[1, 6, 9], |
| 55 | + y=[5, 7, 4], |
| 56 | + pen="2p,blue", |
| 57 | +) |
| 58 | +fig.plot(x=[2, 4, 10], y=[3, 8, 9], pen="2p,red") |
| 59 | +fig.show() |
| 60 | + |
| 61 | +######################################################################################## |
| 62 | +# Change line attributes |
| 63 | +# ---------------------- |
| 64 | +# |
| 65 | +# The line attributes can be set using the ``pen`` parameter. ``pen`` takes a string |
| 66 | +# argument with the optional values *width*,\ *color*,\ *style*. |
| 67 | +# |
| 68 | +# In the example below, the pen width is set to ``"5p"``, and with *black* as the |
| 69 | +# default color and *solid* as the default style. |
| 70 | + |
| 71 | +fig = pygmt.Figure() |
| 72 | +fig.plot( |
| 73 | + region=[0, 10, 0, 10], |
| 74 | + projection="X25c/20c", |
| 75 | + frame="a", |
| 76 | + x=[1, 8], |
| 77 | + y=[3, 9], |
| 78 | + pen="5p", |
| 79 | +) |
| 80 | +fig.show() |
| 81 | + |
| 82 | +######################################################################################## |
| 83 | +# The line color can be set and is added after the line width to the ``pen`` argument. |
| 84 | +# In the example below, the line color is set to "red". |
| 85 | + |
| 86 | +fig = pygmt.Figure() |
| 87 | +fig.plot( |
| 88 | + region=[0, 10, 0, 10], |
| 89 | + projection="X25c/20c", |
| 90 | + frame="a", |
| 91 | + x=[1, 8], |
| 92 | + y=[3, 9], |
| 93 | + pen="5p,red", |
| 94 | +) |
| 95 | +fig.show() |
| 96 | + |
| 97 | +######################################################################################## |
| 98 | +# The line style can be set and is added after the line width or color to the |
| 99 | +# ``pen`` argument. In the example below, the line color is set to *dot dot dash*, and |
| 100 | +# the default color *black* is used. |
| 101 | + |
| 102 | +fig = pygmt.Figure() |
| 103 | +fig.plot( |
| 104 | + region=[0, 10, 0, 10], |
| 105 | + projection="X25c/20c", |
| 106 | + frame="a", |
| 107 | + x=[1, 8], |
| 108 | + y=[3, 9], |
| 109 | + pen="5p,..-", |
| 110 | +) |
| 111 | +fig.show() |
| 112 | + |
| 113 | +######################################################################################## |
| 114 | +# The line width, color, and style can all be set in the same ``pen`` argument. In the |
| 115 | +# example below, the line width is set to *7p*, the color is set to *green*, and the |
| 116 | +# line style is *dash dot dash*. |
| 117 | +# |
| 118 | +# For a gallery showing other ``pen`` settings, see :doc:`/gallery/line/linestyles`. |
| 119 | + |
| 120 | +fig = pygmt.Figure() |
| 121 | +fig.plot( |
| 122 | + region=[0, 10, 0, 10], |
| 123 | + projection="X25c/20c", |
| 124 | + frame="a", |
| 125 | + x=[1, 8], |
| 126 | + y=[3, 9], |
| 127 | + pen="7p,green,-.-", |
| 128 | +) |
| 129 | +fig.show() |
0 commit comments