Plotting API Documentation
This module contains functions to aid in plotting the data.
Author: Travis Alongi (talongi@usgs.gov)
cb_friendly_sequential_cool_colormap(n_segments)
Generates a color-blind friendly sequential color map For plotting using matploblib
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_segments
|
int
|
Number of subdivisions of colormap. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
array |
Array of RGB colors with shape (n_segments, 4). |
Note
Created using https://colorbrewwer2.org
Source code in plotting.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
get_xy_coords_raster(geotiff_file)
Extracts x, y coordinates grids from a GeoTIFF file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geotiff_file (str)
|
Path to GeoTIFF file. |
required |
Returns: tuple: Two 2D numpy arays representing x and y coordinates.
Source code in plotting.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
plot_base_map(plotter, base_map_file, opacity=0.2)
Plots a base map using a GeoTIFF file in PyVista.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plotter
|
Plotter
|
PyVista plotter instance. |
required |
base_map_file
|
str
|
Path to the base map GeoTIFF file. |
required |
Example
import pyvista as pv
plotter=pv.Plotter()
plot_base_map(plotter, 'base_map.tiff')
Source code in plotting.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
plot_earthquakes(plotter, eq_catalog, point_size=3, min_depth=-15000, color='pink')
Plots earthquake locations as spheres in PyVista.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plotter
|
Plotter
|
PyVista plotter instance. |
required |
eq_catalog
|
str
|
Path to the earthquake catalog CSV file. |
required |
point_size
|
int
|
Size of plotted earthquake points. Default is 3. |
3
|
min_depth
|
float
|
Minimum depth filter (meters). Default is -15000. |
-15000
|
color
|
str
|
Color of plotted earthquakes. Default is "pink". |
'pink'
|
Example
import pandas as pd
import numpy as np
catalog = pd.read_csv('catalog.csv')
data = np.array([catalog.x, catalog.y, catalog.depth_m]).T
plot_earthquakes(plotter, data, point_size=5, min_depth=-25000)
Source code in plotting.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
plot_fault_surfaces(plotter, ax, files, colors=None)
Plots 3D fault surfaces and their 2D projections.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plotter
|
Plotter
|
PyVista plotter instance. |
required |
ax
|
Axes
|
Matplotlib axis for 2D projection. |
required |
files
|
list
|
List of file paths to fault surface data (CSV format). |
required |
Source code in plotting.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
plot_topo(plotter, geotiff_files, vert_exag=2, downsample=5, opacity=0.9, monochromatic=False, min_elev=-10000, max_elev=15000, clims=[-10000, 10000])
Plots topography from multiple GeoTIFF tiles in a PyVista plotter.
Merges elevation data from GeoTIFF files, converts coordinates to UTM, and renders a 3D topographic surface with optional vertical exaggeration and coloring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plotter
|
Plotter
|
PyVista plotter instance for rendering. |
required |
geotiff_files
|
list of str
|
Paths to GeoTIFF tiles containing elevation data. |
required |
vert_exag
|
float
|
Vertical exaggeration factor (default: 2). |
2
|
downsample
|
int
|
Factor to reduce resolution for performance (default: 5). |
5
|
opacity
|
float
|
Surface opacity (0 to 1, default: 0.90). |
0.9
|
monochromatic
|
bool
|
If True, plots in grayscale; otherwise, uses a terrain colormap (default: False). |
False
|
min_elev
|
float
|
Minimum elevation threshold (default: -10,000). |
-10000
|
max_elev
|
float
|
Maximum elevation threshold (default: 15,000). |
15000
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
(utm_x, utm_y, elevation, grid) - utm_x (numpy.ndarray): UTM x-coordinates of the mesh. - utm_y (numpy.ndarray): UTM y-coordinates of the mesh. - elevation (numpy.ndarray): Processed elevation data. - grid (pv.StructuredGrid): PyVista grid object of the topography. |
Note
- Assumes GeoTIFFs are in EPSG:4326 (WGS84 latitude/longitude).
- Automatically determines the appropriate UTM zone.
- Uses
pyprojfor coordinate transformation andrasteriofor reading GeoTIFFs.
Example
import pyvista as pv
plotter = pv.Plotter()
geotiff_files = ["tile1.tif", "tile2.tif"]
plot_topo(plotter, geotiff_files, vert_exag=2, monochromatic=False)
plotter.show()
Source code in plotting.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
plot_topo_with_texture(plotter, dem_files, texture_file, vert_exag=3, downsample=5, opacity=0.9, no_data_color=(128, 128, 128), min_elev=-10000, max_elev=20000)
Plots topography with an overlaid GeoTIFF texture.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plotter
|
Plotter
|
PyVista plotter instance. |
required |
dem_files
|
list of str
|
List of DEM GeoTIFF file paths. |
required |
texture_file
|
str
|
Path to the GeoTIFF texture file. |
required |
vert_exag
|
float
|
Vertical exaggeration factor. Default is 1.5. |
3
|
downsample
|
int
|
Factor to downsample the topography. Default is 3. |
5
|
opacity
|
float
|
Opacity of the plotted mesh. Default is 0.9. |
0.9
|
no_data_color
|
tuple
|
RGB color for no-data areas. Default is (128, 128, 128). |
(128, 128, 128)
|
min_elev
|
float
|
Minimum elevation cutoff. Default is -10000. |
-10000
|
max_elev
|
float
|
Maximum elevation cutoff. Default is 20000. |
20000
|
Returns:
| Type | Description |
|---|---|
|
pv.Texture: -PyVista texture object. |
Example
plotter = pv.Plotter()
dem_files = ['dem_tile1.tif', 'dem_tile2.tif']
texture_file = 'texture.tif'
plot_topo_with_texture(plotter, dem_files, texture_file)
Source code in plotting.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | |