Style
style
Style parameters for the elements scilayout draws.
scilayout.style.params holds the defaults for things like panel labels and
scalebars. Change a parameter directly, or load several from a JSON file with
use; both affect elements created afterwards. Setting an option when creating an
element (for example fontsize on a ScaleBar) overrides the parameter for that
element only. reset restores the defaults.
Examples:
>>> import scilayout
>>> scilayout.style.params["panellabel.fontsize"] = 10
>>> scilayout.style.params["panellabel.fontsize"]
10
>>> scilayout.style.reset()
Notes
All parameters:
| Parameter | Used for |
|---|---|
panellabel.case |
None keeps the text, "upper" or "lower" changes it |
panellabel.font |
font family of panel labels |
panellabel.fontsize |
font size of panel labels (pt) |
panellabel.fontweight |
font weight of panel labels |
panellabel.fontstyle |
font style of panel labels |
panellabel.xoffset |
label offset to the right of the panel corner (cm) |
panellabel.yoffset |
label offset below the panel corner (cm) |
scalebars.fontsize |
default font size of scalebar text (pt) |
scalebars.linewidth |
default linewidth of scalebars |
scalebars.pad |
default gap between a scalebar's line and its text (cm) |
figuretext.fontsize |
default font size of FigureText (pt) |
figuretext.fontstyle |
default font style of FigureText |
figuretext.fontweight |
default font weight of FigureText |
stats.linecolor |
color of StatsLine |
stats.linewidth |
linewidth of StatsLine |
stats.drop_amount |
length of a StatsLine's drops, as a fraction of the axes height |
defaultstyles
module-attribute
defaultstyles = {
"figuretext.fontsize": 8,
"figuretext.fontstyle": "normal",
"figuretext.fontweight": "normal",
"panellabel.case": None,
"panellabel.font": "sans-serif",
"panellabel.fontsize": 12,
"panellabel.fontstyle": "normal",
"panellabel.fontweight": "bold",
"panellabel.xoffset": -0.5,
"panellabel.yoffset": -0.3,
"scalebars.fontsize": 8,
"scalebars.linewidth": 1,
"scalebars.pad": 0.1,
"stats.linecolor": "black",
"stats.linewidth": 1,
"stats.drop_amount": 0.025,
}
The default value of every style parameter. Not changed by :func:use or by setting a parameter, so it is what :func:reset restores.
params
module-attribute
params = StyleDictionary()
The current style parameters. Read or set them like a dictionary, for example params["panellabel.fontsize"] = 10.
StyleDictionary
Bases: dict
A dictionary of style parameters that only accepts the keys it already has.
Keys are strings like "panellabel.fontsize". Reading works like a normal
dictionary, and params.key also works for keys that are valid Python names.
Setting an unknown key raises an error, which catches typos.
use
use(
filepath: str | Path,
params: dict[str, Any] = params,
allow_only_valid_keys: bool = True,
) -> None
Use a configuration file to set parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str or Path
|
Path to the JSON configuration file. |
required |
params
|
dict
|
The dictionary to set the parameters in. Defaults to |
params
|
allow_only_valid_keys
|
bool
|
If True (default) raise an error when the file has keys that are not already in
|
True
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |