|
2 | 2 | Bit and hachure patterns
|
3 | 3 | ========================
|
4 | 4 |
|
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. |
| 5 | +In addition to colors, PyGMT also allows using bit and hachure patterns to fill symbols, |
| 6 | +polygons, and other areas, via the ``fill`` parameter or similar parameters. |
7 | 7 |
|
8 | 8 | Example method parameters that support bit and hachure patterns include:
|
9 | 9 |
|
|
19 | 19 | ``uncertaintyfill``
|
20 | 20 | - :meth:`pygmt.Figure.wiggle`: Anomalies via ``fillpositive`` and ``fillnegative``
|
21 | 21 |
|
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`. |
| 22 | +GMT provides 90 predefined 1-bit patterns, which are numbered from 1 to 90. In addition, |
| 23 | +custom 1-, 8-, or 24-bit image raster files can also be used as patterns. |
| 24 | +
|
| 25 | +These patterns can be specified via the :class:`pygmt.params.Pattern` class. The |
| 26 | +patterns can be customized with different resolution and different foreground and |
| 27 | +background colors. The foreground and background colors can also be inverted. |
27 | 28 | """
|
28 | 29 |
|
29 | 30 | # %%
|
30 | 31 | import pygmt
|
| 32 | +from pygmt.params import Pattern |
31 | 33 |
|
32 | 34 | # 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 | +# By default, a pattern is plotted in black and white with a resolution of 300 dpi. |
35 | 36 | patterns = [
|
36 |
| - # Plot a hachted pattern via pattern number 8 |
37 |
| - "p8", |
38 |
| - # Plot a dotted pattern via pattern number 19 |
39 |
| - "p19", |
40 |
| - # Set the background color ("+b") to "red3" and the foreground color ("+f") to |
41 |
| - # "lightgray" |
42 |
| - "p19+bred3+flightbrown", |
43 |
| - # Invert the pattern by using a capitalized "P" |
44 |
| - "P19+bred3+flightbrown", |
45 |
| - # Change the resolution ("+r") to 100 dpi |
46 |
| - "p19+bred3+flightbrown+r100", |
47 |
| - # Make the background transparent by not giving a color after "+b"; |
48 |
| - # works analogous for the foreground |
49 |
| - "p19+b+flightbrown+r100", |
| 37 | + # Predefined 1-bit pattern 8. |
| 38 | + Pattern(8), |
| 39 | + # Predefined 1-bit pattern 19. |
| 40 | + Pattern(19), |
| 41 | + # Pattern 19 with custom background ("red3") and foreground ("lightbrown"). |
| 42 | + Pattern(19, bgcolor="red3", fgcolor="lightbrown"), |
| 43 | + # Invert the background and foreground. |
| 44 | + Pattern(19, invert=True, bgcolor="red3", fgcolor="lightbrown"), |
| 45 | + # Same as above, but with a 100 dpi resolution. |
| 46 | + Pattern(19, bgcolor="red3", fgcolor="lightbrown", dpi=100), |
| 47 | + # Same as above, but with a transparent background by setting bgcolor to "". |
| 48 | + Pattern(19, bgcolor="", fgcolor="lightbrown", dpi=100), |
50 | 49 | ]
|
51 | 50 |
|
52 | 51 | fig = pygmt.Figure()
|
53 | 52 | fig.basemap(
|
54 | 53 | region=[0, 10, 0, 12],
|
55 |
| - projection="X10c", |
| 54 | + projection="X18c/10c", |
56 | 55 | frame="rlbt+glightgray+tBit and Hachure Patterns",
|
57 | 56 | )
|
58 |
| - |
59 | 57 | y = 11
|
60 | 58 | for pattern in patterns:
|
61 | 59 | # Plot a square with the pattern as fill.
|
62 | 60 | # 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) |
| 61 | + fig.plot(x=1, y=y, style="s2c", pen="1p,black", fill=pattern) |
64 | 62 | # Add a description of the pattern.
|
65 |
| - fig.text(x=4, y=y, text=pattern, font="Courier-Bold", justify="ML") |
| 63 | + fig.text(x=2, y=y, text=str(repr(pattern)), font="Courier-Bold", justify="ML") |
66 | 64 | y -= 2
|
67 | 65 | fig.show()
|
0 commit comments