.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/matrix_plot/changing_plot_defaults.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_matrix_plot_changing_plot_defaults.py: Changing Plot Defaults ====================== This example demonstrates how to change the default plot settings for the matrix plot. This includes changing the plot type on the diagonals, changing the plot type for the off-diagonals. .. GENERATED FROM PYTHON SOURCE LINES 7-23 .. code-block:: Python from tsunami_ip_utils.viz.viz import matrix_plot from tsunami_ip_utils.viz.plot_utils import generate_plot_objects_array_from_contributions from tsunami_ip_utils.integral_indices import get_uncertainty_contributions from paths import EXAMPLES application_files = [ EXAMPLES / 'data' / 'example_sdfs' / 'MCT' / f'MIX-COMP-THERM-001-00{i}.sdf' for i in range(1,4) ] experiment_files = application_files contributions_nuclide, contributions_nuclide_reaction = get_uncertainty_contributions(application_files, experiment_files) labels = { 'applications': [ application_file.name for application_file in application_files ], 'experiments': [ experiment_file.name for experiment_file in experiment_files ], } .. GENERATED FROM PYTHON SOURCE LINES 24-31 Changing the Diagonal Plot Type ------------------------------- On the diagonals, where the application and experiment are the same, the plot is a pie chart of contributions to the nuclear-data indcued uncertainty, as shown in :ref:`sphx_glr_auto_examples_visualizing_contributions.py`. However, other types of plots, such as static bar plots can be used instead. This is done by specifying the ``diagonal_type`` in the :func:`tsunami_ip_utils.viz.plot_utils.generate_plot_objects_array_from_contributions` function. Note that any plot type available in :func:`tsunami_ip_utils.viz.viz.contribution_plot` can be used. .. GENERATED FROM PYTHON SOURCE LINES 33-36 Static Pie Chart Diagonals ^^^^^^^^^^^^^^^^^^^^^^^^^^ For a static pie chart, the ``diagonal_type`` should be set to ``'pie'`` .. GENERATED FROM PYTHON SOURCE LINES 36-45 .. code-block:: Python plot_objects_array_nuclide = generate_plot_objects_array_from_contributions( contributions_nuclide, '(Δk/k)^2', diagonal_type='pie' ) fig = matrix_plot(plot_objects_array_nuclide, plot_type='interactive', labels=labels) fig.show() .. raw:: html
.. GENERATED FROM PYTHON SOURCE LINES 46-49 Static Bar Chart Diagonals ^^^^^^^^^^^^^^^^^^^^^^^^^^ For a static pie chart, the ``diagonal_type`` should be set to ``'bar'`` .. GENERATED FROM PYTHON SOURCE LINES 49-58 .. code-block:: Python plot_objects_array_nuclide = generate_plot_objects_array_from_contributions( contributions_nuclide, '(Δk/k)^2', diagonal_type='bar' ) fig = matrix_plot(plot_objects_array_nuclide, plot_type='interactive', labels=labels) fig.show() .. raw:: html
.. GENERATED FROM PYTHON SOURCE LINES 59-62 If a plot type for which a variant with an interactive legend exists (e.g. ``'interactive_pie'``) is used, the interactive legend can be turned off by setting the ``interactive_contribution_legend`` parameter to ``False``. These plots can also be saved to an image .. GENERATED FROM PYTHON SOURCE LINES 62-72 .. code-block:: Python plot_objects_array_nuclide = generate_plot_objects_array_from_contributions( contributions_nuclide, '(Δk/k)^2', diagonal_type='interactive_pie', # This is the default, but it is shown here for clarity interactive_contribution_legend=False ) fig = matrix_plot(plot_objects_array_nuclide, plot_type='interactive', labels=labels) fig.show() .. raw:: html
.. GENERATED FROM PYTHON SOURCE LINES 73-77 Changing the Off-Diagonal Plot Type ----------------------------------- The off-diagonal plots can also be changed to a different type. By default, the off-diagonal plots are interactive scatter plots with an interactive legend, but they can just as easily be changed to a static matplotlib scatter plots .. GENERATED FROM PYTHON SOURCE LINES 77-87 .. code-block:: Python plot_objects_array_nuclide = generate_plot_objects_array_from_contributions( contributions_nuclide, '$(\\Delta k/k)^2$', # Since all plots are matplotlib plots, pylatex formatting can be used to make the labels look nice off_diagonal_type='scatter', diagonal_type='bar', ) fig = matrix_plot(plot_objects_array_nuclide, plot_type='interactive', labels=labels) fig.to_image( EXAMPLES / '_static' / 'matrix_bar_diagonal.png') # sphinx_gallery_thumbnail_path = '../../examples/_static/matrix_bar_diagonal.png' .. raw:: html
.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 38.242 seconds) .. _sphx_glr_download_auto_examples_matrix_plot_changing_plot_defaults.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: changing_plot_defaults.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: changing_plot_defaults.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: changing_plot_defaults.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_