.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "example_gallery/2d_hist/2d_hist_correlations.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_example_gallery_2d_hist_2d_hist_correlations.py: 2D histograms ============= Plot multiple 2D histograms with the variable registry. .. GENERATED FROM PYTHON SOURCE LINES 7-66 .. rst-class:: sphx-glr-horizontal * .. image-sg:: /example_gallery/2d_hist/images/sphx_glr_2d_hist_correlations_001.svg :alt: 2d hist correlations :srcset: /example_gallery/2d_hist/images/sphx_glr_2d_hist_correlations_001.svg :class: sphx-glr-multi-img * .. image-sg:: /example_gallery/2d_hist/images/sphx_glr_2d_hist_correlations_002.svg :alt: 2d hist correlations :srcset: /example_gallery/2d_hist/images/sphx_glr_2d_hist_correlations_002.svg :class: sphx-glr-multi-img * .. image-sg:: /example_gallery/2d_hist/images/sphx_glr_2d_hist_correlations_003.svg :alt: 2d hist correlations :srcset: /example_gallery/2d_hist/images/sphx_glr_2d_hist_correlations_003.svg :class: sphx-glr-multi-img .. code-block:: Python from plothist_utils import get_dummy_data df = get_dummy_data() ### import os import time from itertools import combinations from plothist import ( create_variable_registry, get_variable_from_registry, make_2d_hist, plot_2d_hist, update_variable_registry_binning, ) # No need to redo this step if the registry was already created before variable_keys = ["variable_0", "variable_1", "variable_2"] unique_id = str(int(time.time() * 1000))[-8:] # unique ID based on current time temporary_registry_path = f"./_temporary_variable_registry_{unique_id}.yaml" create_variable_registry(variable_keys, path=temporary_registry_path) update_variable_registry_binning(df, variable_keys, path=temporary_registry_path) # Get all the correlation plot between the variables variable_keys_combinations = list(combinations(variable_keys, 2)) figs = [] for variable_keys_combination in variable_keys_combinations: variable0 = get_variable_from_registry( variable_keys_combination[0], path=temporary_registry_path ) variable1 = get_variable_from_registry( variable_keys_combination[1], path=temporary_registry_path ) h = make_2d_hist( [df[variable0["name"]], df[variable1["name"]]], bins=(variable0["bins"], variable1["bins"]), range=(variable0["range"], variable1["range"]), ) fig, ax, ax_colorbar = plot_2d_hist(h, colorbar_kwargs={"label": "Entries"}) ax.set_xlabel(variable0["name"]) ax.set_ylabel(variable1["name"]) ax.set_xlim(variable0["range"]) ax.set_ylim(variable1["range"]) figs.append(fig) for i, fig in enumerate(figs): fig.savefig(f"2d_hist_correlations_{i}.svg", bbox_inches="tight") os.remove(temporary_registry_path) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 11.725 seconds) .. _sphx_glr_download_example_gallery_2d_hist_2d_hist_correlations.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 2d_hist_correlations.ipynb <2d_hist_correlations.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 2d_hist_correlations.py <2d_hist_correlations.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 2d_hist_correlations.zip <2d_hist_correlations.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_