|
1 |
| -r""" |
| 1 | +""" |
2 | 2 | Bit and hachure patterns
|
3 | 3 | ========================
|
4 | 4 |
|
5 |
| -PyGMT allows using bit or hachure patterns via the ``fill`` parameter |
6 |
| -or similar parameters: |
| 5 | +In addition to colors, PyGMT also allows using bit and hachure patterns to fill |
| 6 | +symbols, polygons, and other areas, via the ``fill`` parameter or similar parameters. |
| 7 | +
|
| 8 | +Example method parameters that support bit and hachure patterns include: |
7 | 9 |
|
8 |
| -- :meth:`pygmt.Figure.coast`: Land and water masses via ``land`` and |
9 |
| - ``water``, respectively |
| 10 | +- :meth:`pygmt.Figure.coast`: Land and water masses via ``land`` and ``water`` |
10 | 11 | - :meth:`pygmt.Figure.histogram`: Histogram bars via ``fill``
|
11 |
| -- :meth:`pygmt.Figure.meca`: Focal mechanisms via ``compressionfill`` |
12 |
| - and ``extensionfill`` |
| 12 | +- :meth:`pygmt.Figure.meca`: Focal mechanisms via ``compressionfill`` and |
| 13 | + ``extensionfill`` |
13 | 14 | - :meth:`pygmt.Figure.plot`: Symbols and polygons via ``fill``
|
14 | 15 | - :meth:`pygmt.Figure.rose`: Histogram sectors via ``fill``
|
15 | 16 | - :meth:`pygmt.Figure.solar`: Day-light terminators via ``fill``
|
16 | 17 | - :meth:`pygmt.Figure.ternary`: Symbols via ``fill``
|
17 |
| -- :meth:`pygmt.Figure.velo`: Uncertainty wedges and velocity error |
18 |
| - ellipses via ``uncertaintyfill`` |
19 |
| -- :meth:`pygmt.Figure.wiggle`: Anomalies via ``fillpositive`` |
20 |
| - and ``fillnegative`` |
21 |
| -
|
22 |
| -The required argument has the following form: |
| 18 | +- :meth:`pygmt.Figure.velo`: Uncertainty wedges and velocity error ellipses via |
| 19 | + ``uncertaintyfill`` |
| 20 | +- :meth:`pygmt.Figure.wiggle`: Anomalies via ``fillpositive`` and ``fillnegative`` |
23 | 21 |
|
24 |
| -**P**\|\ **p**\ *pattern*\ [**+b**\ *color*][**+f**\ *color*][**+r**\ *dpi*] |
25 |
| -
|
26 |
| -*pattern* can either be a number in the range 1-90 or the name of a |
27 |
| -1-, 8-, or 24-bit image raster file. The former will result in one of the 90 |
28 |
| -predefined 64 x 64 bit-patterns provided by GMT; an overview can by found at |
29 |
| -:gmt-docs:`reference/predefined-patterns.html`. |
30 |
| -The latter allows the user to create customized, repeating images using image |
31 |
| -raster files. |
32 |
| -By specifying upper case **P** instead of **p** the image will be |
33 |
| -bit-reversed, i.e., white and black areas will be interchanged (only applies |
34 |
| -to 1-bit images or predefined bit-image patterns). |
35 |
| -For these patterns and other 1-bit images one may specify alternative |
36 |
| -**b**\ ackground and **f**\ oreground colors (by appending **+b**\ *color* |
37 |
| -and/or **+f**\ *color*) that will replace the default white and black pixels, |
38 |
| -respectively. Excluding *color* from a fore- or background specification yields |
39 |
| -a transparent image where only the back- or foreground pixels will be painted. |
40 |
| -The **+r**\ *dpi* modifier sets the resolution in dpi. |
| 22 | +GMT provides 90 predefined patterns that can be used in PyGMT. The patterns are numbered |
| 23 | +from 1 to 90, and can be colored and inverted. The resolution of the pattern |
| 24 | +can be changed, and the background and foreground colors can be set. For a complete list |
| 25 | +of available patterns and the full syntax to specify a pattern, refer to the |
| 26 | +:doc:`/techref/patterns`. |
41 | 27 | """
|
42 | 28 |
|
43 | 29 | # %%
|
44 | 30 | import pygmt
|
45 | 31 |
|
46 |
| -y = 11 |
47 |
| - |
48 |
| -fig = pygmt.Figure() |
49 |
| -fig.basemap( |
50 |
| - region=[0, 10, 0, 12], |
51 |
| - projection="X10c", |
52 |
| - frame="rlbt+glightgray+tBit and Hachure Patterns", |
53 |
| -) |
54 |
| - |
55 |
| -# To use a pattern as fill append "p" and the number of the desired |
56 |
| -# pattern. By default, the pattern is plotted in black and white |
57 |
| -# with a resolution of 300 dpi |
58 |
| -for pattern in [ |
| 32 | +# A list of patterns that will be demonstrated. |
| 33 | +# To use a pattern as fill append "p" and the number of the desired pattern. |
| 34 | +# By default, the pattern is plotted in black and white with a resolution of 300 dpi. |
| 35 | +patterns = [ |
59 | 36 | # Plot a hachted pattern via pattern number 8
|
60 | 37 | "p8",
|
61 | 38 | # Plot a dotted pattern via pattern number 19
|
62 | 39 | "p19",
|
63 |
| - # Set the background color ("+b") to "red3" |
64 |
| - # and the foreground color ("+f") to "lightgray" |
| 40 | + # Set the background color ("+b") to "red3" and the foreground color ("+f") to |
| 41 | + # "lightgray" |
65 | 42 | "p19+bred3+flightbrown",
|
66 | 43 | # Invert the pattern by using a capitalized "P"
|
67 | 44 | "P19+bred3+flightbrown",
|
|
70 | 47 | # Make the background transparent by not giving a color after "+b";
|
71 | 48 | # works analogous for the foreground
|
72 | 49 | "p19+b+flightbrown+r100",
|
73 |
| -]: |
74 |
| - # Plot a square with the pattern as fill |
75 |
| - fig.plot( |
76 |
| - x=2, |
77 |
| - y=y, |
78 |
| - style="s2c", # square with a width of 2 centimeters |
79 |
| - pen="1p,black", # 1 point thick, black outline |
80 |
| - fill=pattern, |
81 |
| - ) |
82 |
| - # Add a description of the pattern |
83 |
| - fig.text( |
84 |
| - x=4, |
85 |
| - y=y, |
86 |
| - text=pattern, |
87 |
| - font="Courier-Bold", |
88 |
| - justify="ML", # justification of the text is Middle Left |
89 |
| - ) |
90 |
| - y -= 2 |
| 50 | +] |
91 | 51 |
|
| 52 | +fig = pygmt.Figure() |
| 53 | +fig.basemap( |
| 54 | + region=[0, 10, 0, 12], |
| 55 | + projection="X10c", |
| 56 | + frame="rlbt+glightgray+tBit and Hachure Patterns", |
| 57 | +) |
| 58 | + |
| 59 | +y = 11 |
| 60 | +for pattern in patterns: |
| 61 | + # Plot a square with the pattern as fill. |
| 62 | + # The square has a size of 2 centimeters with a 1 point thick, black outline. |
| 63 | + fig.plot(x=2, y=y, style="s2c", pen="1p,black", fill=pattern) |
| 64 | + # Add a description of the pattern. |
| 65 | + fig.text(x=4, y=y, text=pattern, font="Courier-Bold", justify="ML") |
| 66 | + y -= 2 |
92 | 67 | fig.show()
|
0 commit comments