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.