.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_examples\visualization\plot_dataframe_distb.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_dataframe_distb.py: Table Boxplot ============= .. GENERATED FROM PYTHON SOURCE LINES 6-180 .. image-sg:: /_examples/visualization/images/sphx_glr_plot_dataframe_distb_001.png :alt: R2, Prob(F), Prob(JB), P>|t| m, P>|t| n, DW :srcset: /_examples/visualization/images/sphx_glr_plot_dataframe_distb_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Data: org abx sari sart r2 f_prob jb jb_prob ptm ptn dw surveillance 0 ABAU AAMI 0.3906 -5.0000e-03 0.181 2.9400e-05 4.648 9.7900e-02 0.000 0.000 1.177 M 1 ABAU AAMO 0.9603 -1.2000e-03 0.053 1.9400e-02 631.965 5.9000e-138 0.019 0.000 1.848 M 2 ABAU AAUG 0.7578 -8.0000e-04 -0.004 4.2400e-01 13.083 1.4400e-03 0.424 0.000 1.640 M 3 ABAU AAZT 0.9706 -9.0000e-04 0.057 1.5600e-02 129.263 8.5300e-29 0.016 0.000 1.604 M 4 ABAU ACAZ 0.9417 -7.0000e-04 0.015 1.3200e-01 103.616 3.1600e-23 0.132 0.000 1.776 M ... ... ... ... ... ... ... ... ... ... ... ... ... 1726 SSAP AGEN 0.0026 -6.3420e-05 0.027 7.2100e-02 40.688 1.4600e-09 0.072 0.004 0.180 SW 1727 SSAP AMET 0.2897 3.8000e-03 0.539 5.1000e-16 2.913 2.3300e-01 0.000 0.000 0.115 SW 1728 SSAP ANIT 0.0118 -2.0000e-04 0.418 1.0700e-11 3.205 2.0100e-01 0.000 0.000 0.443 SW 1729 SSAP APEN 0.8494 -5.0000e-04 0.042 3.2400e-02 5.323 6.9800e-02 0.032 0.000 0.308 SW 1730 SSAP ATRI 0.0608 -1.6810e-05 -0.011 8.0200e-01 0.007 9.9700e-01 0.802 0.000 0.316 SW [1731 rows x 12 columns] | .. code-block:: default :lineno-start: 6 # Libraries import numpy as np import pandas as pd import seaborn as sns import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec from matplotlib import colors from pyamr.utils.plot import hlinebgplot import pyamr pyamr.utils.plot.scalar_colormap([1,2,3,4], 'coolwarm', vmin=0, vmax=10) # ------------------- # PLOTTING SETTINGS # ------------------- # Configuration for each columns info_sari = { 'cmap':'Reds', 'title':'SARI', 'xlim':[-0.1, 1.1], 'xticks':[0, 1], } info_sart = { 'cmap':'RdBu_r', 'title':'SART', 'xlim':[-1.2, 1.2], 'xticks':[-1, 1], } info_r2 = { 'cmap':'YlGn', 'title':'R2', 'ylim': [-0.2, 1.2], 'yticks': [.0, .2, .4, .6, .8 ] } info_fprob = { 'name':'f_prob', 'title':'Prob(F)', 'ylim': [-0.2, 1.2], 'yticks': [.0, .2, .4, .6, .8 ] } info_jb_prob = { 'cmap':'YlGn', 'title':'Prob(JB)', 'ylim': [-0.2, 1.2], 'hline': [{'yv':0.05, 'bg':0.0}], 'yticks': [.0, .2, .4, .6, .8 ] } info_dw = { 'cmap':'YlGn_r', 'title':'DW', 'hline': [{'yv':0.8, 'bg':4.0}], 'ylim': [-0, 4.2], 'yticks': [1, 2, 3] } info_slope = { 'name':'x1_tprob', 'cmap':'YlGn_r', 'title':'P>|t| m', 'hline': [{'yv':0.05, 'bg':1.0}], 'ylim': [-0.2, 1.2], 'yticks': [.0, .2, .4, .6, .8 ] } info_coefficient = { 'name':'c_tprob', 'cmap':'YlGn_r', 'title':'P>|t| n', 'hline': [{'yv':0.05, 'bg':1.0}], 'ylim': [-0.2, 1.2], 'yticks': [.0, .2, .4, .6, .8 ] } # Now we combine all of them together. Note # that the key value corresponds to the name # of the column it should be applied to. info = { 'sari': info_sari, 'sart': info_sart, 'dw': info_dw, 'r2': info_r2, 'jb_prob': info_jb_prob, 'ptm': info_slope, 'ptn': info_coefficient, 'f_prob': info_fprob } # ------------------------------------------- # Main # ------------------------------------------- # Data path. path = '../../pyamr/fixtures/fixture_surveillance.csv' # Rename rename = { 'organismCode': 'org', 'antibioticCode': 'abx', 'sari': 'sari', 'x1_coef': 'sart', 'adj_rsquared': 'r2', 'f_prob': 'f_prob', 'jarque-bera': 'jb', 'jarque_bera_prob': 'jb_prob', 'x1_tprob': 'ptm', 'c_tprob': 'ptn', 'durbin-watson': 'dw', 'surveillance': 'surveillance' } # Create data data = pd.read_csv(path) data = data[rename.keys()] data = data.rename(columns=rename) # Show print("\nData:") print(data) # ------------------------------------------- # Pair Grid # ------------------------------------------- # Features statistics = ['r2', 'f_prob', 'jb_prob', 'ptm', 'ptn', 'dw'] # Create figure f, axes = plt.subplots(1, len(statistics), figsize=(12, 3)) axes = axes.flatten() # Plot strips and format axes for ax, c in zip(axes, statistics): # Get information d = info[c] if c in info else {} # Plot distributions sns.boxplot(x='surveillance', y=data[c], ax=ax, data=data, whis=1e30, palette="Set3", linewidth=0.75) # Plot horizontal lines for e in d.get('hline', []): hlinebgplot(ax, right=3, **e) # Configure axes ax.set(title=d.get('title', c), xlabel='', ylabel='', ylim=d.get('ylim', None), yticks=d.get('yticks', ax.get_yticks())) #ax.tick_params(axis='y', which='both', length=0) ax.xaxis.grid(False) ax.yaxis.grid(False) # Despine sns.despine(bottom=True, left=True) # Change last ticks to right axes[-1].yaxis.tick_right() # Adjust space (overwritten by tight) plt.subplots_adjust(wspace=0.75) # Configure layout #plt.tight_layout() # Show plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.314 seconds) .. _sphx_glr_download__examples_visualization_plot_dataframe_distb.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_dataframe_distb.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_dataframe_distb.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_