ScirisOptions#
- class ScirisOptions[source]#
Bases:
objdictSet options for Sciris.
Note: this class should not be invoked directly. An instance is created automatically, which is the accessible via
sc.options.Use
sc.options.reset()to reset all values to default, orsc.options.set(dpi='default')to reset one parameter to default. Seesc.options.help(detailed=True)for more information.Options can also be saved and loaded using
sc.options.save()andsc.options.load(). Seesc.options.with_style()to set options temporarily.Common options are (see also
sc.options.help(detailed=True)):dpi: the overall DPI (i.e. size) of the figures
font: the font family/face used for the plots
fontsize: the font size used for the plots
backend: which Matplotlib backend to use
interactive: convenience method to set backend
jupyter: True or False; set defaults for Jupyter (change backend)
style: the plotting style to use (choices are ‘simple’ or ‘fancy’)
Each setting can also be set with an environment variable, e.g. SCIRIS_DPI. Note also the environment variable SCIRIS_LAZY, which imports Sciris lazily (i.e. does not import submodules).
Examples:
sc.options(dpi=150) # Larger size sc.options(style='simple', font='Rosario') # Change to the "simple" Sciris style with a custom font sc.options.set(fontsize=18, show=False, backend='agg', precision=64) # Multiple changes sc.options(interactive=False) # Turn off interactive plots sc.options(jupyter=True) # Defaults for Jupyter sc.options('defaults') # Reset to default options
New in version 1.3.0.New in version 2.0.0: revamped with additional optionsinteractiveandjupyter, plus stylesNew in version 3.0.0: renamed from Options to ScirisOptions to avoid potential confusion withsc.optionsNew in version 3.2.5: locked attributes to prevent accidental modificationMethods
- static get_orig_options()[source]#
Set the default options for Sciris – not to be called by the user, use
sc.options.set('defaults')instead.
- set(key=None, value=None, use=True, **kwargs)[source]#
Actually change the style. See
sc.options.help()for more information.- Parameters:
Example:
sc.options.set(dpi=50) # Equivalent to sc.options(dpi=50)
- context(**kwargs)[source]#
Alias to set() for non-plotting options, for use in a “with” block.
Note: for plotting options, use
sc.options.with_style(), which is linked to Matplotlib’s context manager. If you set plotting options with this, they won’t have any effect.
- set_show_type()[source]#
Set NumPy to show numbers as just e.g. 1.3 (Sciris default) or np.float64(1.3) (NumPy default)
- help(detailed=False, output=False)[source]#
Print information about options.
- Parameters:
Example:
sc.options.help(detailed=True)
- load(filename, verbose=True, **kwargs)[source]#
Load current settings from a JSON file.
- Parameters:
filename (str) – file to load
kwargs (dict) – passed to
sc.loadjson()
- save(filename, verbose=True, **kwargs)[source]#
Save current settings as a JSON file.
- Parameters:
filename (str) – file to save to
kwargs (dict) – passed to
sc.savejson()
- with_style(style=None, use=False, **kwargs)[source]#
Combine all Matplotlib style information, and either apply it directly or create a style context.
To set globally, use
sc.options.use_style(). Otherwise, usesc.options.with_style()as part of awithblock to set the style just for that block (using this function outsde of a with block and withuse=Falsehas no effect, so don’t do that!).Note: you can also just use
plt.style.context().- Parameters:
Valid style arguments are:
dpi: the figure DPIfont: font (typeface)fontsize: font sizegrid: whether or not to plot gridlinesfacecolor: color of the axes behind the plotany of the entries in
plt.rcParams
Examples:
with sc.options.with_style(dpi=300): # Use default options, but higher DPI plt.figure() plt.plot([1,3,6]) with sc.options.with_style(style='fancy'): # Use the "fancy" style plt.figure() plt.plot([6,1,3])