-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plot customization example #228
base: dev
Are you sure you want to change the base?
Conversation
I'll take a closer look in the coming days. |
fit.assign_parameter_latex_names(x='t', a='\\alpha', b='\\beta') | ||
fit.assign_model_function_latex_name('\\theta') | ||
fit.assign_model_function_latex_expression('{a} \\cdot {x} + {b}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fit.assign_parameter_latex_names(x='t', a='\\alpha', b='\\beta') | |
fit.assign_model_function_latex_name('\\theta') | |
fit.assign_model_function_latex_expression('{a} \\cdot {x} + {b}') | |
fit.assign_parameter_latex_names(x='t', a=r'\alpha', b=r'\beta') | |
fit.assign_model_function_latex_name(r'\theta') | |
fit.assign_model_function_latex_expression(r'{a} \cdot {x} + {b}') |
Also it should be mentioned somewhere that when parameters are called alpha_1, beta, gamma_d, etc. in code they are automatically converted to LaTeX.
The corresponding values for the model function can also be customized: | ||
By default, the plot will use the labels specified for each dataset (see :ref:'container-labels'). | ||
If multiple fits are plotted to the same figure, the axis labels from the data containers are concatenated while skipping duplicates. | ||
Alternatively the axis labels can be overwritten for each fit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be either "overridden for each fit" or "set as properties for each fit" depending on what you mean.
p.customize('model_error_band', 'label', [(0, r'$\pm 1 \sigma$'), (1, r'$\pm 1 \sigma$')]) | ||
p.customize('model_error_band', 'color', [(0, 'orange'), (1, 'lightgreen')]) | ||
Additionally the axis scale can be changed to logarithmic. | ||
When changing between a linear and logarithmic x-axis scale, the supporting points for plotting the model function will be updated and evenly spaced on a linear or logarithmic scale. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what this sentence is supposed to mean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's correct. The x values for drawing in the models will be spaced logarithmically in this case. But I think there's no need to mention this in the documentation as this is expected behaviour.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest just to remove this sentence.
When changing between a linear and logarithmic x-axis scale, the supporting points for plotting the model function will be updated and evenly spaced on a linear or logarithmic scale. |
|
||
In order to change the name for the data set and suppress the second output, use the following call: | ||
.. code-block:: python | ||
plot.customize('data', 'label', [(0, "test data"), (1, '__del__')]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This syntax with [(fit_index, property)]
was not introduced I think. Please document it.
|
||
plot = Plot(fit_objects=fit) | ||
plot.plot(residual=True) | ||
plot.show() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid multiple calls to show
in a single example since it will block until the window is closed.
customized_fit.assign_parameter_latex_names(x='t', a='\\alpha', b='\\beta') | ||
customized_fit.assign_model_function_latex_name('\\theta') | ||
customized_fit.assign_model_function_latex_expression('{a} \\cdot {x} + {b}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
customized_fit.assign_parameter_latex_names(x='t', a='\\alpha', b='\\beta') | |
customized_fit.assign_model_function_latex_name('\\theta') | |
customized_fit.assign_model_function_latex_expression('{a} \\cdot {x} + {b}') | |
fit.assign_parameter_latex_names(x='t', a=r'\alpha', b=r'\beta') | |
fit.assign_model_function_latex_name(r'\theta') | |
fit.assign_model_function_latex_expression(r'{a} \cdot {x} + {b}') |
customized_plot.customize('model_line', 'label', | ||
'model line label') # Overwrite the model label in the info box | ||
|
||
customized_plot.customize('model_error_band', 'alpha', | ||
0.2) # Set the alpha value (transparency) for the error band | ||
customized_plot.customize('model_error_band', 'linestyle', | ||
'--') # Set the linestyle for the border of the error band | ||
customized_plot.customize('model_error_band', 'linewidth', | ||
3) # Set the linewidth for the border of the error band | ||
customized_plot.customize('model_error_band', 'color', '#DB1F0B') # Set the color of the error band | ||
customized_plot.customize('model_error_band', 'label', | ||
'model error band label') # Set the label for the error band |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to have comments above the code instead of having line breaks in the code.
Co-authored-by: Cedric Verstege <[email protected]>
Co-authored-by: Johannes Gäßler <[email protected]>
Co-authored-by: Johannes Gäßler <[email protected]>
Co-authored-by: Johannes Gäßler <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added some further comments.
Additionally, the other comments should also be addressed before merging.
@@ -6,82 +6,116 @@ | |||
It briefly demonstrates methods that modify the optics of kafe2 output. | |||
""" | |||
|
|||
from kafe2 import XYContainer, Fit, Plot | |||
from kafe2 import XYContainer, XYFit, Plot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change Fit to XYFit? Is there any reason? Fit is a wrapper which automatically uses the correct fit class.
line_fit = Fit(data=xy_data) | ||
line_fit.do_fit() | ||
|
||
fit = XYFit(xy_data=xy_data, model_function=model) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. Any reason why changing fit to XYFit?
|
||
# Now we will look at how to customize a plot | ||
# We create a new XYFit object which will be used for the customization: | ||
customized_fit = XYFit(xy_data=xy_data, model_function=model) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here Fit vs. XYFit. In general, the user doesn't really care if it's a XYFit or a HistFit. That's why we introduced the Fit wrapper, which automatically uses the correct Fit class based on the data it's given.
Using different Fit Objects like XYFit and HistFit just confuses new users not familiar wit OOP.
Revised the plot customization example and guide and added an example plot with demonstrative labels.