2.21.1.10. pycsamt.inversion.plot#
Plotting helpers for pycsamt.inversion results.
This module provides compact quick-look plots for
pycsamt.inversion.results.InversionResult objects. The public
functions are intentionally small and backend-neutral: each plot consumes the
common result API rather than SimPEG, pyGIMLi, Occam2D, ModEM, or built-in
solver internals.
The plotting helpers follow the shared pyCSAMT plotting API. Section-like views
use pycsamt.api.section.PYCSAMT_SECTION, diagnostic line styling uses
pycsamt.api.style.PYCSAMT_STYLE, and optional saving goes through
pycsamt.api.plot.save_fig().
Available plots#
plot_modelPlot a recovered 1-D layered model as a depth profile, or a 2-D inversion section as a profile/depth color mesh.
plot_rmsPlot station RMS values when available, otherwise plot the global weighted RMS value.
Coordinate and value conventions#
Depth is positive downward. Model values are stored as
log10(rho / ohm m) by the interpretation model container, and plotting uses
that log scale by default. Pass log_rho=False to display linear
resistivity in ohm metres.
Examples
Plot a recovered inversion section:
>>> from pycsamt.inversion.plot import plot_model
>>> ax = plot_model(result, section="compact")
>>> ax.get_ylabel()
'Depth (m)'
Plot RMS diagnostics:
>>> from pycsamt.inversion.plot import plot_rms
>>> ax = plot_rms(result)
>>> ax.get_ylabel()
'Weighted RMS'
Save figures using global pyCSAMT plot settings:
>>> from pycsamt.inversion.plot import plot_model
>>> plot_model(result, savepath="figures/inversion_model")
See also
pycsamt.inversion.results.InversionResultBackend-neutral result object consumed by the plotting helpers.
pycsamt.inversion.exportFile export helpers for CSV, NPZ, GeoJSON, VTK, GeoTIFF, and ZIP products.
pycsamt.api.plot.save_figShared figure-saving helper used by this module.
References
Hunter, J. D. (2007). Matplotlib: A 2D graphics environment. Computing in Science & Engineering, 9(3), 90-95.
Tufte, E. R. (2001). The Visual Display of Quantitative Information, 2nd edition. Graphics Press.
Functions
|
Plot a recovered 1-D or 2-D resistivity model. |
|
Plot inversion RMS misfit diagnostics. |
- pycsamt.inversion.plot.plot_model(result, ax=None, *, log_rho=True, cmap='jet_r', colorbar=True, show_stations=True, section='inversion', title=None, savepath=None, savefig_kw=None)[source]
Plot a recovered 1-D or 2-D resistivity model.
plot_modelis the quick-look model visualizer forpycsamt.inversion.results.InversionResult. It first converts the result throughresult.to_resistivity_model()and then chooses the plot type from the recovered grid shape:one model column -> a depth profile using
Axes.step;multiple columns -> a profile/depth section using
Axes.pcolormesh.
The depth axis is positive downward, matching
pycsamt.interp.ResistivityModeland the rest of the interpretation API. Section sizing, station labels, colorbar style, and optional saving use the shared pyCSAMT plotting configuration.- Parameters:
result (InversionResult) – Result produced by
pycsamt.inversion. The result must be convertible to a 2-Dpycsamt.interp.ResistivityModelthroughresult.to_resistivity_model().ax (matplotlib Axes, optional) – Existing axes to draw into. If omitted, a new figure and axes are created using the selected section style.
log_rho (bool, default True) – Plot
log10(rho / ohm m)values. IfFalse, values are converted to linear resistivity in ohm metres before plotting.cmap (str, default "jet_r") – Matplotlib colormap for 2-D sections. Ignored for single-column 1-D depth profiles.
colorbar (bool, default True) – Add a colorbar for 2-D section plots. Ignored for single-column 1-D depth profiles.
show_stations (bool, default True) – Draw station markers and labels using the section station preset when station positions are available.
section (str or SectionStyle, default "inversion") – Shared section style preset name or explicit
pycsamt.api.section.SectionStyleobject. Names are resolved throughpycsamt.api.section.PYCSAMT_SECTION.title (str, optional) – Axes title. If omitted, a backend/method/dimension summary is used.
savepath (str, optional) – If given, save the figure using
pycsamt.api.plot.save_fig(). The path may omit the extension when global pyCSAMT plot formats are configured.savefig_kw (dict, optional) – Extra keyword arguments forwarded to
save_fig.
- Returns:
Axes containing the model plot.
- Return type:
Notes
The function does not call
matplotlib.pyplot.show. This keeps it safe for scripts, notebooks, test suites, and batch figure generation. Use the returned axes to further customize labels, limits, annotations, or overlays.Examples
Plot an inversion result returned by a workflow:
>>> from pycsamt.inversion.plot import plot_model >>> ax = plot_model(result, section="compact", colorbar=False) >>> ax.get_ylabel() 'Depth (m)'
Save a publication copy using the shared pyCSAMT plot settings:
>>> from pycsamt.inversion.plot import plot_model >>> plot_model(result, savepath="figures/inversion_model")
Draw linear resistivity instead of log10 resistivity:
>>> from pycsamt.inversion.plot import plot_model >>> plot_model(result, log_rho=False, cmap="viridis")
References
[plot-model-1]Tufte, E. R. (2001). The Visual Display of Quantitative Information, 2nd edition. Graphics Press.
[plot-model-2]Hunter, J. D. (2007). Matplotlib: A 2D graphics environment. Computing in Science & Engineering, 9(3), 90-95.
[plot-model-3]Chave, A. D. and Jones, A. G. (2012). The Magnetotelluric Method: Theory and Practice. Cambridge University Press.
- pycsamt.inversion.plot.plot_rms(result, ax=None, *, title='Inversion misfit', savepath=None, savefig_kw=None, **kwargs)[source]
Plot inversion RMS misfit diagnostics.
plot_rmsvisualizes the weighted root-mean-square misfit stored on anpycsamt.inversion.results.InversionResult. Whenresult.metadata["station_rms"]is available, the function draws one marker per station. Otherwise it draws a single global RMS bar fromresult.rms.- Parameters:
result (InversionResult) – Inversion result containing a global
rmsvalue and optionallymetadata["station_rms"].ax (matplotlib Axes, optional) – Existing axes to draw into. If omitted, a new compact figure and axes are created.
title (str, default "Inversion misfit") – Axes title.
savepath (str, optional) – If given, save the figure using
pycsamt.api.plot.save_fig().savefig_kw (dict, optional) – Extra keyword arguments forwarded to
save_fig.**kwargs – Additional Matplotlib keyword arguments forwarded to
Axes.plotfor station RMS curves orAxes.barfor a global RMS bar.
- Returns:
Axes containing the RMS plot.
- Return type:
Notes
RMS near 1 is often interpreted as consistency with the supplied data-error model, but the correct target depends on data quality, error floors, regularization strength, and backend conventions. This plot is therefore a diagnostic companion to model plots rather than a standalone quality guarantee.
Examples
Plot the global RMS or station RMS diagnostics:
>>> from pycsamt.inversion.plot import plot_rms >>> ax = plot_rms(result) >>> ax.get_ylabel() 'Weighted RMS'
Customize line/bar appearance and save the plot:
>>> from pycsamt.inversion.plot import plot_rms >>> plot_rms(result, color="black", savepath="figures/rms")
References
[plot-rms-1]Aster, R. C., Borchers, B. and Thurber, C. H. (2018). Parameter Estimation and Inverse Problems, 3rd edition. Elsevier.
[plot-rms-2]Constable, S. C., Parker, R. L. and Constable, C. G. (1987). Occam’s inversion: A practical algorithm for generating smooth models from electromagnetic sounding data. Geophysics, 52(3), 289-300.