Plotting Preferences#

While keyword arguments customize individual plots, preferences control persistent defaults that affect all future plots in the current session and the following ones.

Accessing Preferences#

[1]:
import spectrochempy as scp

prefs = scp.preferences

Preferences are organized by category. The most commonly used are:

[2]:
print("Figure size:", prefs.figure.figsize)
print("Default colormap:", prefs.colormap)
print("Font family:", prefs.font.family)
print("Current style:", prefs.style)
Figure size: (6, 4)
Default colormap: auto
Font family: sans-serif
Current style: scpy

Changing Defaults#

Set a preference once; it affects all subsequent plots:

[3]:
ds = scp.read("irdata/nh4y-activation.spg")
[4]:
# Save original values for later restoration
original_cmap = prefs.colormap
original_figsize = prefs.figure.figsize
[5]:
# Change defaults
prefs.colormap = "magma"
prefs.figure.figsize = (8, 4)

Now all plots use these new defaults. The figure size applies to every plot, while prefs.colormap applies to image and contour plots:

[6]:
_ = ds.plot()
../../_images/userguide_plotting_preferences_10_0.png
[7]:
_ = ds.plot_image()
../../_images/userguide_plotting_preferences_11_0.png

Resetting to Defaults#

[8]:
# Restore original values
prefs.colormap = original_cmap
prefs.figure.figsize = original_figsize

Alternatively, reset all plotting preferences to defaults:

[9]:
prefs.reset()

Common Preferences#

Preference

Description

prefs.colormap

Default colormap for plots (“auto” for automatic selection)

prefs.colormap_sequential

Default sequential colormap (e.g., “viridis”)

prefs.colormap_diverging

Default diverging colormap (e.g., “RdBu_r”)

prefs.figure.figsize

Default figure (width, height)

prefs.font.family

Font family (sans-serif, serif, monospace)

prefs.font.size

Default font size

prefs.axes.grid

Show grid by default

prefs.style

Default visual style

Example: setting font and colormap:

[10]:
prefs.font.family = "serif"
prefs.colormap_sequential = "plasma"
_ = ds.plot()
../../_images/userguide_plotting_preferences_18_0.png
[11]:
# Reset for other examples
prefs.reset()

Group Access#

Preferences can be accessed by group. For example, all line-related preferences:

[12]:
prefs.lines
[12]:
lines
antialiased
:
True
dash_capstyle
:
butt
dash_joinstyle
:
round
dashdot_pattern
:
(3.0, 5.0, 1.0, 5.0)
dashed_pattern
:
(6.0, 6.0)
dotted_pattern
:
(1.0, 3.0)
linestyle
:
-
linewidth
:
0.75
marker
:
None
markeredgecolor
:
auto
markeredgewidth
:
0.0
markerfacecolor
:
auto
markersize
:
7.0
scale_dashes
:
False
solid_capstyle
:
round
solid_joinstyle
:
round

Or all font-related preferences:

[13]:
prefs.font
[13]:
font
family
:
sans-serif
size
:
10.0
stretch
:
normal
style
:
normal
variant
:
normal
weight
:
normal

Getting Help#

Get help on a specific preference:

[14]:
prefs.help("colormap")
colormap = auto     [default: auto]
                    Colormap name or 'auto' for automatic selection based on data

The Mental Model#

  • Keyword arguments (ds.plot(cmap="magma")) → single plot

  • Preferences (prefs.colormap = "magma") → all future plots

  • Style (ds.plot(style="grayscale")) → appearance theme

Use preferences for session-long defaults; kwargs for one-off changes.

To list all available preferences with their current and default values, run prefs.list_all().