.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_examples\visualization\plot_pyplot_timeseries.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_timeseries.py: Plotly - Timeseries ------------------- .. todo:: Explain and Simplify .. todo: Frequency might not be working? Frequency can be computed as sum of columns. .. GENERATED FROM PYTHON SOURCE LINES 11-88 .. rst-class:: sphx-glr-script-out .. code-block:: none '\n\n# --------------------------------------------------------------------\n# Main\n# --------------------------------------------------------------------\n# Load data\ndata, antibiotics, organisms = load_data_nhs()\n\n# Count records per specimen code\nspecimen_code_count = data .groupby(\'laboratory_number\').head(1) .specimen_code.value_counts(normalize=True) .sort_values(ascending=False)\n\n# Filter most frequent specimens\ndata = data[data.specimen_code.isin( specimen_code_count.index.values[:1])]\n\n# -------------------------------------------\n# Compute Freq and SARI\n# -------------------------------------------\n# Create instance\nfreq = Frequency(column_antibiotic=\'antimicrobial_code\',\n column_organism=\'microorganism_code\',\n column_date=\'date_received\',\n column_outcome=\'sensitivity\')\n\n# Create daily frequency\ndaily = freq.compute(data, strategy=\'ITI\',\n by_category=\'pairs\',\n fs=\'1M\')\n\ndaily[\'freq\'] = daily.sum(axis=1)\n\nimport plotly.express as px\nimport pandas as pd\n\nprint(daily)\n\ndaily = daily.reset_index()\ndaily = daily[daily.SPECIE.isin([\'ECOL\', \'PSEUD\']) &\n daily.ANTIBIOTIC.isin([\'AAUG\'])]\n\n\n\nfig = px.bar(daily, x=\'DATE\', y=\'freq\',\n title=\'Time Series with Range Slider and Selectors\',\n facet_col=\'SPECIE\')\n\nfig.update_xaxes(\n rangeslider_visible=True,\n rangeselector=dict(\n buttons=list([\n dict(count=1, label="1m", step="month", stepmode="backward"),\n dict(count=6, label="6m", step="month", stepmode="backward"),\n dict(count=1, label="YTD", step="year", stepmode="todate"),\n dict(count=1, label="1y", step="year", stepmode="backward"),\n dict(step="all")\n ])\n )\n)\n\nfig.show()\n' | .. code-block:: default :lineno-start: 12 # Libraries import sys import glob import numpy as np import pandas as pd import seaborn as sns import matplotlib as mpl import matplotlib.pyplot as plt # Import own libraries from pyamr.core.freq import Frequency from pyamr.datasets.load import load_data_nhs """ # -------------------------------------------------------------------- # Main # -------------------------------------------------------------------- # Load data data, antibiotics, organisms = load_data_nhs() # Count records per specimen code specimen_code_count = data \ .groupby('laboratory_number').head(1) \ .specimen_code.value_counts(normalize=True) \ .sort_values(ascending=False) # Filter most frequent specimens data = data[data.specimen_code.isin( \ specimen_code_count.index.values[:1])] # ------------------------------------------- # Compute Freq and SARI # ------------------------------------------- # Create instance freq = Frequency(column_antibiotic='antimicrobial_code', column_organism='microorganism_code', column_date='date_received', column_outcome='sensitivity') # Create daily frequency daily = freq.compute(data, strategy='ITI', by_category='pairs', fs='1M') daily['freq'] = daily.sum(axis=1) import plotly.express as px import pandas as pd print(daily) daily = daily.reset_index() daily = daily[daily.SPECIE.isin(['ECOL', 'PSEUD']) & daily.ANTIBIOTIC.isin(['AAUG'])] fig = px.bar(daily, x='DATE', y='freq', title='Time Series with Range Slider and Selectors', facet_col='SPECIE') fig.update_xaxes( rangeslider_visible=True, rangeselector=dict( buttons=list([ dict(count=1, label="1m", step="month", stepmode="backward"), dict(count=6, label="6m", step="month", stepmode="backward"), dict(count=1, label="YTD", step="year", stepmode="todate"), dict(count=1, label="1y", step="year", stepmode="backward"), dict(step="all") ]) ) ) fig.show() """ .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.001 seconds) .. _sphx_glr_download__examples_visualization_plot_pyplot_timeseries.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_timeseries.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_pyplot_timeseries.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_