Dark Theme
Using of themes for the plots¶
For working with different color themes, you can import color_schemas
into the Notebook and overwrite the default theme.
In [1]:
Copied!
# Loading packages and default data
from spectrafit.plugins import notebook as nb
import pandas as pd
df = pd.read_csv(
"https://raw.githubusercontent.com/Anselmoo/spectrafit/main/Examples/data.csv"
)
# Loading packages and default data from spectrafit.plugins import notebook as nb import pandas as pd df = pd.read_csv( "https://raw.githubusercontent.com/Anselmoo/spectrafit/main/Examples/data.csv" )
Loading of the dark color theme¶
In [2]:
Copied!
from spectrafit.plugins import color_schemas as cs
spn = nb.SpectraFitNotebook(
df=df,
x_column="Energy",
y_column="Noisy",
color=cs.DraculaColor(),
font=cs.DraculaFont(),
)
from spectrafit.plugins import color_schemas as cs spn = nb.SpectraFitNotebook( df=df, x_column="Energy", y_column="Noisy", color=cs.DraculaColor(), font=cs.DraculaFont(), )
--------------------------------------------------------------------------- ValidationError Traceback (most recent call last) Cell In[2], line 3 1 from spectrafit.plugins import color_schemas as cs ----> 3 spn = nb.SpectraFitNotebook( 4 df=df, 5 x_column="Energy", 6 y_column="Noisy", 7 color=cs.DraculaColor(), 8 font=cs.DraculaFont(), 9 ) File ~/LocalDocuments/GitHub_Forks/spectrafit/spectrafit/plugins/notebook.py:892, in SpectraFitNotebook.__init__(self, df, x_column, y_column, oversampling, smooth, shift, energy_start, energy_stop, title, xaxis_title, yaxis_title, residual_title, metric_title, run_title, legend_title, show_legend, legend, font, minor_ticks, color, grid, size, fname, folder, description) 882 self.args_pre = DataPreProcessingAPI( 883 oversampling=oversampling, 884 energy_start=energy_start, (...) 888 column=list(self.df.columns), 889 ) 890 self.args_desc = description --> 892 self.args_plot = PlotAPI( 893 x=self.x_column, 894 y=self.y_column, 895 title=title, 896 xaxis_title=xaxis_title, 897 yaxis_title=yaxis_title, 898 residual_title=residual_title, 899 metric_title=metric_title, 900 run_title=run_title, 901 legend_title=legend_title, 902 show_legend=show_legend, 903 legend=legend, 904 font=font, 905 minor_ticks=minor_ticks, 906 color=color, 907 grid=grid, 908 size=size, 909 ) 910 self.export_args_df = FnameAPI(fname=fname, folder=folder, suffix="csv") 911 self.export_args_out = FnameAPI(fname=fname, folder=folder, suffix="lock") File ~/LocalDocuments/GitHub_Forks/spectrafit/.venv/lib/python3.11/site-packages/pydantic/main.py:150, in BaseModel.__init__(__pydantic_self__, **data) 148 # `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks 149 __tracebackhide__ = True --> 150 __pydantic_self__.__pydantic_validator__.validate_python(data, self_instance=__pydantic_self__) ValidationError: 2 validation errors for PlotAPI font Input should be a valid dictionary or instance of FontAPI [type=model_type, input_value=DraculaFont(family='Fira ...ize=12, color='#f8f8f2'), input_type=DraculaFont] For further information visit https://errors.pydantic.dev/2.1.2/v/model_type color Input should be a valid dictionary or instance of ColorAPI [type=model_type, input_value=DraculaColor(intensity='#...f8f8f2', font='#f8f8f2'), input_type=DraculaColor] For further information visit https://errors.pydantic.dev/2.1.2/v/model_type
Define the fitting model as usual¶
In [3]:
Copied!
initial_model = [
{
"pseudovoigt": {
"amplitude": {"max": 2, "min": 0, "vary": True, "value": 1},
"center": {"max": 2, "min": -2, "vary": True, "value": 0},
"fwhmg": {"max": 0.3, "min": 0.02, "vary": True, "value": 0.1},
"fwhml": {"max": 0.2, "min": 0.01, "vary": True, "value": 0.1},
}
},
{
"gaussian": {
"amplitude": {"max": 2, "min": 0, "vary": True, "value": 0.3},
"center": {"max": 2.0, "min": 0, "vary": True, "value": 2},
"fwhmg": {"max": 0.3, "min": 0.02, "vary": True, "value": 0.1},
}
},
{
"gaussian": {
"amplitude": {"max": 2, "min": 0, "vary": True, "value": 0.3},
"center": {"max": 3.5, "min": 1.5, "vary": True, "value": 2.5},
"fwhmg": {"max": 0.4, "min": 0.02, "vary": True, "value": 0.2},
}
},
{
"gaussian": {
"amplitude": {"max": 2, "min": 0, "vary": True, "value": 0.3},
"center": {"max": 3.5, "min": 2, "vary": True, "value": 2.5},
"fwhmg": {"max": 0.4, "min": 0.02, "vary": True, "value": 0.3},
}
},
{
"gaussian": {
"amplitude": {"max": 2, "min": 0, "vary": True, "value": 0.3},
"center": {"max": 4.5, "min": 3, "vary": True, "value": 2.5},
"fwhmg": {"max": 0.4, "min": 0.02, "vary": True, "value": 0.3},
}
},
{
"gaussian": {
"amplitude": {"max": 2, "min": 0, "vary": True, "value": 0.3},
"center": {"max": 4.7, "min": 3.7, "vary": True, "value": 3.8},
"fwhmg": {"max": 0.4, "min": 0.02, "vary": True, "value": 0.3},
}
},
]
initial_model = [ { "pseudovoigt": { "amplitude": {"max": 2, "min": 0, "vary": True, "value": 1}, "center": {"max": 2, "min": -2, "vary": True, "value": 0}, "fwhmg": {"max": 0.3, "min": 0.02, "vary": True, "value": 0.1}, "fwhml": {"max": 0.2, "min": 0.01, "vary": True, "value": 0.1}, } }, { "gaussian": { "amplitude": {"max": 2, "min": 0, "vary": True, "value": 0.3}, "center": {"max": 2.0, "min": 0, "vary": True, "value": 2}, "fwhmg": {"max": 0.3, "min": 0.02, "vary": True, "value": 0.1}, } }, { "gaussian": { "amplitude": {"max": 2, "min": 0, "vary": True, "value": 0.3}, "center": {"max": 3.5, "min": 1.5, "vary": True, "value": 2.5}, "fwhmg": {"max": 0.4, "min": 0.02, "vary": True, "value": 0.2}, } }, { "gaussian": { "amplitude": {"max": 2, "min": 0, "vary": True, "value": 0.3}, "center": {"max": 3.5, "min": 2, "vary": True, "value": 2.5}, "fwhmg": {"max": 0.4, "min": 0.02, "vary": True, "value": 0.3}, } }, { "gaussian": { "amplitude": {"max": 2, "min": 0, "vary": True, "value": 0.3}, "center": {"max": 4.5, "min": 3, "vary": True, "value": 2.5}, "fwhmg": {"max": 0.4, "min": 0.02, "vary": True, "value": 0.3}, } }, { "gaussian": { "amplitude": {"max": 2, "min": 0, "vary": True, "value": 0.3}, "center": {"max": 4.7, "min": 3.7, "vary": True, "value": 3.8}, "fwhmg": {"max": 0.4, "min": 0.02, "vary": True, "value": 0.3}, } }, ]
Run fitting and plot the results in the dark theme¶
In [4]:
Copied!
spn.solver_model(initial_model=initial_model)
spn.solver_model(initial_model=initial_model)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[4], line 1 ----> 1 spn.solver_model(initial_model=initial_model) NameError: name 'spn' is not defined