Plot Types

SpectroChemPy provides several plotting methods. ds.plot() chooses automatically, but explicit methods give you control.

Line Plot

For spectra and time-series:

[1]:
import spectrochempy as scp

ds = scp.read("irdata/nh4y-activation.spg")
ds = ds[:, 4000.0:650.0]  # We keep only the region that we want to display
ds.y -= ds.y[0]  # Set y coordinates as relative time  for better visualization
ds.y.ito("hour")
ds.y.title = "Time on stream"  # Update y-axis title accordingly
ds[:, 1290.0:920.0] = scp.MASKED  # We also mask a region that we do not want to display
ds1 = ds[0]  # Single spectrum
[2]:
_ = ds1.plot()
../../_images/userguide_plotting_plot_types_3_0.png

Or using plot_lines() explicitly (canonical form):

[3]:
_ = ds.plot_lines()
../../_images/userguide_plotting_plot_types_5_0.png

Image Plot

For 2D data where both axes are numerical:

[4]:
_ = ds.plot_image()
../../_images/userguide_plotting_plot_types_7_0.png

Image plots automatically include a colorbar:

[5]:
_ = ds.plot_image(colorbar=True)
../../_images/userguide_plotting_plot_types_9_0.png

Hide the colorbar if needed:

[6]:
_ = ds.plot_image(colorbar=False)
../../_images/userguide_plotting_plot_types_11_0.png

Contour Plot

For continuous data with smooth transitions:

[7]:
_ = ds.plot_contour()
../../_images/userguide_plotting_plot_types_13_0.png

Contour plots also support colorbars:

[8]:
_ = ds.plot_contour(colorbar=True)
../../_images/userguide_plotting_plot_types_15_0.png

Decision Guide

Method

Use When

plot() / plot_lines()

Showing spectra, time series, or stacked traces

plot_image()

2D field with spatial x/y axes

plot_contour()

Smooth visualization of continuous 2D data

plot_surface()

3D perspective view of 2D data

plot_waterfall()

3D-style waterfall representation

Surface Plot

For a 3D perspective view of 2D data:

[9]:
_ = ds.plot_surface(y_reverse=True, linewidth=0)
../../_images/userguide_plotting_plot_types_18_0.png

Waterfall Plot

For a waterfall-style representation:

[10]:
_ = ds.plot_waterfall(y_reverse=True, figsize=(6, 5))
../../_images/userguide_plotting_plot_types_20_0.png

Combining with Options

All plot methods accept the same customization options:

[11]:
_ = ds.plot_image(
    cmap="plasma",
    xlim=(2000, 1300),
    ylim=(1, 5),
)
../../_images/userguide_plotting_plot_types_22_0.png

The appropriate method is chosen automatically when you call ds.plot(), but explicit methods make your intent clear and provide specific functionality.

Deprecated Method Names

The following method names are deprecated but still work:

Deprecated

Current (Canonical)

plot_stack()

plot_lines()

plot_map()

plot_contour()

plot(method="image")

plot_image() or plot_contourf()

Using the canonical names is recommended for new code.