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_model

Plot a recovered 1-D layered model as a depth profile, or a 2-D inversion section as a profile/depth color mesh.

plot_rms

Plot 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.InversionResult

Backend-neutral result object consumed by the plotting helpers.

pycsamt.inversion.export

File export helpers for CSV, NPZ, GeoJSON, VTK, GeoTIFF, and ZIP products.

pycsamt.api.plot.save_fig

Shared figure-saving helper used by this module.

References

Functions

plot_model(result[, ax, log_rho, cmap, ...])

Plot a recovered 1-D or 2-D resistivity model.

plot_rms(result[, ax, title, savepath, ...])

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_model is the quick-look model visualizer for pycsamt.inversion.results.InversionResult. It first converts the result through result.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.ResistivityModel and 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-D pycsamt.interp.ResistivityModel through result.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. If False, 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.SectionStyle object. Names are resolved through pycsamt.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:

matplotlib.axes.Axes

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

pycsamt.inversion.plot.plot_rms(result, ax=None, *, title='Inversion misfit', savepath=None, savefig_kw=None, **kwargs)[source]#

Plot inversion RMS misfit diagnostics.

plot_rms visualizes the weighted root-mean-square misfit stored on an pycsamt.inversion.results.InversionResult. When result.metadata["station_rms"] is available, the function draws one marker per station. Otherwise it draws a single global RMS bar from result.rms.

Parameters:
  • result (InversionResult) – Inversion result containing a global rms value and optionally metadata["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.plot for station RMS curves or Axes.bar for a global RMS bar.

Returns:

Axes containing the RMS plot.

Return type:

matplotlib.axes.Axes

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