.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_examples\visualization\plot_piechart_amrreview.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_piechart_amrreview.py: Piechart AMR review =================== .. note:: The values can be changed to display other data. http://matplotlib.org/examples/color/named_colors.html http://matplotlib.org/examples/color/colormaps_reference.html http://matplotlib.org/api/patches_api.html#matplotlib.patches.Wedge http://matplotlib.org/api/text_api.html#matplotlib.text.Text =================== .. GENERATED FROM PYTHON SOURCE LINES 14-240 .. rst-class:: sphx-glr-horizontal * .. image-sg:: /_examples/visualization/images/sphx_glr_plot_piechart_amrreview_001.png :alt: plot piechart amrreview :srcset: /_examples/visualization/images/sphx_glr_plot_piechart_amrreview_001.png :class: sphx-glr-multi-img * .. image-sg:: /_examples/visualization/images/sphx_glr_plot_piechart_amrreview_002.png :alt: plot piechart amrreview :srcset: /_examples/visualization/images/sphx_glr_plot_piechart_amrreview_002.png :class: sphx-glr-multi-img * .. image-sg:: /_examples/visualization/images/sphx_glr_plot_piechart_amrreview_003.png :alt: plot piechart amrreview :srcset: /_examples/visualization/images/sphx_glr_plot_piechart_amrreview_003.png :class: sphx-glr-multi-img .. code-block:: default :lineno-start: 15 from __future__ import division # Libraries import seaborn as sns import matplotlib as mpl import matplotlib.pyplot as plt # Matplotlib font size configuration. mpl.rcParams['font.size'] = 9.0 # ------------------------------------------------------------------------ # HELPER METHODS # ------------------------------------------------------------------------ def transparency(cmap, alpha): """ """ for i,rgb in enumerate(cmap): cmap[i] = rgb + (alpha,) return cmap # ------------------------------------------------------------------------ # FIGURE 1 # ------------------------------------------------------------------------ # Common configuration. title_font_size = 30 labels = ['Prescription', 'Surveillance','Diagnosis', 'Dosing', 'Others'] # labels labels_empty = ['', '', '', '', ''] # labels empty colors = transparency(sns.color_palette("Set2", desat=0.75, n_colors=7), 0.4) explode = (0.00,0,0,0,0) # proportion with which to offset each wedge autopct = ''#'%1.0f%%' # print values inside the wedges pctdistance = 0.8 # ratio betwen center and text (default=0.6) labeldistance = 0.5 # radial distance wich pie labels are drawn shadow = False # shadow startangle = 90 # rotate piechart (default=0) radius = 1 # size of piechart (default=1) counterclock = False # fractions direction. center = (0,0) # center position of the chart. frame = False # plot axes frame with the pie chart. # map with arguments for the text objects. textprops = {'fontsize':'x-large'} # map with arguments for the wedge objects. wedgeprops = {} # Color manually selected colors_manual = ['mediumpurple', 'violet', 'mediumaquamarine', 'lightskyblue', 'lightsalmon', 'indianred'] # --------------------------- # plot # --------------------------- # Portions. sizes = [69, 10, 5, 2, 14] # Add proportions # reset feature startangle = 90 # Plot plt.figure() plt.pie(sizes, explode=explode, labels=labels, # Use: labels / labels_empty colors=colors, # Use: colors / colors_manual autopct=autopct, pctdistance=pctdistance, labeldistance=labeldistance, shadow=shadow, startangle=startangle, radius=radius, counterclock=counterclock, center=center, frame=frame, textprops=textprops, wedgeprops={'linewidth':0.35, 'edgecolor':'k'}) # Format figure. plt.axis('equal') plt.tight_layout() plt.title("", fontsize=title_font_size) # Add title. #plt.legend(labels=labels, fontsize='xx-large') # Add legend. # ------------------------------------------------------------------------ # FIGURE 2 # ------------------------------------------------------------------------ # Common configuration. title_font_size = 30 labels = ['Rule-based', 'Tree-based','Case-based', 'Other'] # labels labels_empty = ['', '', '', ''] # labels empty colors = transparency(sns.color_palette("Set2", desat=0.75, n_colors=7), 0.4) explode = (0.00,0,0,0) # proportion with which to offset each wedge autopct = ''#'%1.0f%%' # print values inside the wedges pctdistance = 0.6 # ratio betwen center and text (default=0.6) labeldistance = 0.4 # radial distance wich pie labels are drawn shadow = False # shadow startangle = 90 # rotate piechart (default=0) radius = 1 # size of piechart (default=1) counterclock = False # fractions direction. center = (0,0) # center position of the chart. frame = False # plot axes frame with the pie chart. # map with arguments for the text objects. textprops = {'fontsize':'x-large'} # map with arguments for the wedge objects. wedgeprops = {} # Color manually selected colors_manual = ['mediumpurple', 'violet', 'mediumaquamarine', 'lightskyblue', 'lightsalmon', 'indianred'] # --------------------------- # plot # --------------------------- # Portions. sizes = [64, 18, 10, 6] # Add proportions # reset feature startangle = 90 # Plot plt.figure() plt.pie(sizes, explode=explode, labels=labels, # Use: labels / labels_empty colors=colors, # Use: colors / colors_manual autopct=autopct, pctdistance=pctdistance, labeldistance=labeldistance, shadow=shadow, startangle=startangle, radius=radius, counterclock=counterclock, center=center, frame=frame, textprops=textprops, wedgeprops={'linewidth':0.35, 'edgecolor':'k'}) # Format figure. plt.axis('equal') plt.tight_layout() plt.title("", fontsize=title_font_size) # Add title. #plt.legend(labels=labels, fontsize='xx-large') # Add legend. # ------------------------------------------------------------------------ # FIGURE 3 # ------------------------------------------------------------------------ # Common configuration. title_font_size = 30 labels = ['Bacteremia', 'SSI','UTI', 'RTI' ' C+', 'Gram'] # labels labels_empty = ['', '', '', '', '', ''] # labels empty colors = transparency(sns.color_palette("Set2", desat=0.75, n_colors=7), 0.4) explode = (0.00,0,0,0,0,0) # proportion with which to offset each wedge autopct = ''#'%1.0f%%' # print values inside the wedges pctdistance = 0.6 # ratio betwen center and text (default=0.6) labeldistance = 0.4 # radial distance wich pie labels are drawn shadow = False # shadow startangle = 90 # rotate piechart (default=0) radius = 1 # size of piechart (default=1) counterclock = False # fractions direction. center = (0,0) # center position of the chart. frame = False # plot axes frame with the pie chart. # map with arguments for the text objects. textprops = {'fontsize':'x-large'} # map with arguments for the wedge objects. wedgeprops = {} # Color manually selected colors_manual = ['mediumpurple', 'violet', 'mediumaquamarine', 'lightskyblue', 'lightsalmon', 'indianred'] # --------------------------- # plot # --------------------------- # Portions. sizes = [49, 19, 14, 14, 2, 2] # Add proportions # reset feature startangle = 90 # Plot plt.figure() plt.pie(sizes, explode=explode, labels=labels_empty, # Use: labels / labels_empty colors=colors, # Use: colors / colors_manual autopct=autopct, pctdistance=pctdistance, labeldistance=labeldistance, shadow=shadow, startangle=startangle, radius=radius, counterclock=counterclock, center=center, frame=frame, textprops=textprops, wedgeprops={'linewidth':0.35, 'edgecolor':'k'}) # Format figure. plt.axis('equal') plt.tight_layout() plt.title("", fontsize=title_font_size) # Add title. #plt.legend(labels=labels, fontsize='xx-large') # Add legend. # Show figures plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.163 seconds) .. _sphx_glr_download__examples_visualization_plot_piechart_amrreview.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_piechart_amrreview.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_piechart_amrreview.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_