Styles๏ƒ

Styles provide theme-level control over visual appearance. They affect fonts, grids, backgrounds, and default colormaps without changing your code.

Available Styles๏ƒ

SpectroChemPy includes several built-in styles:

[1]:
import spectrochempy as scp

ds = scp.read("irdata/nh4y-activation.spg")

# List style files in the stylesheets directory
from pathlib import Path

styles_dir = Path(scp.preferences.stylesheets)
print("Available styles:")
for f in sorted(styles_dir.glob("*.mplstyle")):
    print(f"  - {f.stem}")
Available styles:
  - grayscale
  - mycustom
  - notebook
  - paper
  - poster
  - sans
  - scpy
  - serif
  - talk

Applying a Style๏ƒ

Apply a style to a single plot:

[2]:
_ = ds.plot(style="grayscale")
../../_images/userguide_plotting_styles_4_0.png

Combining Style with Options๏ƒ

Styles work with all other plot options:

[3]:
_ = ds.plot(style="grayscale", xlim=(1800, 1500), ylim=(0, 2.5), grid=True)
../../_images/userguide_plotting_styles_6_0.png

Setting a Default Style๏ƒ

Make a style persistent across your session and future sessions by setting it in preferences:

[4]:
original_style = scp.preferences.style
scp.preferences.style = "grayscale"
_ = ds.plot()
../../_images/userguide_plotting_styles_8_0.png
[5]:
scp.preferences.style = "ggplot"
_ = ds.plot()
../../_images/userguide_plotting_styles_9_0.png

Reset to default:

[6]:
scp.preferences.style = original_style

Style Characteristics๏ƒ

Style

Characteristics

scpy

Default SpectroChemPy appearance

grayscale

Grayscale colors, sets image.cmap to โ€œgrayโ€

serif

Serif fonts

sans

Sans-serif fonts

paper

Smaller fonts, higher DPI

notebook

Optimized for Jupyter

talk

Large fonts for presentations

poster

Very large fonts

Creating Custom Styles๏ƒ

You can create your own style based on current preferences:

[7]:
# Set preferences
prefs = scp.preferences
prefs.colormap_sequential = "jet"
prefs.font.family = "monospace"
prefs.font.size = 30
prefs.axes.grid = True

# Create a custom style
prefs.makestyle("mycustom")

# Reset to defaults
prefs.reset()

# Now use your custom style
_ = ds.plot(style="mycustom")
../../_images/userguide_plotting_styles_14_0.png

How Styles Affect Colormaps๏ƒ

Styles affect colormaps only when:

  1. The style explicitly sets image.cmap in its definition

  2. prefs.colormap is set to โ€œautoโ€ (the default)

The grayscale style sets image.cmap = "gray", so it changes the colormap when prefs.colormap = "auto". If you set a specific prefs.colormap, the style will not override it.

Best Practice๏ƒ

  • Use styles for theme-level changes (publication, presentation)

  • Use kwargs for plot-specific adjustments

  • Use preferences for session defaults

This separation keeps your code flexible and reproducible.