|
| 1 | +r""" |
| 2 | +Bit and Hachure Patterns |
| 3 | +------------------------ |
| 4 | +
|
| 5 | +PyGMT allows using bit or hachure patterns via the ``fill`` parameter |
| 6 | +or similar parameters: |
| 7 | +
|
| 8 | +- :meth:`pygmt.Figure.coast`: Land and water masses via ``land`` and |
| 9 | + ``water``, respectively |
| 10 | +- :meth:`pygmt.Figure.histogram`: Histogram bars via ``fill`` |
| 11 | +- :meth:`pygmt.Figure.meca`: Focal mechanisms via ``compressionfill`` |
| 12 | + and ``extensionfill`` |
| 13 | +- :meth:`pygmt.Figure.plot`: Symbols and polygons via ``fill`` |
| 14 | +- :meth:`pygmt.Figure.rose`: Histogram sectors via ``fill`` |
| 15 | +- :meth:`pygmt.Figure.solar`: Day-light terminators via ``fill`` |
| 16 | +- :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: |
| 23 | +
|
| 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 | +https://docs.generic-mapping-tools.org/latest/cookbook/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. |
| 41 | +""" |
| 42 | + |
| 43 | +import pygmt |
| 44 | + |
| 45 | +y = 11 |
| 46 | + |
| 47 | +fig = pygmt.Figure() |
| 48 | +fig.basemap( |
| 49 | + region=[0, 10, 0, 12], |
| 50 | + projection="X10c", |
| 51 | + frame="rlbt+glightgray+tBit and Hachure Patterns", |
| 52 | +) |
| 53 | + |
| 54 | +# To use a pattern as fill append "p" and the number of the desired |
| 55 | +# pattern. By default, the pattern is plotted in black and white |
| 56 | +# with a resolution of 300 dpi |
| 57 | +for pattern in [ |
| 58 | + # Plot a hachted pattern via pattern number 8 |
| 59 | + "p8", |
| 60 | + # Plot a dotted pattern via pattern number 19 |
| 61 | + "p19", |
| 62 | + # Set the background color ("+b") to "red3" |
| 63 | + # and the foreground color ("+f") to "lightgray" |
| 64 | + "p19+bred3+flightbrown", |
| 65 | + # Invert the pattern by using a capitalized "P" |
| 66 | + "P19+bred3+flightbrown", |
| 67 | + # Change the resolution ("+r") to 100 dpi |
| 68 | + "p19+bred3+flightbrown+r100", |
| 69 | + # Make the background transparent by not giving a color after "+b"; |
| 70 | + # works analogous for the foreground |
| 71 | + "p19+b+flightbrown+r100", |
| 72 | +]: |
| 73 | + # Plot a square with the pattern as fill |
| 74 | + fig.plot( |
| 75 | + x=2, |
| 76 | + y=y, |
| 77 | + style="s2c", # square with a width of 2 centimeters |
| 78 | + pen="1p,black", # 1 point thick, black outline |
| 79 | + fill=pattern, |
| 80 | + ) |
| 81 | + # Add a description of the pattern |
| 82 | + fig.text( |
| 83 | + x=4, |
| 84 | + y=y, |
| 85 | + text=pattern, |
| 86 | + font="Courier-Bold", |
| 87 | + justify="ML", # justification of the text is Middle Left |
| 88 | + ) |
| 89 | + y -= 2 |
| 90 | + |
| 91 | +fig.show() |
0 commit comments