Skip to content
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

Draft
wants to merge 6 commits into
base: dev
Choose a base branch
from
Draft

Plot customization example #228

wants to merge 6 commits into from

Conversation

TimLdl
Copy link
Collaborator

@TimLdl TimLdl commented Jun 30, 2023

Revised the plot customization example and guide and added an example plot with demonstrative labels.

@TimLdl TimLdl marked this pull request as draft June 30, 2023 16:18
@TimLdl TimLdl changed the base branch from master to dev June 30, 2023 16:31
@cverstege
Copy link
Member

I'll take a closer look in the coming days.

Comment on lines +450 to +452
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}')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

doc/src/parts/user_guide.rst Outdated Show resolved Hide resolved
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.
Copy link
Collaborator

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.

doc/src/parts/user_guide.rst Outdated Show resolved Hide resolved
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.
Copy link
Collaborator

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.

Copy link
Member

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.

Copy link
Member

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.

Suggested change
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__')])
Copy link
Collaborator

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()
Copy link
Collaborator

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.

Comment on lines +46 to +48
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}')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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}')

examples/005_convenience/customize.py Outdated Show resolved Hide resolved
Comment on lines +81 to +92
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
Copy link
Collaborator

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.

Copy link
Member

@cverstege cverstege left a 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
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants