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()
Or using plot_lines() explicitly (canonical form):
[3]:
_ = ds.plot_lines()
Image Plotο
For 2D data where both axes are numerical:
[4]:
_ = ds.plot_image()
Image plots automatically include a colorbar:
[5]:
_ = ds.plot_image(colorbar=True)
Hide the colorbar if needed:
[6]:
_ = ds.plot_image(colorbar=False)
Contour Plotο
For continuous data with smooth transitions:
[7]:
_ = ds.plot_contour()
Contour plots also support colorbars:
[8]:
_ = ds.plot_contour(colorbar=True)
Decision Guideο
Method |
Use When |
|---|---|
|
Showing spectra, time series, or stacked traces |
|
2D field with spatial x/y axes |
|
Smooth visualization of continuous 2D data |
|
3D perspective view of 2D data |
|
3D-style waterfall representation |
Surface Plotο
For a 3D perspective view of 2D data:
[9]:
_ = ds.plot_surface(y_reverse=True, linewidth=0)
Waterfall Plotο
For a waterfall-style representation:
[10]:
_ = ds.plot_waterfall(y_reverse=True, figsize=(6, 5))
Combining with Optionsο
All plot methods accept the same customization options:
[11]:
_ = ds.plot_image(
cmap="plasma",
xlim=(2000, 1300),
ylim=(1, 5),
)
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) |
|---|---|
|
|
|
|
|
|
Using the canonical names is recommended for new code.