.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_examples\visualization\plot_pyplot_sunburst.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__examples_visualization_plot_pyplot_sunburst.py: Plotly - Sunburst (sari) ------------------------ .. warning:: Please be patient, it might take some time to load. .. GENERATED FROM PYTHON SOURCE LINES 8-53 .. raw:: html


.. code-block:: default :lineno-start: 9 # Plotly import plotly.express as px # Import own libraries from pyamr.datasets.load import load_data_nhs # -------------------------------------------------------------------- # Main # -------------------------------------------------------------------- # Load data data, antibiotics, organisms = load_data_nhs(nrows=1000) # Create DataFrame dataframe = data.groupby(['specimen_code', 'microorganism_code', 'antimicrobial_code', 'sensitivity']) \ .size().unstack().fillna(0) # Compute frequency dataframe['freq'] = dataframe.sum(axis=1) # Compute sari dataframe['sari'] = dataframe.resistant / \ (dataframe.resistant + dataframe.sensitive) # Reset index dataframe = dataframe.reset_index() # ------------------------------------------- # Plot # ------------------------------------------- # Show fig = px.sunburst(dataframe, path=['specimen_code', 'microorganism_code', 'antimicrobial_code'], values='freq', color='sari', title='Sunburst of pairs') # Show #fig.show() fig .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 1.816 seconds) .. _sphx_glr_download__examples_visualization_plot_pyplot_sunburst.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_pyplot_sunburst.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_pyplot_sunburst.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_