{"id":19912,"date":"2021-02-07T22:33:43","date_gmt":"2021-02-08T03:33:43","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/?p=19912"},"modified":"2025-06-25T02:24:50","modified_gmt":"2025-06-25T02:24:50","slug":"this-file-will-contain-visualization-code-for-6-health-performance-aspects","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=19912","title":{"rendered":"This file will contain visualization code for 6 health performance aspects"},"content":{"rendered":"\n<figure class=\"wp-block-image\"><a href=\"https:\/\/medium.com\/@SayedAhmedCanada?source=post_page-----80a91863ad74--------------------------------\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/miro.medium.com\/fit\/c\/96\/96\/1%2AqIditOG5oO0RmWRR7Iw4bA.png?w=750&#038;ssl=1\" alt=\"Justetc Social Services (non-profit)\"\/><\/a><\/figure>\n\n\n\n<p><a href=\"https:\/\/medium.com\/@SayedAhmedCanada?source=post_page-----80a91863ad74--------------------------------\">Justetc Social Services (non-profit)<\/a><a href=\"https:\/\/medium.com\/health-system-performance\/health-system-performance-with-seven-indicators-python-code-and-visualizations-80a91863ad74?source=post_page-----80a91863ad74--------------------------------\">Jan 31<\/a>&nbsp;\u00b7&nbsp;29&nbsp;min read<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"21c1\">Indicator visualizations will be in a separate ipynb file (visualize-indicators-final.ipynb)<\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"b5c6\">Visualizations can be created using the UI interface i.e. Select options and execute the code block after to get the visualizations.<\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"8b22\">I have placed a separate section at the end of this file where research questions and plots as I placed on my documents and presentations are placed (Code there will generate the plots for that section)<\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"e0d0\">For research question section, corresponding health status will need to be selected and data reloaded to re \u2014 execute (UI selections will not matter)<\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\">#!conda install basemapimport pandas as pd<br \/>import matplotlib.pyplot as plt<br \/>%matplotlib inline<br \/>import numpy as np<br \/><br \/>from __future__ import print_function<br \/>from ipywidgets import interact, interactive, fixed, interact_manual<br \/>import ipywidgets as widgets<br \/><br \/>import pandas as pd<br \/>import matplotlib.pyplot as plt<br \/>%matplotlib inline# it is important <br \/># from geopy.geocoders import Nominatim<br \/><br \/># for geo maps<br \/># !conda install basemap<br \/>import conda<br \/>import os<br \/>if 'PROJ_DIR' in os.environ:<br \/>    pyproj_datadir = os.environ['PROJ_DIR']<br \/>else:<br \/>    conda_file_dir = conda.CONDA_PACKAGE_ROOT<br \/>    conda_dir = conda_file_dir.split('lib')[0]<br \/>    pyproj_datadir = os.path.join(os.path.join(conda_dir, 'Library'),'share')<br \/>    os.environ['PROJ_LIB'] = pyproj_datadir<br \/> <br \/>#important<br \/>#from mpl_toolkits.basemap import Basemap<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"6b9c\">Location of the Data Files Folder.<\/h1>\n\n\n\n<p id=\"932e\">Data folder will have data files, one for one aspect of healthcare performance. I will load data file names(aspects) in a drop down \u2014 to act upon that. Hence, any new data files with similar structures (likely) can be easily integrated with the visualizations.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import os<br \/><br \/>data_folder = '.\/data\/'<br \/>measure_files = os.listdir(data_folder)<br \/>measure_files['.~lock.health-status.xls#',<br \/> 'access-to-care.xls',<br \/> 'health-status.xls',<br \/> 'non-med-determinants.xls',<br \/> 'patient-safety.xls',<br \/> 'prescribing-primary.xls',<br \/> 'quality-of-care.xls']<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"b00e\">Select a measure\/aspect to visualize upon<\/h1>\n\n\n\n<p id=\"1419\">If you see: [\u2018.~lock.health-status.xls#\u2019, or similar that needs to be ignored<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"fd4f\">Note: when a health-aspect i.e. measure will be changed in the drop-down below, some code need to be re-executed to load related data.<\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"dc0b\">I am marking with START-RELOAD-DATA and END-RELOAD-DATA<\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\">print('Select a health measure\/aspect to visualize\\n')<br \/># create the interactive interface<br \/>def f(measure):<br \/>    return measure<br \/><br \/>print('Select a measure:')<br \/>measure_file = interactive(f, measure = measure_files);<br \/>display(measure_file)Select a health measure\/aspect to visualize<br \/><br \/>Select a measure:<br \/><br \/><br \/><br \/>interactive(children=(Dropdown(description='measure', options=('.~lock.health-status.xls#', 'access-to-care.xl\u2026<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"c834\">Test what aspect\/measure we have selected<\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"e958\">START-RELOAD-DATA<\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\">'Selected: ' + measure_file.result'Selected: access-to-care.xls'if (measure_file.result == ''):<br \/>    measure_file.result = 'health-status.xls'<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"7b58\">Load Data and Display<\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\">data_file = data_folder + measure_file.result<br \/>measure_data = pd.read_excel(data_file)<br \/>measure_data.head()<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/miro.medium.com\/proxy\/1%2AHhuLkDM-CJQXWSAylx5gLA.png?w=750&#038;ssl=1\" alt=\"png\"\/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"1d4a\">Find all the performance indicators under this aspect\/measure<\/h1>\n\n\n\n<p id=\"5782\">irrespective we have data for Canada or not<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># find details on Indicators<br \/># find all indicators<br \/>measure_data.set_index(['Indicator'])<br \/>indicators = pd.Index(measure_data['Indicator']).unique()<br \/>indicatorsIndex(['Inability to Pay for Medical Bills', 'Poor Weekend\/Evening Care',<br \/>       'Regular Doctor', 'Same or Next Day Appt',<br \/>       'Wait Time: Cataract Surgery', 'Wait Time: Hip Replacement',<br \/>       'Wait Time: Knee Replacement', 'Wait Time: Specialist'],<br \/>      dtype='object', name='Indicator')<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"93fa\">Find the performance indicators under this aspect\/measure when Canada must have data<\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\"># indicators that must have canadian data<br \/><br \/># first where canada do exist<br \/>data_with_canada = measure_data[measure_data['Region'] == 'Canada']<br \/><br \/>#indicators when canada also have data<br \/>indicators_with_canada = data_with_canada['Indicator'].unique()<br \/><br \/>print('All indicators\\n', indicators)<br \/>print('Indicators where canada also has Data\\n', indicators_with_canada)<br \/>'Indicator Counts', len(indicators_with_canada), len(indicators)All indicators<br \/> Index(['Inability to Pay for Medical Bills', 'Poor Weekend\/Evening Care',<br \/>       'Regular Doctor', 'Same or Next Day Appt',<br \/>       'Wait Time: Cataract Surgery', 'Wait Time: Hip Replacement',<br \/>       'Wait Time: Knee Replacement', 'Wait Time: Specialist'],<br \/>      dtype='object', name='Indicator')<br \/>Indicators where canada also has Data<br \/> ['Inability to Pay for Medical Bills' 'Poor Weekend\/Evening Care'<br \/> 'Regular Doctor' 'Same or Next Day Appt' 'Wait Time: Cataract Surgery'<br \/> 'Wait Time: Hip Replacement' 'Wait Time: Knee Replacement'<br \/> 'Wait Time: Specialist']<br \/><br \/><br \/><br \/><br \/><br \/>('Indicator Counts', 8, 8)<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"22a3\">Find years as we can see in the data<\/h1>\n\n\n\n<p id=\"8c5e\">All years, also seprately when we have data for Canada<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># find all years<br \/>years = measure_data['Data year'].dropna().unique()<br \/>years_with_canada = data_with_canada['Data year'].dropna().unique()<br \/><br \/><br \/>print('Years we have data\\n', years)<br \/>print('Years where canada also has data\\n', years_with_canada)Years we have data<br \/> ['2016' 2016 'Not applicable' '2015' '2013']<br \/>Years where canada also has data<br \/> [2016]<\/pre>\n\n\n\n<p id=\"b107\">Years when we have data for Canada<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># sort years for all data<br \/>years = [ int(aYear) for aYear in years if (aYear != 'Not applicable') and len( str(aYear).split(' ')) &lt;= 1 ]<br \/>years = sorted(years)<br \/>years<br \/><br \/>all_years = [0] + years<br \/>all_years[0, 2013, 2015, 2016, 2016]<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"f3ee\">Sort the years so that we can show them in drop down in ascending format<\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"cb3f\">0 means all years selected<\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\"># sort years<br \/>years_with_canada = [ int(aYear) for aYear in years_with_canada if (aYear != 'Not applicable') and len( str(aYear).split(' ')) &lt;= 1 ]<br \/>years_with_canada = sorted(years_with_canada)<br \/>years_with_canada<br \/><br \/>all_years_canada = [0] + years_with_canada<br \/>all_years_canada[0, 2016]<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"0ee0\">All countries<\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\">countries = measure_data[ (measure_data['Type of region'] == 'Country') | (measure_data['Type of region'] == 'Canada') ]['Region']<br \/>countries = sorted (countries.unique())<br \/>#print(countries)<br \/>#countries = ['Canada'] + countries<br \/><br \/># bring Canada at the top<br \/>if 'Canada' in countries:<br \/>    countries = ['Canada'] + countries<br \/>    <br \/>countries[:1]['Canada']<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"2f48\">unique color code for each country<\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"7234\">color will be used as a third dimension in some plots<\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\"># countries unique color code<br \/>all_regions = measure_data['Region'].unique()<br \/>region_colors = []<br \/>region_colors_dict = {}<br \/>import random<br \/>random.seed(0)<br \/>for aRegion in all_regions:<br \/>    region_colors_dict[aRegion] = np.random.randint(0, 255)<br \/>    <br \/>list(region_colors_dict.keys())[:5], list(region_colors_dict.values())[:5](['United Kingdom',<br \/>  'Saskatchewan',<br \/>  'Germany',<br \/>  'British Columbia',<br \/>  'Australia'],<br \/> [227, 16, 56, 193, 232])# latitude and longitude information<br \/>geolocator = Nominatim(user_agent=\"chrome\")<br \/>lats, lons = [], []<br \/>lats_dict = {}<br \/>lons_dict = {}<br \/>#for aCountry in countries:<br \/>for aRegion in all_regions:  <br \/>    try:<br \/>        location = geolocator.geocode(aRegion)<br \/>        lats.append(location.latitude)<br \/>        lons.append(location.longitude)<br \/>        lats_dict[aRegion] = location.latitude<br \/>        lons_dict[aRegion] = location.longitude<br \/>    except:<br \/>        continue<br \/>    <br \/>lats_dict['Canada']<br \/>#list(zip(lats, lons))---------------------------------------------------------------------------<br \/><br \/>NameError                                 Traceback (most recent call last)<br \/><br \/>&lt;ipython-input-17-1521376715a3&gt; in &lt;module&gt;()<br \/>      1 # latitude and longitude information<br \/>----&gt; 2 geolocator = Nominatim(user_agent=\"chrome\")<br \/>      3 lats, lons = [], []<br \/>      4 lats_dict = {}<br \/>      5 lons_dict = {}<br \/><br \/><br \/>NameError: name 'Nominatim' is not defined# Province  unique color code<br \/>all_provinces = measure_data[ measure_data['Type of region'] == 'Province'  ]['Region'].unique()<br \/>province_colors = []<br \/>province_colors_dict = {}<br \/>import random<br \/>random.seed(0)<br \/>for aProvince in all_provinces:<br \/>    province_colors_dict[aProvince] = np.random.randint(0, 255)<br \/>    <br \/>list(province_colors_dict.keys()), list(province_colors_dict.values())(['Saskatchewan',<br \/>  'British Columbia',<br \/>  'Newfoundland and Labrador',<br \/>  'Manitoba',<br \/>  'Alberta',<br \/>  'Quebec',<br \/>  'New Brunswick',<br \/>  'Ontario',<br \/>  'Nova Scotia',<br \/>  'Prince Edward Island'],<br \/> [172, 161, 91, 156, 3, 216, 153, 234, 191, 96])<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"8427\">latitude longitude for all regions (countries, provinces)<\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"c5b6\">will be used in map\/geo plots<\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\"># latitude and longitude information<br \/>geolocator = Nominatim(user_agent=\"chrome\")<br \/>lats, lons = [], []<br \/>lats_dict = {}<br \/>lons_dict = {}<br \/>#for aCountry in countries:<br \/>for aRegion in all_regions:  <br \/>    try:<br \/>        location = geolocator.geocode(aRegion)<br \/>        lats.append(location.latitude)<br \/>        lons.append(location.longitude)<br \/>        lats_dict[aRegion] = location.latitude<br \/>        lons_dict[aRegion] = location.longitude<br \/>    except:<br \/>        continue<br \/>    <br \/>lats_dict['Canada']<br \/>#list(zip(lats, lons))---------------------------------------------------------------------------<br \/><br \/>NameError                                 Traceback (most recent call last)<br \/><br \/>&lt;ipython-input-19-1521376715a3&gt; in &lt;module&gt;()<br \/>      1 # latitude and longitude information<br \/>----&gt; 2 geolocator = Nominatim(user_agent=\"chrome\")<br \/>      3 lats, lons = [], []<br \/>      4 lats_dict = {}<br \/>      5 lons_dict = {}<br \/><br \/><br \/>NameError: name 'Nominatim' is not defined<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"8d4d\">Test to check the OECD Data: Benchmark data<\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\">for anIndicator in indicators:<br \/>    oecd_data = measure_data.loc[  (measure_data['Indicator'] == anIndicator)   &amp; (measure_data['Region'] == 'OECD average') ]<br \/>    #oecd_data['Value'].tolist()[0]<br \/>    print(oecd_data[ ['Indicator', 'Value', 'Data year' ]])<br \/><br \/>#print(all_years)<br \/>for aYear in all_years:<br \/>    indicator_data = measure_data.loc[  (measure_data['Indicator'] == indicators[0])  &amp; ( (measure_data['Data year'] == aYear) &amp; (measure_data['Type of region'].isin(['Country', 'Canada']) ) )   | \\<br \/>                                         ( (measure_data['Indicator'] == indicators[0]) &amp; (measure_data['Region'] == 'OECD average')) ]<br \/><br \/>    #print(indicator_data[ ['Indicator', 'Value', 'Data year' ]])<br \/>    #print(indicator_data['Value'])Indicator  Value       Data year<br \/>17  Inability to Pay for Medical Bills    8.7  Not applicable<br \/>                    Indicator  Value       Data year<br \/>27  Poor Weekend\/Evening Care   54.1  Not applicable<br \/>         Indicator  Value       Data year<br \/>57  Regular Doctor   94.6  Not applicable<br \/>                Indicator  Value       Data year<br \/>84  Same or Next Day Appt   59.2  Not applicable<br \/>                       Indicator  Value       Data year<br \/>110  Wait Time: Cataract Surgery   98.0  Not applicable<br \/>                      Indicator  Value       Data year<br \/>128  Wait Time: Hip Replacement  115.2  Not applicable<br \/>                       Indicator  Value       Data year<br \/>161  Wait Time: Knee Replacement  204.6  Not applicable<br \/>                 Indicator  Value       Data year<br \/>174  Wait Time: Specialist   41.9  Not applicable<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"b278\">END-RELOAD-DATA<\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"a52f\">Method to plot over years or only for a year.<\/h1>\n\n\n\n<p id=\"9384\">#Note: All combinations of UI selections might not work as that will require extensive testing and adjust (adjust with data and real life) #country might be represented by colors when applicable #supports plots such as: Bubble, Line, Bar, Hor Bar, Pie #other plot types can also be added. Once implemented will work for all measures and indicators (with proper data format provided) #Note: it is known to me that code can be improved here. similar codes are in multiple places \u2014 could be reduced<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#plt.rcParams['figure.figsize'] = [10, 15]<br \/>def plot_measure_by_years(year, indicator, bubble_scale, chart_type = '', ratios=[10, 1], animate=False, provincial_only=False, all_years=all_years, fig_size=[10, 10], sec_fig=True):<br \/>    plt.rcParams['figure.figsize'] = fig_size<br \/>    <br \/>    # redundend code to address a last minute bug<br \/>    # countries unique color code<br \/>    all_regions = measure_data['Region'].unique()<br \/>    region_colors = []<br \/>    region_colors_dict = {}<br \/>    import random<br \/>    random.seed(0)<br \/>    for aRegion in all_regions:<br \/>        region_colors_dict[aRegion] = np.random.randint(0, 255)<br \/>            <br \/>            <br \/>    # print('year, indicator', year, indicator)   <br \/>    <br \/>    # keep these, I might need this<br \/>    <br \/>    \"\"\"<br \/>    plt.ion()    <br \/>    f = plt.figure()<br \/>    ax = f.gca()<br \/>    <br \/>    #top box<br \/>    f.show()<br \/>    \"\"\"<br \/>    <br \/>    # benchmark data<br \/>    oecd_data = measure_data.loc[  (measure_data['Indicator'] == indicator)   &amp; (measure_data['Region'] == 'OECD average') ]<br \/>    #benchmark_value = oecd_data['Value']<br \/>    #print(type(benchmark_value), benchmark_value)<br \/>    benchmark_value = oecd_data['Value'].tolist()[0]<br \/>        <br \/>    <br \/>    # one improvement that can be made: usually I kept, two plots side by side. where the right one shows country and color<br \/>    # as in other cases we do not need the right one, code to hide the right one or just to create and use one subplot is more<br \/>    # appropriate<br \/>    # if (sec_fig == True):<br \/>    fig, axs = plt.subplots(1, 2, figsize=fig_size, sharey=False, gridspec_kw = {'width_ratios':ratios})<br \/>    #else:<br \/>    #axs = plt.subplots(1, 1, figsize=fig_size )<br \/>        <br \/>        <br \/>    #plt.xticks(rotation=90)<br \/>        <br \/>    # for one year    <br \/>    if ( year &gt; 1 ):<br \/>        <br \/>        indicator_data = measure_data.loc[  (measure_data['Indicator'] == indicator)  &amp; ( (measure_data['Data year'] == year) &amp; (measure_data['Type of region'].isin(['Country', 'Canada']) ) )   | \\<br \/>                                         ( (measure_data['Indicator'] == indicator) &amp; (measure_data['Region'] == 'OECD average')) ]<br \/>        if (provincial_only == True):<br \/>            indicator_data = measure_data.loc[  (measure_data['Indicator'] == indicator)  &amp; \\<br \/>                                              (measure_data['Data year'] == year) &amp; (measure_data['Type of region'].isin(['Province']))]<br \/>        <br \/>        #print(indicator_data)<br \/>        <br \/>        # for country color codes<br \/>        if (provincial_only == False):<br \/>            c =  [ region_colors_dict[x]  for x in indicator_data['Region'] ]    <br \/>            m =  [ x  for x in indicator_data['Region'] ] <br \/>            c_code =  [ x[0:3]  for x in indicator_data['Region'] ]  <br \/>        else:<br \/>            #province_colors_dict<br \/>            c =  [ province_colors_dict[x]  for x in indicator_data['Region'] ]    <br \/>            m =  [ x  for x in indicator_data['Region'] ] <br \/>            c_code =  [ x[0:3]  for x in indicator_data['Region'] ]<br \/>            region_colors_dict = province_colors_dict<br \/>            <br \/>        <br \/>        <br \/>        # this block might not apply to anything for one single year plot<br \/>        <br \/>        color_as_a_dimension = False<br \/>        if color_as_a_dimension == True:<br \/>            axs[1].scatter([1]*len(c), [i*5 for i in range(len(c))], s=300, c=c, marker='^')                                <br \/>            count = list(region_colors_dict.keys())<br \/>            #print(count)<br \/>            for j in range(len(c)):<br \/>                axs[1].annotate(count[j],  (1.0001, j*5))<br \/><br \/>            axs[1].set_xlabel('Country and Colors')<br \/>            axs[1].set_ylabel('')<br \/><br \/>            axs[1].set_xticks([])<br \/>            axs[1].set_yticks([])<br \/>            <br \/>            <br \/>        <br \/>        <br \/>                <br \/>        if chart_type == 'Line': <br \/>            # best to use only for one year<br \/>            <br \/>            <br \/>            <br \/>            axs[0].plot(indicator_data['Value'], indicator_data['Region']) #, c=c                 <br \/>            axs[0].set_xticklabels(indicator_data['Value'], rotation=90) # can be turned off                        <br \/>            # https:\/\/stackoverflow.com\/questions\/10998621\/rotate-axis-text-in-python-matplotlib<br \/>            plt.suptitle(indicator + ' For a Year')<br \/>            axs[0].set_xlabel('Values')<br \/>            axs[0].set_ylabel('Countries\/Regions')<br \/>            <br \/>            fig.savefig('.\/saved_images_from_visualizations\/' + 'line_' +indicator.replace(' ', '_')[0:10] + '_' + str(np.random.randint(0, 99999)) + '.png')<br \/>            <br \/>            plt.show()<br \/>            <br \/>            fig, axs = plt.subplots(1, 2, figsize=fig_size, sharey=False, gridspec_kw = {'width_ratios':ratios})<br \/>            axs[0].plot(indicator_data['Region'], indicator_data['Value']) #, c=c                <br \/>            axs[0].set_xticklabels(indicator_data['Region'], rotation=90) # can be turned off <br \/>            <br \/>            plt.suptitle(indicator + ' Over a Year')<br \/>            axs[0].set_xlabel('Regions\/Countries')<br \/>            axs[0].set_ylabel('Values')<br \/>        <br \/>            #fig.savefig('.\/saved_images_from_visualizations\/cancer_mortality_2017_country_region_x.png')<br \/>            fig.savefig('.\/saved_images_from_visualizations\/' + 'line_' + indicator.replace(' ', '_')[0:12] + '_' + str(np.random.randint(0, 99999)) + '.png')<br \/>            <br \/>            plt.show()<br \/>            <br \/>            <br \/>        elif chart_type == 'Bar':<br \/>            #fig, axs = plt.subplots(1, 2, figsize=(10, 8), sharey=False, gridspec_kw = {'width_ratios':ratios})<br \/>            axs[0].bar(indicator_data['Region'], indicator_data['Value']) #, c=c                <br \/>            axs[0].set_xticklabels(indicator_data['Region'], rotation=90) # can be turned off <br \/>            <br \/>            plt.suptitle(indicator + ' Over a Year')<br \/>            axs[0].set_xlabel('Regions\/Countries')<br \/>            axs[0].set_ylabel('Values')<br \/>        <br \/>            #fig.savefig('.\/saved_images_from_visualizations\/cancer_mortality_2017_country_region_x.png')<br \/>            fig.savefig('.\/saved_images_from_visualizations\/' + 'bar_' + indicator.replace(' ', '_')[0:12] + '_' + str(np.random.randint(0, 99999)) + '.png')<br \/>            <br \/>            plt.show()<br \/>            <br \/>        elif chart_type == 'Hor Bar':<br \/>            #fig, axs = plt.subplots(1, 2, figsize=(10, 8), sharey=False, gridspec_kw = {'width_ratios':ratios})<br \/>            axs[0].barh(indicator_data['Region'], indicator_data['Value']) #, c=c                <br \/>            #axs[0].set_xticklabels(indicator_data['Region'], rotation=90) # can be turned off <br \/>            <br \/>            plt.suptitle(indicator + ' Over a Year')<br \/>            axs[0].set_xlabel('Values')<br \/>            axs[0].set_ylabel('Regions\/Countries')<br \/>        <br \/>            #fig.savefig('.\/saved_images_from_visualizations\/cancer_mortality_2017_country_region_x.png')<br \/>            fig.savefig('.\/saved_images_from_visualizations\/' + 'hor_bar' + indicator.replace(' ', '_')[0:12] + '_' + str(np.random.randint(0, 99999)) + '.png')<br \/>            <br \/>            plt.show()<br \/>            <br \/>        elif chart_type == 'Pie':<br \/>            #ax.scatter(indicator_data['Region'], indicator_data['Value'],  s=indicator_data['Value'] * bubble_scale )<br \/>            #plt.barh(indicator_data['Region'], indicator_data['Value'])                <br \/>            #ax.pie(indicator_data['Value'], labels=indicator_data['Data year'], autopct=\"%1.1f%%\")<br \/>            <br \/>            <br \/>            axs[0].pie(indicator_data['Value'], labels=indicator_data['Region']) #, c=c                 <br \/>            axs[0].set_xticklabels(indicator_data['Value'], rotation=90) # can be turned off                        <br \/>            # https:\/\/stackoverflow.com\/questions\/10998621\/rotate-axis-text-in-python-matplotlib<br \/>            plt.suptitle(indicator + ' For a Year')<br \/>            axs[0].set_xlabel('Values')<br \/>            axs[0].set_ylabel('Countries\/Regions')<br \/>            <br \/>            <br \/>            <br \/>            fig.savefig('.\/saved_images_from_visualizations\/' + 'pie_' + indicator.replace(' ', '_')[0:10] + '_' + str(np.random.randint(0, 99999)) + '.png')<br \/>            <br \/>            plt.show()<br \/>            <br \/>        else:<br \/>            <br \/>            #print(indicator_data)<br \/>            # for country color codes<br \/>            if (provincial_only == False):<br \/>                c =  [ region_colors_dict[x]  for x in indicator_data['Region'] ]    <br \/>                m =  [ x  for x in indicator_data['Region'] ]  <br \/>                <br \/>            else:<br \/>                #province_colors_dict<br \/>                c =  [ province_colors_dict[x]  for x in indicator_data['Region'] ]    <br \/>                m =  [ x  for x in indicator_data['Region'] ] <br \/>                #c_code =  [ x[0:3]  for x in indicator_data['Region'] ] <br \/>                region_colors_dict = province_colors_dict<br \/>            <br \/><br \/>            #ax.scatter(indicator_data['Data year'], indicator_data['Region'], s=indicator_data['Value'] * bubble_scale, c=c )<br \/>            axs[0].scatter(indicator_data['Region'], indicator_data['Value'], s=indicator_data['Value'] * bubble_scale, c=c )<br \/>            #axs[0].set_xticks([year])<br \/>            #axs[0].set_yticks(indicator_data['Value'])<br \/><br \/>            plt.suptitle(indicator + ' Over a Year ' + str(year) )<br \/>            axs[0].set_xlabel('Regions')<br \/>            axs[0].set_ylabel('Values')<br \/>            axs[0].set_xticklabels(indicator_data['Region'], rotation=90) # can be turned off                        <br \/>            <br \/>            <br \/>            axs[1].scatter([1]*len(c), [i*5 for i in range(len(c))], s=300, c=c, marker='^')                                <br \/>            count = list(region_colors_dict.keys())<br \/>            #print(count)<br \/>            for j in range(len(c)):<br \/>                axs[1].annotate(count[j],  (1.0001, j*5))<br \/><br \/>            axs[1].set_xlabel('Country and Colors')<br \/>            axs[1].set_ylabel('')<br \/><br \/>            axs[1].set_xticks([])<br \/>            axs[1].set_yticks([])<br \/>            <br \/>            fig.savefig('.\/saved_images_from_visualizations\/' + 'bubble_' + indicator.replace(' ', '_')[0:10] + '_' + str(np.random.randint(0, 99999)) + '.png')<br \/>            <br \/>                    <br \/>        #plt.show()        <br \/>    else:<br \/>        # for multiple years<br \/>        # though this method is primarily to use for one year, unless in some specific cases<br \/>        \"\"\"<br \/>        plt.ion()    <br \/>        f = plt.figure()<br \/>        #ax = f.gca()<br \/><br \/>        #top box<br \/>        f.show()<br \/>        \"\"\"<br \/>        <br \/>        <br \/>        <br \/>        # redundend code to address a last minute bug<br \/>        # countries unique color code<br \/>        all_regions = measure_data['Region'].unique()<br \/>        region_colors = []<br \/>        region_colors_dict = {}<br \/>        import random<br \/>        random.seed(0)<br \/>        for aRegion in all_regions:<br \/>            region_colors_dict[aRegion] = np.random.randint(0, 255)<br \/><br \/>        #list(region_colors_dict.keys())[:5], list(region_colors_dict.values())[:5]<br \/><br \/><br \/>            <br \/>            <br \/>        #print(all_years)<br \/>        for aYear in all_years:<br \/>            if aYear == 0:<br \/>                continue<br \/>                <br \/>            if aYear == 'Not applicable':<br \/>                continue<br \/>                <br \/>            # older : original # <br \/>            #indicator_data = measure_data.loc[  (measure_data['Indicator'] == indicator)  &amp; (measure_data['Data year'] == aYear) ]<br \/>            <br \/>            \"\"\"<br \/>            indicator_data = measure_data.loc[  (measure_data['Indicator'] == indicator)  &amp; ( (measure_data['Data year'] == aYear) &amp; (measure_data['Type of region'].isin(['Country', 'Canada']) ) )   | \\<br \/>                                         ( (measure_data['Indicator'] == indicator) &amp; (measure_data['Region'] == 'OECD average')) ]<br \/>            <br \/>            \"\"\"<br \/>            <br \/>            indicator_data = measure_data.loc[  (measure_data['Indicator'] == indicator)  &amp;  (measure_data['Data year'] == aYear) &amp; (measure_data['Type of region'].isin(['Country', 'Canada']) )  ]<br \/>            if (provincial_only == True):<br \/>                indicator_data = measure_data.loc[  (measure_data['Indicator'] == indicator)  &amp; \\<br \/>                                              (measure_data['Data year'] == aYear) &amp; (measure_data['Type of region'].isin(['Province']))]<br \/>                <br \/>            #print(indicator_data)<br \/>        <br \/>        <br \/>             #print(indicator_data)<br \/>            # for country color codes<br \/>            #print(region_colors_dict)<br \/>            if (provincial_only == False):<br \/>                c =  [ region_colors_dict[x]  for x in indicator_data['Region'] ]    <br \/>                m =  [ x  for x in indicator_data['Region'] ]  <br \/>                <br \/>            else:<br \/>                #province_colors_dict<br \/>                c =  [ province_colors_dict[x]  for x in indicator_data['Region'] ]    <br \/>                m =  [ x  for x in indicator_data['Region'] ] <br \/>                #c_code =  [ x[0:3]  for x in indicator_data['Region'] ] <br \/>                region_colors_dict = province_colors_dict<br \/>                <br \/>                <br \/>        <br \/>            #c =  [ region_colors_dict[x]  for x in indicator_data['Region'] ]    <br \/>            #m =  [ x  for x in indicator_data['Region'] ] <br \/>            <br \/>            #print( list(zip(m,c)))<br \/>            <br \/>            if chart_type == 'Line':                <br \/>                # plt.plot(indicator_data['Data year'], indicator_data['Value'], c=c)<br \/>                # plt.xticks(indicator_data['Value'])<br \/>                <br \/>                <br \/>                # was here axs[0].plot(indicator_data['Data year'], indicator_data['Value']) #, c=c           <br \/>                # was here axs[0].set_xticks(indicator_data['Value'])<br \/>                <br \/>                # brought from one year<br \/>                # best to use only for one year<br \/>                #plt.plot(indicator_data['Data year'], indicator_data['Value'], c=c)            <br \/>                #plt.xticks(indicator_data['Value'])<br \/><br \/>                #axs[0].plot(indicator_data['Data year'], indicator_data['Value']) #, c=c                       <br \/>                axs[0].plot(indicator_data['Data year'], indicator_data['Value']) #, c=c     <br \/>                #axs[0].plot(165, 'OECD', color='Red')<br \/>                #axs[0].set_xticklabels(indicator_data['Data year'], rotation=90) # can be turned off                        <br \/>                # https:\/\/stackoverflow.com\/questions\/10998621\/rotate-axis-text-in-python-matplotlib<br \/>                #plt.suptitle(indicator + ' For a Year')<br \/>                #axs[0].set_xlabel('Years')<br \/>                #axs[0].set_ylabel('Values')<br \/><br \/>                fig.savefig('.\/saved_images_from_visualizations\/cancer_mortality_years_country.png')<br \/><br \/>                #plt.show()<br \/><br \/>                \"\"\"<br \/>                fig, axs = plt.subplots(1, 2, figsize=(10, 8), sharey=False, gridspec_kw = {'width_ratios':ratios})<br \/>                axs[0].plot(indicator_data['Region'], indicator_data['Value']) #, c=c                <br \/>                axs[0].set_xticklabels(indicator_data['Region'], rotation=90) # can be turned off <br \/><br \/>                plt.suptitle(indicator + ' Over a Year')<br \/>                axs[0].set_xlabel('Regions\/Countries')<br \/>                axs[0].set_ylabel('Values')<br \/><br \/>                fig.savefig('.\/saved_images_from_visualizations\/cancer_mortality_2017_country_region_x.png')<br \/><br \/>                plt.show()  <br \/>                \"\"\"<br \/>                <br \/>                # end of brought from one year<br \/>                <br \/>                #f.canvas.draw()<br \/>                <br \/><br \/>                <br \/>            <br \/>                <br \/>            elif chart_type == 'Bar':<br \/>                #ax.scatter(indicator_data['Region'], indicator_data['Value'],  s=indicator_data['Value'] * bubble_scale )<br \/>                plt.bar(indicator_data['Data year'], indicator_data['Value'])<br \/>            elif chart_type == 'Hor Bar':<br \/>                #ax.scatter(indicator_data['Region'], indicator_data['Value'],  s=indicator_data['Value'] * bubble_scale )<br \/>                plt.barh(indicator_data['Region'], indicator_data['Value'])<br \/>            elif chart_type == 'Pie':<br \/>                #ax.scatter(indicator_data['Region'], indicator_data['Value'],  s=indicator_data['Value'] * bubble_scale )<br \/>                #plt.barh(indicator_data['Region'], indicator_data['Value'])                <br \/>                ax.pie(indicator_data['Value'], labels=indicator_data['Data year'], autopct=\"%1.1f%%\")<br \/>            else:<br \/>                indicator_data['Value'] = indicator_data['Value'].div(benchmark_value)<br \/>                <br \/>                # for country color codes<br \/>                c =  [ region_colors_dict[x]  for x in indicator_data['Region'] ]    <br \/>                m =  [ x  for x in indicator_data['Region'] ] <br \/>        <br \/>        <br \/>                axs[0].scatter(indicator_data['Data year'], indicator_data['Value'], s = indicator_data['Value'] * bubble_scale, c=c)<br \/>                <br \/>                plt.suptitle(indicator + ' Over Years \\n Values are in multiples of Benchmark (' + str(benchmark_value) + ')' )<br \/>                axs[0].set_xlabel('Years')<br \/>                axs[0].set_ylabel('Values\/Becnhmark Value(' + str(benchmark_value) +')' )<br \/>        <br \/>                fig.savefig('.\/saved_images_from_visualizations\/transport_mortality_over_years.png')<br \/>            <br \/>                #plt.show()<br \/>            <br \/>            <br \/>                # show country colors<br \/>                axs[1].scatter([1]*len(c), [i*5 for i in range(len(c))], s=300, c=c, marker='o')<br \/>                <br \/>                count = list(m) #list(region_colors_dict.keys())<br \/>                #print(count)<br \/>                for j in range(len(c)):<br \/>                    axs[1].annotate(count[j],  (1, j*5))<br \/>                    <br \/>                axs[1].set_xlabel('Country and Colors')<br \/>                axs[1].set_ylabel('')<br \/><br \/>                axs[1].set_xticks([])<br \/>                axs[1].set_yticks([])<br \/>                <br \/>            if (animate):<br \/>                plt.pause(0.01)<br \/>            #f.canvas.draw()<br \/>    <br \/>    #plt.show()<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"8fe4\">Plot over a region for different countries<\/h1>\n\n\n\n<p id=\"b42e\">Some of the plots as can be generated from this method can also be generated using the method above. The use of this method will be mostly averaging over years. However, in the dataset, data for all years might not be available; hence, to make the visualization, the years selected need to make sense consideringreal-world Ideally, I could give options to select multiple years individually and show info to the users what data are there and what are appropriate (I am considering that out of scope for now)<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">plt.rcParams['figure.figsize'] = [10, 10]<br \/>def plot_measure_by_regions(year, indicator, bubble_scale, chart_type = '', ratios=[3,1], provincial_only=False, all_years=all_years):    <br \/>    #print('year, indicator', year, indicator)    <br \/>    plt.ion()    <br \/>    # now f = plt.figure()<br \/>    # now ax = f.gca()<br \/>    #plt.xticks([])<br \/>    # now f.show()<br \/>    <br \/>    # indicator_data = measure_data.loc[  (measure_data['Indicator'] == indicators[0] ) ]<br \/>    # (20, 10)<br \/>    fig, axs = plt.subplots(1, 2, figsize=(20, 10), sharey=False, gridspec_kw = {'width_ratios':ratios})<br \/>    #plt.xticks(rotation=90)<br \/>    <br \/>    if ( year &gt; 1 ):<br \/>        #indicator_data = indicator_data [ indicator_data['Data year'] == year]<br \/>        indicator_data = measure_data.loc[  (measure_data['Indicator'] == indicator)  &amp; (measure_data['Data year'] == year) ]<br \/>        <br \/>        # for country color codes<br \/>        c =  [ region_colors_dict[x]  for x in indicator_data['Region'] ]    <br \/>        m =  [ x  for x in indicator_data['Region'] ] <br \/>        c_code =  [ x[0:3]  for x in indicator_data['Region'] ]  <br \/>    <br \/>    <br \/>        #print(indicator_data)<br \/>        if chart_type == 'Line':<br \/>            #ax.scatter(indicator_data['Region'], indicator_data['Value'],  s=indicator_data['Value'] * bubble_scale )<br \/>            #plt.plot(indicator_data['Region'], indicator_data['Value'])<br \/>            <br \/>            <br \/>            axs[0].plot(indicator_data['Region'], indicator_data['Value']) #,  s=indicator_data['Value'] * bubble_scale, c=c )<br \/>            plt.suptitle(indicator + ' Over Regions')<br \/>            axs[0].set_xlabel('Regions and Countries')<br \/>            axs[0].set_ylabel('Values')<br \/>            axs[0].set_xticklabels(indicator_data['Region'], rotation=90) # can be turned off    <br \/>            <br \/>            fig.savefig('.\/saved_images_from_visualizations\/' + 'line_' + indicator.replace(' ', '_')[0:10] + '_' + str(np.random.randint(0, 99999)) + '.png')<br \/>            <br \/>            <br \/>        elif chart_type == 'Bar':<br \/>            #ax.scatter(indicator_data['Region'], indicator_data['Value'],  s=indicator_data['Value'] * bubble_scale )<br \/>            #plt.bar(indicator_data['Region'], indicator_data['Value'])<br \/>            <br \/>            indicator_data = indicator_data.sort_values(by=['Value'])<br \/>            axs[0].bar(indicator_data['Region'], indicator_data['Value']) #,  s=indicator_data['Value'] * bubble_scale, c=c )<br \/>            plt.suptitle(indicator + ' Over Regions')<br \/>            axs[0].set_xlabel('Regions and Countries')<br \/>            axs[0].set_ylabel('Values')<br \/>            axs[0].set_xticklabels(indicator_data['Region'], rotation=90) # can be turned off    <br \/>            <br \/>            fig.savefig('.\/saved_images_from_visualizations\/' + 'bar_' + indicator.replace(' ', '_')[0:10] + '_' + str(np.random.randint(0, 99999)) + '.png')<br \/>            <br \/>            <br \/>        elif chart_type == 'Hor Bar':<br \/>                #ax.scatter(indicator_data['Region'], indicator_data['Value'],  s=indicator_data['Value'] * bubble_scale )<br \/>                #plt.barh(indicator_data['Region'], indicator_data['Value'])<br \/>                <br \/>                indicator_data = indicator_data.sort_values(by=['Value'])<br \/>                axs[0].barh(indicator_data['Region'], indicator_data['Value']) #,  s=indicator_data['Value'] * bubble_scale, c=c )<br \/>                plt.suptitle(indicator + ' Over Regions')<br \/>                axs[0].set_xlabel('Regions and Countries')<br \/>                axs[0].set_ylabel('Values')<br \/>                #axs[0].set_xticklabels(indicator_data['Region'], rotation=90) # can be turned off    <br \/>            <br \/>                fig.savefig('.\/saved_images_from_visualizations\/' + 'hor_bar_' + indicator.replace(' ', '_')[0:10] + '_' + str(np.random.randint(0, 99999)) + '.png')<br \/>            <br \/>        elif chart_type == 'Pie':<br \/>                #ax.scatter(indicator_data['Region'], indicator_data['Value'],  s=indicator_data['Value'] * bubble_scale )<br \/>                #plt.barh(indicator_data['Region'], indicator_data['Value'])                <br \/>                #ax.pie(indicator_data['Value'], labels=indicator_data['Region'], autopct=\"%1.1f%%\")<br \/>                <br \/>                <br \/>                axs[0].pie(indicator_data['Value'], labels = indicator_data['Region'], ) #,  s=indicator_data['Value'] * bubble_scale, c=c )<br \/>                plt.suptitle(indicator + ' Over Regions')<br \/>                axs[0].set_xlabel('Regions and Countries')<br \/>                axs[0].set_ylabel('Values')<br \/>                axs[0].set_xticklabels(indicator_data['Region'], rotation=90) # can be turned off    <br \/><br \/>                fig.savefig('.\/saved_images_from_visualizations\/' + 'pie_' + indicator.replace(' ', '_')[0:10] + '_' + str(np.random.randint(0, 99999)) + '.png')<br \/>            <br \/>        else:<br \/>            axs[0].scatter(indicator_data['Region'], indicator_data['Value'],  s=indicator_data['Value'] * bubble_scale, c=c )<br \/>            plt.suptitle(indicator + ' Over Regions')<br \/>            axs[0].set_xlabel('Regions and Countries')<br \/>            axs[0].set_ylabel('Values')<br \/>            axs[0].set_xticklabels(indicator_data['Region'], rotation=90) # can be turned off    <br \/>                                    <br \/>            <br \/>            <br \/>            # plt.show()<br \/>            # show country colors<br \/>            axs[1].scatter([1]*len(c), [i*5 for i in range(len(c))], s=300, c=c, marker='o')<br \/><br \/>            count = list(m) #list(region_colors_dict.keys())<br \/>            #print(count)<br \/>            for j in range(len(c)):<br \/>                axs[1].annotate(count[j],  (1, j*5))<br \/><br \/>            axs[1].set_xlabel('Country and Colors')<br \/>            axs[1].set_ylabel('')<br \/><br \/>            axs[1].set_xticks([])<br \/>            axs[1].set_yticks([])<br \/>            <br \/>            fig.savefig('.\/saved_images_from_visualizations\/' + 'bubble_' + indicator.replace(' ', '_')[0:10] + '_' + str(np.random.randint(0, 99999)) + '.png')<br \/>            <br \/>            <br \/>            <br \/>        # now plt.show()<br \/>    <br \/>    # multiple year selected<br \/>    else:        <br \/>        #indicator_data = measure_data.loc[  (measure_data['Indicator'] == indicator)  &amp;  (measure_data['Data year'] == aYear) &amp; (measure_data['Type of region'].isin(['Country', 'Canada']) )  ]<br \/>        indicator_data = measure_data.loc[  (measure_data['Indicator'] == indicator) &amp; (measure_data['Type of region'].isin(['Country', 'Canada']) )  ]<br \/>        if (provincial_only == True):<br \/>            indicator_data = measure_data.loc[  (measure_data['Indicator'] == indicator)  &amp; \\<br \/>                                          (measure_data['Data year'] == aYear) &amp; (measure_data['Type of region'].isin(['Province']))]<br \/><br \/><br \/>        # for country color codes<br \/>        c =  [ region_colors_dict[x]  for x in indicator_data['Region'] ]    <br \/>        m =  [ x  for x in indicator_data['Region'] ] <br \/>        c_code =  [ x[0:3]  for x in indicator_data['Region'] ] <br \/>        <br \/>        indicator_data = indicator_data.set_index(['Region'])<br \/>       <br \/>        <br \/>        x = indicator_data.groupby(['Region']).mean()<br \/>            <br \/>       <br \/>        <br \/>        #print(x.index, x['Value'])<br \/>            <br \/>            <br \/>        ### for aYear in all_years:<br \/>        # now indicator_data = measure_data.loc[  (measure_data['Indicator'] == indicator)  &amp; (measure_data['Data year'] == aYear) ]<br \/><br \/>        \"\"\"<br \/>        indicator_data = measure_data.loc[  (measure_data['Indicator'] == indicator)  &amp;  (measure_data['Data year'] == aYear) &amp; (measure_data['Type of region'].isin(['Country', 'Canada']) )  ]<br \/>        if (provincial_only == True):<br \/>            indicator_data = measure_data.loc[  (measure_data['Indicator'] == indicator)  &amp; \\<br \/>                                          (measure_data['Data year'] == aYear) &amp; (measure_data['Type of region'].isin(['Province']))]<br \/><br \/><br \/>        indicator_data = indicator_data.set_index(['Region'])<br \/>        indicator_data['mean'] = indicator_data.groupby(['Region']).mean()<br \/>        print(indicator_data)<br \/>        \"\"\"<br \/><br \/>        <br \/><br \/>        if chart_type == 'Line':<br \/>            <br \/>            axs[0].plot(x.index, x['Value']) #,  s = x['Value'] * bubble_scale, c=c )<br \/>            <br \/>            # though I am repeating this block of code - this can be just placed at the end of the else block<br \/>            # just trying to save on debug time            <br \/>            plt.suptitle(indicator + ' Over Regions')<br \/>            axs[0].set_xlabel('Regions and Countries')<br \/>            axs[0].set_ylabel('Values')            <br \/>            axs[0].set_xticklabels(x.index, rotation=90) # can be turned off   <br \/>            <br \/>            fig.savefig('.\/saved_images_from_visualizations\/' + 'line_' + indicator.replace(' ', '_')[0:10] + '_' + str(np.random.randint(0, 99999)) + '.png')<br \/>            <br \/><br \/><br \/>        elif chart_type == 'Bar':<br \/>            #ax.scatter(indicator_data['Region'], indicator_data['Value'],  s=indicator_data['Value'] * bubble_scale )<br \/>            # now plt.bar(indicator_data['Region'], indicator_data['Value'])<br \/>            <br \/>            <br \/>            x = x.sort_values(by=['Value'])            <br \/>            axs[0].bar(x.index, x['Value']) #,  s = x['Value'] * bubble_scale, c=c )<br \/>            <br \/>            # though I am repeating this block of code - this can be just placed at the end of the else block<br \/>            # just trying to save on debug time            <br \/>            plt.suptitle(indicator + ' Over Regions')<br \/>            axs[0].set_xlabel('Regions and Countries')<br \/>            axs[0].set_ylabel('Values')            <br \/>            axs[0].set_xticklabels(x.index, rotation=90) # can be turned off   <br \/>            <br \/>            fig.savefig('.\/saved_images_from_visualizations\/' + 'bar_' + indicator.replace(' ', '_')[0:10] + '_' + str(np.random.randint(0, 99999)) + '.png')<br \/>            <br \/>                                    <br \/>        elif chart_type == 'Hor Bar':<br \/>            #ax.scatter(indicator_data['Region'], indicator_data['Value'],  s=indicator_data['Value'] * bubble_scale )<br \/>            #plt.barh(indicator_data['Region'], indicator_data['Value'])<br \/>            <br \/>            x = x.sort_values(by=['Value'])            <br \/>            axs[0].barh(x.index, x['Value']) #,  s = x['Value'] * bubble_scale, c=c )<br \/>            <br \/>            # though I am repeating this block of code - this can be just placed at the end of the else block<br \/>            # just trying to save on debug time            <br \/>            plt.suptitle(indicator + ' Over Regions')<br \/>            #axs[0].set_xlabel('Regions and Countries')<br \/>            axs[0].set_xlabel('Values')<br \/>            axs[0].set_ylabel('Regions and Countries')            <br \/>            #axs[0].set_xticklabels(x.index, rotation=90) # can be turned off <br \/>            fig.savefig('.\/saved_images_from_visualizations\/' + 'hor_bar_' + indicator.replace(' ', '_')[0:10] + '_' + str(np.random.randint(0, 99999)) + '.png')<br \/>            <br \/>            <br \/>        elif chart_type == 'Pie':<br \/>            #ax.scatter(indicator_data['Region'], indicator_data['Value'],  s=indicator_data['Value'] * bubble_scale )<br \/>            #plt.barh(indicator_data['Region'], indicator_data['Value'])                <br \/>            # now ax.pie(indicator_data['Value'], labels=indicator_data['Region'], autopct=\"%1.1f%%\")<br \/>            <br \/>            <br \/>            <br \/>            <br \/>            axs[0].pie(x['Value'], labels=x.index) #, c=c                 <br \/>            axs[0].set_xticklabels(x['Value'], rotation=90) # can be turned off                        <br \/>            # https:\/\/stackoverflow.com\/questions\/10998621\/rotate-axis-text-in-python-matplotlib<br \/>            plt.suptitle(indicator + ' Over Regions')<br \/>            #axs[0].set_xlabel('Values')<br \/>            axs[0].set_ylabel('Countries\/Regions')<br \/>            <br \/>            fig.savefig('.\/saved_images_from_visualizations\/' + 'pie_' + indicator.replace(' ', '_')[0:10] + '_' + str(np.random.randint(0, 99999)) + '.png')<br \/>            <br \/>            plt.show()<br \/>            <br \/>            <br \/><br \/>        else:<br \/>            #axs[0].scatter(indicator_data['Region'], indicator_data['Value'],  s = indicator_data['Value'] * bubble_scale, c=c )<br \/>            axs[0].scatter(x.index, x['Value'],  s = x['Value'] * bubble_scale, c=c )<br \/>            <br \/>            plt.suptitle(indicator + ' Over Regions')<br \/>            axs[0].set_xlabel('Regions and Countries')<br \/>            axs[0].set_ylabel('Values')<br \/>            #axs[0].set_xticklabels(indicator_data['Region'], rotation=90) # can be turned off    <br \/>            axs[0].set_xticklabels(x.index, rotation=90) # can be turned off    <br \/><br \/>            #plt.show()<br \/>            # show country colors<br \/>            axs[1].scatter([1]*len(c), [i*5 for i in range(len(c))], s=300, c=c, marker='o')<br \/><br \/>            count = list(m) #list(region_colors_dict.keys())<br \/>            #print(count)<br \/>            for j in range(len(c)):<br \/>                axs[1].annotate(count[j],  (1, j*5))<br \/><br \/>            axs[1].set_xlabel('Country and Colors')<br \/>            axs[1].set_ylabel('')<br \/><br \/>            axs[1].set_xticks([])<br \/>            axs[1].set_yticks([])<br \/><br \/>            fig.savefig('.\/saved_images_from_visualizations\/' + 'bubble_' + indicator.replace(' ', '_')[0:10] + '_' + str(np.random.randint(0, 99999)) + '.png')<br \/>                <br \/>            #now f.canvas.draw()<br \/>            <br \/>    #plt.suptitle(indicator + 'Over Regions and Years')<br \/>    #plt.xlabel('Regions and Countries')<br \/>    #plt.ylabel('Values')<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"af6f\">Geo Plot, Map Plot on a World Map<\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\">\"\"\"<br \/>magnitudes = measure_data[['Region', 'Value']]<br \/>magnitudes['Region'][1]<br \/><br \/>year = 2015<br \/>indicator_data = measure_data.loc[  (measure_data['Indicator'] == indicators[0])  &amp; (measure_data['Data year'] == 2015) ]          <br \/>#print(indicator_data)<br \/>magnitudes = indicator_data[['Region', 'Value', 'Data year']]<br \/><br \/>for r, v in zip(magnitudes['Region'], magnitudes['Value']):<br \/>    print(r, v)<br \/>\"\"\"\"\\nmagnitudes = measure_data[['Region', 'Value']]\\nmagnitudes['Region'][1]\\n\\nyear = 2015\\nindicator_data = measure_data.loc[  (measure_data['Indicator'] == indicators[0])  &amp; (measure_data['Data year'] == 2015) ]          \\n#print(indicator_data)\\nmagnitudes = indicator_data[['Region', 'Value', 'Data year']]\\n\\nfor r, v in zip(magnitudes['Region'], magnitudes['Value']):\\n    print(r, v)\\n\"def plot_map_measure_by_regions(year, indicator, bubble_scale, chart_type = '', provincial_only=False, all_years=all_years):    <br \/>    #print('year, indicator', year, indicator)    <br \/>               <br \/>    if ( year &gt; 1 ):<br \/>        <br \/>        indicator_data = measure_data.loc[  (measure_data['Indicator'] == indicator)  &amp; (measure_data['Data year'] == year) ]          <br \/>        #print(indicator_data)<br \/>        magnitudes = indicator_data[['Region', 'Value']]<br \/>        <br \/>        <br \/>        # Make this plot larger.<br \/>        plt.figure(figsize=(16,12))<br \/><br \/><br \/>        eq_map = Basemap(projection='robin', resolution = 'l', area_thresh = 1000.0,<br \/>                      lat_0=0, lon_0=-130)<br \/>        eq_map.drawcoastlines()<br \/>        eq_map.drawcountries()<br \/>        eq_map.fillcontinents(color = 'gray')<br \/>        eq_map.drawmapboundary()<br \/>        eq_map.drawmeridians(np.arange(0, 360, 30))<br \/>        eq_map.drawparallels(np.arange(-90, 90, 30))<br \/><br \/>        min_marker_size = 2.5 #* bubble_scale<br \/>        #for lon, lat, mag in zip(lons, lats, magnitudes):<br \/>        #for i in range(indicator_data.shape[0]):<br \/>        for reg, val in zip(magnitudes['Region'], magnitudes['Value']):<br \/>            #try:<br \/>            #reg = magnitudes[i:i+1]['Region']    <br \/>            #reg = magnitudes['Region'][i]<br \/>            #print(reg)<br \/>            lat = lats_dict[reg]<br \/>            lon = lons_dict[reg]   <br \/><br \/>            #print(lat, lon)<br \/>            x, y = eq_map(lon, lat)<br \/>            mag = val #magnitudes['Value'][i] #magnitudes[i:i+1]['Value']    <br \/>            #print(mag)<br \/>            msize = mag * min_marker_size\/bubble_scale<br \/>            #print(msize, msize)<br \/>            #marker_string = get_marker_color(mag)<br \/>            #eq_map.plot(x, y, marker_string, markersize=msize)<br \/>            eq_map.plot(x, y,  marker='o', markersize=msize)<br \/>            <br \/>            #x, y = eq_map(0, 0)<br \/>            #eq_map.plot(x, y, marker='D',color='m')<br \/><br \/>            #plt.show()<br \/><br \/>            #except:<br \/>                #print('hello')<br \/>                #continue<br \/><br \/>        title_string = indicator<br \/>        title_string += ' for year ' + str(year)<br \/>        plt.title(title_string)<br \/>        #plt.show()<br \/>        <br \/>        plt.savefig('.\/saved_images_from_visualizations\/' + 'geo_plot_for_a_year_' +indicator.replace(' ', '_')[0:5] + '_' + str(np.random.randint(0, 99999)) + '.png')<br \/>        plt.show()<br \/>        <br \/>        <br \/>        #plt.suptitle(indicator + 'Over Regions and Years')<br \/>        #plt.xlabel('Regions and Countries')<br \/>        #plt.ylabel('Values')<br \/>        #plt.show()<br \/>        <br \/>    else:<br \/>        # this is to plot over multiple years<br \/>        # average taken over multiple years will be plotted<br \/>        # I could make this more user friendly and data friendly <br \/>        # by giving users the option to select years, countries; also by informing to what extent data are available (skipping as that will extend the work much)<br \/>        <br \/>        #indicator_data = measure_data.loc[  (measure_data['Indicator'] == indicator)  &amp;  (measure_data['Data year'] == aYear) &amp; (measure_data['Type of region'].isin(['Country', 'Canada']) )  ]<br \/>        indicator_data = measure_data.loc[  (measure_data['Indicator'] == indicator) &amp; (measure_data['Type of region'].isin(['Country', 'Canada']) )  ]<br \/>        if (provincial_only == True):<br \/>            indicator_data = measure_data.loc[  (measure_data['Indicator'] == indicator)  &amp; \\<br \/>                                          (measure_data['Data year'] == aYear) &amp; (measure_data['Type of region'].isin(['Province']))]<br \/><br \/>        #print(indicator_data)<br \/>        # for country color codes<br \/>        \"\"\"<br \/>        c =  [ region_colors_dict[x]  for x in indicator_data['Region'] ]    <br \/>        m =  [ x  for x in indicator_data['Region'] ] <br \/>        c_code =  [ x[0:3]  for x in indicator_data['Region'] ] <br \/>        \"\"\"<br \/>        <br \/>        indicator_data = indicator_data.set_index(['Region'])<br \/>        x = indicator_data.groupby(['Region']).mean()<br \/>        <br \/>        #print(x)<br \/>        #print(x['Value'][0])<br \/>        <br \/>        <br \/>        <br \/>        #print(indicator_data)<br \/>        # not used<br \/>        magnitudes = pd.DataFrame()<br \/>        magnitudes['Region'] = x.index<br \/>        magnitudes['Value'] = x['Value']<br \/>        <br \/>        #print(magnitudes)<br \/>        <br \/>        # Make this plot larger.<br \/>        plt.figure(figsize=(16,12))<br \/><br \/><br \/>        eq_map = Basemap(projection='robin', resolution = 'l', area_thresh = 1000.0,<br \/>                      lat_0=0, lon_0=-130)<br \/>        eq_map.drawcoastlines()<br \/>        eq_map.drawcountries()<br \/>        eq_map.fillcontinents(color = 'gray')<br \/>        eq_map.drawmapboundary()<br \/>        eq_map.drawmeridians(np.arange(0, 360, 30))<br \/>        eq_map.drawparallels(np.arange(-90, 90, 30))<br \/><br \/>        min_marker_size = 2.5 #* bubble_scale<br \/>        #for lon, lat, mag in zip(lons, lats, magnitudes):<br \/>        #for i in range(indicator_data.shape[0]):<br \/>        #for reg, val in zip(magnitudes['Region'], magnitudes['Value']):<br \/>        for reg, val in zip(x.index, x['Value']):<br \/>            try:<br \/>                #reg = magnitudes[i:i+1]['Region']    <br \/>                #reg = magnitudes['Region'][i]<br \/>                #print(reg, val)<br \/>                lat = lats_dict[reg]<br \/>                lon = lons_dict[reg]   <br \/><br \/>                #print(lat, lon)<br \/>                x, y = eq_map(lon, lat)<br \/>                mag = val #magnitudes['Value'][i] #magnitudes[i:i+1]['Value']    <br \/>                #print(mag)<br \/>                msize = mag * min_marker_size\/bubble_scale<br \/>                #print(msize, msize)<br \/>                #marker_string = get_marker_color(mag)<br \/>                #eq_map.plot(x, y, marker_string, markersize=msize)<br \/>                eq_map.plot(x, y,  marker='o', markersize=msize)<br \/><br \/>                #x, y = eq_map(0, 0)<br \/>                #eq_map.plot(x, y, marker='D',color='m')<br \/><br \/>                #plt.show()<br \/><br \/>            except:<br \/>                #print('hello')<br \/>                continue<br \/><br \/>        title_string = indicator<br \/>        title_string += ' Average for selected years '<br \/>        plt.title(title_string)<br \/>        #plt.show()<br \/>        <br \/>        plt.savefig('.\/saved_images_from_visualizations\/' + 'geo_plot_average_over_multiple_years_' +indicator.replace(' ', '_')[0:5] + '_' + str(np.random.randint(0, 99999)) + '.png')<br \/>        plt.show()<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"3c5b\">Heatmap to compare across indicators and countries<\/h1>\n\n\n\n<p id=\"39dc\">Options implemented:<\/p>\n\n\n\n<p id=\"bbce\">Heatmap for one year, one indicator for a health-aspect across countries Heatmap for one year, all indicator for a health-aspect across countries<\/p>\n\n\n\n<p id=\"16ef\">Heatmap for one year, one indicator for a health-aspect across Canadian province Heatmap for one year, all indicator for a health-aspect across Canadian province<\/p>\n\n\n\n<p id=\"b20d\">Heatmap for all years with mean values, one indicator for a health-aspect across countries Heatmap for all years with mean values, all indicator for a health-aspect across countries<\/p>\n\n\n\n<p id=\"9824\">Heatmap for all years with mean values, one indicator for a health-aspect across Canadian province Heatmap for all years with mean values, all indicator for a health-aspect across Canadian province<\/p>\n\n\n\n<p id=\"835c\">Whether taking mean over multiple years is a pragmatic approach or not: \u2014 it can be an effective way of measurements provided data exist for all those years (otherwise the years with data will dominate) \u2014 in my case, data will not be available for all indicators for all years \u2014 we can then just plot for one year or I could give an interface to select years, indicators, countries for custom comparison \u2014 that can be a long task. Hence, I am giving the tool that can be extended in different ways<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># ref : https:\/\/cmdlinetips.com\/2019\/01\/how-to-make-heatmap-with-seaborn-in-python\/<br \/><br \/><br \/>import pandas as pd<br \/>import seaborn as sns<br \/>import matplotlib.pyplot as pltdef plot_heatmap_across_indicators(year, indicator = '', ratios = [3,1], provincial_only = False, all_years = all_years, fig_size = [10, 10]):<br \/>    <br \/>    if ( year &gt; 1 ):<br \/>        heatmap_data = measure_data.loc[  (measure_data['Data year'] == year)  &amp; (measure_data['Type of region'].isin(['Country', 'Canada']) )  ]<br \/>        if ( provincial_only == True ):<br \/>            heatmap_data = measure_data.loc[  (measure_data['Data year'] == year)  &amp; (measure_data['Type of region'].isin(['Province']) )  ]<br \/>            <br \/>        if ( indicator != ''):<br \/>            heatmap_data = measure_data.loc[  (measure_data['Indicator'] == indicator)  &amp; (measure_data['Data year'] == year) &amp; ( measure_data['Type of region'].isin(['Country', 'Canada']) ) ]<br \/>            if ( provincial_only == True ):<br \/>                heatmap_data = measure_data.loc[ (measure_data['Indicator'] == indicator)  &amp; (measure_data['Data year'] == year)  &amp; (measure_data['Type of region'].isin(['Province']) )  ]<br \/><br \/>        #print(heatmap_data)<br \/>        indicator_data_heatmap = heatmap_data[ ['Region', 'Value', 'Indicator', 'Data year']  ]<br \/>        <br \/>        #print(indicator_data_heatmap)<br \/>        <br \/>        <br \/>        heatmap1_data = pd.pivot_table(indicator_data_heatmap, values='Value',  index=['Region'], columns='Indicator')<br \/>        plt.figure(figsize=fig_size)<br \/>        ax = sns.heatmap(heatmap1_data, cmap=\"YlGnBu\")<br \/>        <br \/>        # https:\/\/stackoverflow.com\/questions\/48470251\/move-tick-marks-at-the-top-of-the-seaborn-plot?noredirect=1&amp;lq=1<br \/>        ax.xaxis.set_ticks_position('top')<br \/>        ax.set_xticklabels(indicator_data_heatmap['Indicator'], rotation=90) # can be turned off                        <br \/>        <br \/>        #plt.show()<br \/><br \/>                            <br \/>        title_string = measure_file.result[0:len(measure_file.result)-4]  + ':' + indicator<br \/>        title_string += ' for year ' + str(year)<br \/>        plt.title(title_string)<br \/>        #plt.show()<br \/>        <br \/>        plt.savefig('.\/saved_images_from_visualizations\/' + 'heatmap_' + measure_file.result[0:len(measure_file.result)-4] + indicator.replace(' ', '_')[0:5] + '_' + str(np.random.randint(0, 99999)) + '.png')<br \/>        #plt.show()<br \/>        <br \/>        <br \/>        <br \/>    else:<br \/>        # this is to plot over multiple years<br \/>        # average taken over multiple years will be plotted<br \/>        # I could make this more user friendly and data friendly <br \/>        # by giving users the option to select years, countries; also by informing to what extent data are available (skipping as that will extend the work much)<br \/>        <br \/>        <br \/>        heatmap_data = measure_data.loc[   (measure_data['Type of region'].isin(['Country', 'Canada']) )  ]<br \/>        if ( provincial_only == True ):<br \/>            heatmap_data = measure_data.loc[ (measure_data['Type of region'].isin(['Province']) )  ]<br \/>            <br \/>        if ( indicator != '' ):<br \/>            heatmap_data = measure_data.loc[  (measure_data['Indicator'] == indicator) &amp; (measure_data['Type of region'].isin(['Country', 'Canada']) )  ]<br \/>            if ( provincial_only == True ):<br \/>                heatmap_data = measure_data.loc[ (measure_data['Indicator'] == indicator)   &amp; (measure_data['Type of region'].isin(['Province']) )  ]<br \/><br \/>        #print(heatmap_data)<br \/>        indicator_data_heatmap = heatmap_data[ ['Region', 'Value', 'Indicator', 'Data year']  ]<br \/>        <br \/>                <br \/>        indicator_data = indicator_data_heatmap.set_index(['Region'])<br \/>        <br \/>        # x is not used, mean is calculated by seaborn<br \/>        #x = indicator_data.groupby(['Region', 'Indicator']).mean()        <br \/>        #print(x.index)<br \/>        #print(x)<br \/>        <br \/>        <br \/>        #heatmap1_data = pd.pivot_table(indicator_data_heatmap, values='Value',  index=['Region'],  columns='Indicator') <br \/>        #heatmap1_data = pd.pivot_table(x, values='Value',  index=x.index,  columns='Indicator') <br \/>        heatmap1_data = pd.pivot_table(indicator_data, index = indicator_data.index, columns='Indicator', values='Value', aggfunc = 'mean') <br \/>        plt.figure(figsize=fig_size)<br \/>        #ax = <br \/>        sns.heatmap(heatmap1_data, cmap=\"YlGnBu\")<br \/>        <br \/>        #ax.xaxis.set_ticks_position('top')<br \/>        #ax.set_xticklabels(indicator_data_heatmap['Indicator'], rotation=90) # can be turned off                        <br \/>        <br \/>        <br \/>        #plt.show()<br \/><br \/>                            <br \/>        title_string = measure_file.result[0:len(measure_file.result)-4] + ':' + indicator<br \/>        <br \/>        all_years_str = ''<br \/>        for aYear in all_years:<br \/>            if (aYear &gt; 0):<br \/>                all_years_str += str(aYear) + ', '<br \/>            <br \/>            <br \/>        year_str = ' for year '  + str(year) if year &gt; 0 else ' Mean over years \\n' + all_years_str<br \/>        title_string += year_str<br \/>        plt.title(title_string)<br \/>        #plt.show()<br \/>        <br \/>        plt.savefig('.\/saved_images_from_visualizations\/' + 'heatmap_over_years_' + measure_file.result[0:len(measure_file.result)-4] + indicator.replace(' ', '_')[0:5] + '_' + str(np.random.randint(0, 99999)) + '.png')<br \/>        #plt.show()<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"82cf\">Create the components for the UI interface<\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"3620\">Users will be interact with the system to generate custom visualizations<\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"75d9\">START-RELOAD-DAT<\/h1>\n\n\n\n<p id=\"664c\">this UI component creation might not be the must<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># create the interactive interface<br \/>def f(indicator):<br \/>    return indicator<br \/><br \/>#print ('Measure' + measure_file.result)<br \/>#print('Select parameters\\n')<br \/>#print('Select Indicator with or without Canadian data')<br \/>indicator_country = interactive(f, indicator=indicators);<br \/>#display(indicator_country)<br \/>indicator_country.result<br \/><br \/><br \/>def f(canada_indicator):<br \/>    return canada_indicator<br \/><br \/>#print('Select Indicator with Canadian data')<br \/>indicator_canada = interactive(f, canada_indicator=indicators_with_canada);<br \/>#display(indicator_canada)<br \/>indicator_canada.result<br \/><br \/><br \/>def f(year):<br \/>    return year<br \/><br \/>#print('Select Year: 0 = all years')<br \/>year_country = interactive(f, year=all_years);<br \/>#display(year_country)<br \/>year_country.result<br \/><br \/>#print('Select Year: 0 = all years')<br \/>year_canada = interactive(f, year=all_years_canada);<br \/>#display(year_canada)<br \/>year_canada.result<br \/><br \/><br \/>def f(what_to_plot):<br \/>    return what_to_plot<br \/><br \/>#print('Select what to plt:')<br \/>what_to_plot = {}<br \/># this can come from an excel file as well<br \/>what_to_plot['health-status.xls'] = ['Indicator Values over years', 'Indicator Values over countries', 'Geo plot', 'Heatmap']<br \/>what_to_plot['access-to-care.xls'] = ['Indicator Values over years', 'Indicator Values over countries', 'Geo plot', 'Heatmap']<br \/>#what_to_plot['indicator-methodology.xls'] = ['Indicator Values over years', 'Indicator Values over countries']<br \/>what_to_plot['non-med-determinants.xls'] = ['Indicator Values over years', 'Indicator Values over countries', 'Geo plot', 'Heatmap']<br \/>what_to_plot['patient-safety.xls'] = ['Indicator Values over years', 'Indicator Values over countries', 'Geo plot', 'Heatmap']<br \/>what_to_plot['prescribing-primary.xls'] = ['Indicator Values over years', 'Indicator Values over countries', 'Geo plot', 'Heatmap']<br \/>what_to_plot['quality-of-care.xls'] = ['Indicator Values over years', 'Indicator Values over countries', 'Geo plot', 'Heatmap']<br \/><br \/><br \/>plots = interactive(f, what_to_plot=what_to_plot[measure_file.result]);<br \/>#display(plots)<br \/>plots.result<br \/><br \/><br \/>def f(chart_type):<br \/>    return chart_type<br \/><br \/>#print('Select chart type:')<br \/>chart_types = ['Bubble', 'Bar', 'Hor Bar', 'Pie', 'Line']<br \/>chart = interactive(f, chart_type=chart_types);<br \/>#display(chart)<br \/>chart.result<br \/><br \/><br \/>def f(scale):<br \/>    return scale<br \/><br \/>#print('Select bubble size')<br \/>bubble_scale_country = interactive(f, scale=(0, 100, 1));<br \/>#display(bubble_scale_country)<br \/>#bubble_scale_country.result = 10<br \/><br \/>def f(x):<br \/>    return x<br \/><br \/>#print('Max country count to compare with')<br \/>country_count = interactive(f, x=range(1, 20));<br \/>#display(country_count)<br \/>country_count.result<br \/><br \/>#print('Select countries')<br \/>#print('Compare with Canada')<br \/>all_countries = interactive(f, x=True);<br \/>#display(all_countries)<br \/>all_countries.result<br \/><br \/>country_0 = interactive(f, x = countries);<br \/>country_1 = interactive(f, x = countries);<br \/>#country_str = \"var%d = interactive(f, x = countries)\"<br \/>#display(country_0)<br \/>#display(country_1)<br \/>country_0.result<br \/><br \/>def f(com_with_cdn):<br \/>    return com_with_cdn<br \/><br \/>#print('Compare with Canada')<br \/>compare_canada = interactive(f, com_with_cdn=False);<br \/>#display(compare_canada)<br \/>compare_canada.result<br \/><br \/>def f(use_data_with_canada):<br \/>    return use_data_with_canada<br \/><br \/>use_data_with_canada = interactive(f, use_data_with_canada=False);<br \/>#display(use_data_with_canada)<br \/>use_data_with_canada.result<br \/><br \/><br \/>def f(provincial_only):<br \/>    return provincial_only<br \/><br \/>provincial_only_plot = interactive(f, provincial_only=False);<br \/>#display(use_data_with_canada)<br \/>provincial_only_plot.result<br \/><br \/><br \/># animate over time<br \/>def f(animate):<br \/>    return animate<br \/><br \/>#print('Compare with Canada')<br \/>animate_ = interactive(f, animate=False);<br \/>#display(compare_canada)<br \/>animate_.result<br \/><br \/><br \/># for heatmap, do we consider the indicator or not<br \/>def f(heatmap_consider_indicator):<br \/>    return heatmap_consider_indicator<br \/><br \/>heatmap_consider_indicator_ = interactive(f, heatmap_consider_indicator=False);<br \/>#display(heatmap_consider_indicator_)<br \/>heatmap_consider_indicator_.result<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"281c\">Render the UI controls<\/h1>\n\n\n\n<p id=\"201c\">Note: use_data_with_canada \u2014 is to indicate that when canadian data are available. Also, Canada_Indicator and Year from the right will be used<\/p>\n\n\n\n<p id=\"8b39\">com_with_cdn and animate controls are not used so far<\/p>\n\n\n\n<p id=\"f011\">Must as part of reload data<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Reference: https:\/\/ipywidgets.readthedocs.io\/en\/stable\/examples\/Widget%20Styling.html<br \/>print('Indicator and year list on the right, represent where Canadian data exist')<br \/>from ipywidgets import Button, GridBox, Layout, ButtonStyle<br \/>GridBox(children=[<br \/>                    use_data_with_canada, compare_canada,<br \/>                    indicator_country, indicator_canada, <br \/>                    year_country, year_canada,<br \/>                    plots, chart,<br \/>                    bubble_scale_country, provincial_only_plot,<br \/>                    heatmap_consider_indicator_, animate_<br \/>                ],<br \/>        <br \/>        layout=Layout(<br \/>            width='100%',<br \/>            grid_template_rows='auto auto',<br \/>            grid_template_columns='50%50%',<br \/>            )<br \/>       )Indicator and year list on the right, represent where Canadian data exist<br \/><br \/><br \/><br \/>---------------------------------------------------------------------------<br \/><br \/>ImportError                               Traceback (most recent call last)<br \/><br \/>&lt;ipython-input-28-5b8e7f56abb0&gt; in &lt;module&gt;()<br \/>      1 # Reference: https:\/\/ipywidgets.readthedocs.io\/en\/stable\/examples\/Widget%20Styling.html<br \/>      2 print('Indicator and year list on the right, represent where Canadian data exist')<br \/>----&gt; 3 from ipywidgets import Button, GridBox, Layout, ButtonStyle<br \/>      4 GridBox(children=[<br \/>      5                     use_data_with_canada, compare_canada,<br \/><br \/><br \/>ImportError: cannot import name 'GridBox'<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"b76c\">END-RELOAD-DATA<\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\"># assign a default value<br \/>bubble_scale_country.result = 10<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"09a7\">Create the Plot Based on User Selections<\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\">plt.rcParams['figure.figsize'] = [10, 8]<br \/>#print(chart.result)<br \/>#provincial_only = False<br \/>heatmap_consider_indicator = heatmap_consider_indicator_.result<br \/># Data irrespective Canada has data or not<br \/>if use_data_with_canada.result == False:<br \/>    indicator = indicator_country.result<br \/>    year = year_country.result<br \/>    bubble_scale = bubble_scale_country.result<br \/><br \/># when we are saying data for canada must exist there    <br \/>else:<br \/>    indicator = indicator_canada.result<br \/>    year = year_canada.result<br \/>    bubble_scale = bubble_scale_country.result<br \/>    #provincial_only = provincial_only_plot.result<br \/>    <br \/>#print(indicator, year, bubble_scale)<br \/>if plots.result == 'Indicator Values over years':<br \/>    plot_measure_by_years(year, indicator, bubble_scale, chart_type=chart.result, ratios=[3,1], animate = animate_.result, <br \/>        provincial_only=provincial_only_plot.result, fig_size=[20,10], sec_fig=False)<br \/>elif plots.result == 'Geo plot':<br \/>    plot_map_measure_by_regions(year, indicator, bubble_scale, chart_type=chart.result, \\<br \/>                                provincial_only=provincial_only_plot.result)<br \/>    <br \/>elif plots.result == 'Heatmap':<br \/>    if ( heatmap_consider_indicator == False ):<br \/>        indicator = ''<br \/>    plot_heatmap_across_indicators(year, indicator, provincial_only=provincial_only_plot.result, fig_size=[10, 10])   <br \/>else: # Indicator Values over countries<br \/>    plot_measure_by_regions(year, indicator, bubble_scale, chart_type=chart.result, \\<br \/>                            ratios=[3,1], provincial_only=provincial_only_plot.result)<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"573d\">Section: Research Questions and Answers<\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"942e\">Please Select the related measure and reload all data (as marked with Start-Reload, End-Reload). Otherwise the following visualizations might not work unless that is for currently selected measures<\/h1>\n\n\n\n<p id=\"77ce\">A better solution could be: I could place the measure selection here and could execute all the data reload code<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"ea93\">Visualizations plotted independently for the visualizations used in the detail prsentation document<\/h1>\n\n\n\n<p id=\"8159\">All these can be generated using the UI, I am just showing specific cases as I plotted using UI and provided on my report<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"31c6\">How does Canada compare for a health status indicator such as : Cancer Mortality (F) for 2017 (per 100k)? Example: Cancer Mortality, 2017:<\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\">year = 2017<br \/>indicator = 'Cancer Mortality (F)'<br \/><br \/># does not matter<br \/>bubble_scale = 11<br \/><br \/>chart_type = 'Line'<br \/><br \/># subplot ratios<br \/>ratios = [1000, 1]<br \/><br \/># not implemented<br \/>animate = False<br \/><br \/># if for Provinces - Canada<br \/>provincial_only = False<br \/><br \/># figure size<br \/>fig_size = [5, 5]<br \/><br \/># not important<br \/>sec_fig = True<br \/><br \/>print('The right line on the plot does not count; comes from the right subplot; that is not relevant for this case')<br \/>plot_measure_by_years(year, indicator, bubble_scale, chart_type, ratios, animate, provincial_only, fig_size=fig_size)The right line on the plot does not count; comes from the right subplot; that is not relevant for this case<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/miro.medium.com\/proxy\/1%2AzlKd20OftTsNdZYIAY9k-A.png?w=750&#038;ssl=1\" alt=\"png\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/miro.medium.com\/proxy\/1%2A_07zvH70-qtKAbildWclqQ.png?w=750&#038;ssl=1\" alt=\"png\"\/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"fbef\">Research Question: how does an indicator such as Transport Mortality changed over time for different countries?<\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\">year = 0<br \/>indicator = 'Transport Accident Mortality (M)'<br \/><br \/># does not matter<br \/>bubble_scale = 100<br \/><br \/>chart_type = 'Bubble'<br \/><br \/># subplot ratios<br \/># as we will show countries by colors, ratios are useful<br \/>ratios = [3, 1]<br \/><br \/># not implemented<br \/>animate = False<br \/><br \/># if for Provinces - Canada<br \/>provincial_only = False<br \/><br \/># figure size<br \/>fig_size = [20, 10]<br \/><br \/># not important<br \/>sec_fig = True<br \/><br \/>print('Note: Y axis values need to be multiplied by Benchmark value to get actual values')<br \/>plot_measure_by_years(year, indicator, bubble_scale, chart_type, ratios, animate, provincial_only, fig_size=fig_size)Note: Y axis values need to be multiplied by Benchmark value to get actual values<br \/><br \/><br \/>C:\\ProgramData\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:346: SettingWithCopyWarning: <br \/>A value is trying to be set on a copy of a slice from a DataFrame.<br \/>Try using .loc[row_indexer,col_indexer] = value instead<br \/><br \/>See the caveats in the documentation: <a href=\"http:\/\/pandas.pydata.org\/pandas-docs\/stable\/indexing.html#indexing-view-versus-copy\">http:\/\/pandas.pydata.org\/pandas-docs\/stable\/indexing.html#indexing-view-versus-copy<\/a><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/miro.medium.com\/proxy\/1%2AMyruPlpD4AIHTZbLxD5HmA.png?w=750&#038;ssl=1\" alt=\"png\"\/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"7486\">Research Question: How do Canadian provinces perform for Transport Mortality (M) for 2017?<\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\">year = 2017<br \/>indicator = 'Transport Accident Mortality (M)'<br \/><br \/># does not matter<br \/>bubble_scale = 100<br \/><br \/># will plot for other chart types as well<br \/>chart_type = 'Line'<br \/><br \/># subplot ratios<br \/># as we will show countries by colors, ratios are useful<br \/>ratios = [10, 1]<br \/><br \/># not implemented<br \/>animate = False<br \/><br \/># Matters as we are plotting for Canadian provinces<br \/>provincial_only = True<br \/><br \/># figure size<br \/>fig_size = [10, 8]<br \/><br \/># not important<br \/>sec_fig = True<br \/><br \/>print('Note: Y axis values need to be multiplied by Benchmark value to get actual values')<br \/>plot_measure_by_years(year, indicator, bubble_scale, chart_type, ratios, animate, provincial_only, fig_size=fig_size)Note: Y axis values need to be multiplied by Benchmark value to get actual values<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/miro.medium.com\/proxy\/1%2ApLMu1jWwW_hg2iUKyGxwRA.png?w=750&#038;ssl=1\" alt=\"png\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/miro.medium.com\/proxy\/1%2Ag0S1ZQkThJdWk4nRHvNGCQ.png?w=750&#038;ssl=1\" alt=\"png\"\/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"a348\">Research, Analysis, and Visualization Concern:<\/h1>\n\n\n\n<p id=\"811c\">How does the transport mortality compare against countries on 2017 based on the data we have? Visualize in different format<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">chart_types = ['Bubble', 'Bar', 'Hor Bar', 'Pie', 'Line']<br \/><br \/>year = 2017<br \/>indicator = 'Transport Accident Mortality (M)'<br \/><br \/># does not matter<br \/>bubble_scale = 32<br \/><br \/># will plot for other chart types as well<br \/>chart_type = 'Line'<br \/><br \/># subplot ratios<br \/># as we will show countries by colors, ratios are useful<br \/>ratios = [10, 1]<br \/><br \/># not implemented<br \/>animate = False<br \/><br \/># Matters as we are plotting for Canadian provinces<br \/>provincial_only = False<br \/><br \/># figure size<br \/>fig_size = [5, 5]<br \/><br \/># not important<br \/>sec_fig = True<br \/><br \/><br \/>for chart_type in chart_types:<br \/>    plot_measure_by_years(year, indicator, bubble_scale, chart_type, ratios, animate, provincial_only, fig_size=fig_size)<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/miro.medium.com\/proxy\/1%2AdP-AsAliG4uHKYqJaNL_WQ.png?w=750&#038;ssl=1\" alt=\"png\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/miro.medium.com\/proxy\/1%2A9bJxVISUZJsbF3Rl0Wa5-Q.png?w=750&#038;ssl=1\" alt=\"png\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/miro.medium.com\/proxy\/1%2A5UfUQWDEXjCBLpuehLA4xA.png?w=750&#038;ssl=1\" alt=\"png\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/miro.medium.com\/proxy\/1%2At_EUiIsEINlPNRzSHtapTw.png?w=750&#038;ssl=1\" alt=\"png\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/miro.medium.com\/proxy\/1%2ASwj1jIkQT8WyMYYwoG023Q.png?w=750&#038;ssl=1\" alt=\"png\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/miro.medium.com\/proxy\/1%2APLg3nhM6HjQOddcfKmJ63Q.png?w=750&#038;ssl=1\" alt=\"png\"\/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"2b29\">How does the transport mortality compare against Canadian provinces on 2017 based on the data we have? Visualize in different format<\/h1>\n\n\n\n<p id=\"5259\">Note: the code from the above cell need to be executed first as I am reusing some variables<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Matters as we are plotting for Canadian provinces<br \/>provincial_only = True<br \/><br \/># figure size<br \/>fig_size = [10, 8]<br \/><br \/># not important<br \/>sec_fig = True<br \/><br \/>ratios = [3, 1]<br \/><br \/>for chart_type in chart_types:<br \/>    plot_measure_by_years(year, indicator, bubble_scale, chart_type, ratios, animate, provincial_only, fig_size=fig_size)<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/miro.medium.com\/proxy\/1%2ALWtpJgxIEq5an3KM4zJtXg.png?w=750&#038;ssl=1\" alt=\"png\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/miro.medium.com\/proxy\/1%2AgF_g_slrT8UMrBik5kws9Q.png?w=750&#038;ssl=1\" alt=\"png\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/miro.medium.com\/proxy\/1%2AVnNXA3N4bKQFCQawZJRb8w.png?w=750&#038;ssl=1\" alt=\"png\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/miro.medium.com\/proxy\/1%2AUzBLfiGCmj9Z2Z4pTDR4LQ.png?w=750&#038;ssl=1\" alt=\"png\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/miro.medium.com\/proxy\/1%2AuNkXVGQwEb_bINFRSE3oOA.png?w=750&#038;ssl=1\" alt=\"png\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/miro.medium.com\/proxy\/1%2AHKvgk2WUUmZZZJCChso2ew.png?w=750&#038;ssl=1\" alt=\"png\"\/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"eedb\">For Research Question: What are average alcohol consumption across countries over last couple of years<\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\"># you can add or remove years, to get average measures over those years<br \/>year = 0 # 0 indicates all years for the list all_years<br \/>all_years = [2013, 2014, 2015, 2016, 2017] <br \/>indicator = 'Alcohol Consumption: Adults'<br \/>bubble_scale = 91 # NA<br \/>chart_type='Bar' # change to Line, Bubble, Pie, 'Hor Bar'<br \/>provincial_only = False # if you set true only provincial data will be plotted<br \/><br \/># plot_measure_by_regions(year, indicator, bubble_scale, chart_type = '', ratios=[3,1], provincial_only=False, all_years=all_years):    <br \/>plot_measure_by_regions(year, indicator, bubble_scale, chart_type, ratios=[3,1], provincial_only=provincial_only, all_years=all_years)<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/miro.medium.com\/proxy\/1%2AqU44EhXt6YKOuLOQK_tkpA.png?w=750&#038;ssl=1\" alt=\"png\"\/><\/figure>\n\n\n\n<p id=\"e271\">the above case just for year 2015<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#year = 0 # 0 indicates all years for the list all_years<br \/>#all_years = [2013, 2014, 2015, 2016, 2017] <br \/>indicator = 'Alcohol Consumption: Adults'<br \/>#bubble_scale = 91 # NA<br \/>#chart_type='Bar' # change to Line, Bubble, Pie, 'Hor Bar'<br \/>provincial_only = False # if you set true only provincial data will be plotted<br \/><br \/><br \/>print('if you want for only one year change as follows')<br \/>print('For Research Question: What are average alcohol consumption across countries for 2015')<br \/># if you want for only one year change as follows<br \/>year = 2015<br \/># other chart type sych as bar will work though will have issues<br \/>chart_type='Bar' <br \/>#plot_measure_by_regions(year, indicator, bubble_scale, chart_type,  ratios=[3,1], provincial_only)      <br \/>plot_measure_by_regions(year, indicator, bubble_scale, chart_type, ratios=[3,1], provincial_only=provincial_only, all_years=all_years)if you want for only one year change as follows<br \/>For Research Question: What are average alcohol consumption across countries for 2015<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/miro.medium.com\/proxy\/1%2AoHcC6aVFQ69zErGlFSeNgA.png?w=750&#038;ssl=1\" alt=\"png\"\/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"79e0\">Research Question: For 2015, which country smoked the most? Used Geo plot. However, plots like above sections could also be used<\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\">chart_type'Bar'year = 2015<br \/>indicator = 'Smoking: Adults (M)'<br \/><br \/># the plot on the presentation used 2<br \/># note : this is inverse size of the bubble<br \/>bubble_scale = 3<br \/>chart_type = ''<br \/># are not relevant<br \/># chart_type = '',  all_years=all_years, also provincial_only=False<br \/><br \/>plot_map_measure_by_regions(year, indicator, bubble_scale, chart_type = '', provincial_only=False, all_years=all_years)<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/miro.medium.com\/proxy\/1%2AOyC7Nq-BZ7FskHZsxNX86w.png?w=750&#038;ssl=1\" alt=\"png\"\/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"0e23\">Research Question: Where in the world obesity are more common?<\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\">year = 0<br \/>indicator = 'Obesity Reported: Adults'<br \/># the plot on the presentation used 2<br \/># note : this is inverse size of the bubble<br \/>bubble_scale = 2<br \/>chart_type = ''<br \/># are not relevant<br \/># chart_type = '',  all_years=all_years, also provincial_only=False<br \/><br \/>plot_map_measure_by_regions(year, indicator, bubble_scale, chart_type = '', provincial_only=False, all_years=all_years)<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/miro.medium.com\/proxy\/1%2ApU02uwW5bG8z79i0UYSttA.png?w=750&#038;ssl=1\" alt=\"png\"\/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"4102\">Research Question: Using a Heatmap, How different countries compare for their Non Medical Determinants aspect for 2014<\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"8deb\">Note: current selection needs to be: Non Medical Determinants.<\/h1>\n\n\n\n<p id=\"6a14\">You can change the Health Measure and then all data have to be reloaded by executing the sections marked: START-Reload, END-Reload<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">indicator = ''<br \/>year = 2014<br \/>indicator = ''<br \/>provincial_only_plot = False<br \/>plot_heatmap_across_indicators(year, indicator, provincial_only=provincial_only_plot, fig_size=[10, 10])<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/miro.medium.com\/proxy\/1%2ApxDLDR3WBW-voeFboBD8hA.png?w=750&#038;ssl=1\" alt=\"png\"\/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"3571\">Research question: How do different countries compare for health status indicators over years<\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"e7b6\">Note: current selection needs to be: Health status with code from START-Reload-data to END-RELOAD-Data need to be executed)<\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\">indicator = ''<br \/>year = 0<br \/>indicator = ''<br \/>provincial_only_plot = False<br \/>plot_heatmap_across_indicators(year, indicator, provincial_only=provincial_only_plot, fig_size=[10, 10])<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/miro.medium.com\/proxy\/1%2APN0ANq7OiPoj1TvMrR8-9g.png?w=750&#038;ssl=1\" alt=\"png\"\/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"5687\">Research question: How do Canadian Provinces compare for health status indicators over years<\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"b1c1\">Note: current selection needs to be: Health status (otherwise, plots will be using current health aspect\/measure that I may or may not have tested)<\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\">indicator = ''<br \/>year = 0<br \/>indicator = ''<br \/>provincial_only_plot = True<br \/>fig_size_=[7, 5]<br \/>plot_heatmap_across_indicators(year, indicator, provincial_only=provincial_only_plot, fig_size=fig_size_)<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/miro.medium.com\/proxy\/1%2APihUJE__InE6Ro27mTL6kA.png?w=750&#038;ssl=1\" alt=\"png\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\">year, indicator(2017, 'Transport Accident Mortality (F)')<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"dd76\">Research Question: How does transport mortality (Female) compare acrosss countries for 2017<\/h1>\n\n\n\n<p id=\"ea48\">This is just an example to show heatmap plot when \u2018heatmap_consider_indicator\u2019 option is selected and an indicator is selected<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">year = 2017<br \/>indicator = 'Transport Accident Mortality (F)'<br \/>fig_size_=[3, 5]<br \/>plot_heatmap_across_indicators(year, indicator, provincial_only=provincial_only_plot.result, fig_size=fig_size_)<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/miro.medium.com\/proxy\/1%2APzU8mmapvvfB6fUNjq20DQ.png?w=750&#038;ssl=1\" alt=\"png\"\/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"7ffe\">Access to Care<\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"cfbd\">Please select Access to Care Measure, and reload all data<\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"7bde\">Wait time for specialists in Days<\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\">year = 0<br \/>indicator = 'Wait Time: Specialist'<br \/>bubble_scale = 10<br \/>chart_type = 'Bubble'<br \/>provincial_only=False<br \/>ratios=[3,1]<br \/><br \/>plot_measure_by_regions(year, indicator, bubble_scale, chart_type=chart_type, ratios=ratios, provincial_only=False)<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/miro.medium.com\/proxy\/1%2ARUjp_INRle7Wjz7CVYAVZQ.png?w=750&#038;ssl=1\" alt=\"png\"\/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"e8a4\">Access to Care: same or next day appointment<\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\">year, indicator, bubble_scale(0, 'Same or Next Day Appt', 10)year = 0<br \/>indicator = 'Same or Next Day Appt'<br \/>bubble_scale = 10<br \/>chart_type = 'Bubble'<br \/>provincial_only=True<br \/>ratios=[3,1]<br \/><br \/>plot_measure_by_regions(year, indicator, bubble_scale, chart_type=chart_type, ratios=ratios, provincial_only=True)<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/miro.medium.com\/proxy\/1%2AINh0t7At2A5wSa5Md33K2A.png?w=750&#038;ssl=1\" alt=\"png\"\/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"3a5d\">Heatmap: Access to Care Indicators<\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\">year,indicator(0, '')year = 0<br \/>indicator = ''<br \/>plot_heatmap_across_indicators(year, indicator, provincial_only=False, fig_size=[10, 10])<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/miro.medium.com\/proxy\/1%2AtFJm1lN_c_VDTXKbRZ5ROA.png?w=750&#038;ssl=1\" alt=\"png\"\/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"aeea\">The following code are supposed to be removed at the final step<\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"ff54\">Code reused from lab 06 the geoplot<\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\"># references<br \/># <a href=\"https:\/\/pypi.org\/project\/geopy\/\">https:\/\/pypi.org\/project\/geopy\/<\/a><\/pre>\n\n\n\n<p><a href=\"https:\/\/medium.com\/health-system-performance?source=post_sidebar--------------------------post_sidebar-----------\">Health System Performance<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Health System Performance<\/h4>\n\n\n\n<p>Following<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/medium.com\/health-system-performance\/tagged\/health-system-performance\">Health System Performance<\/a><\/li><li><a href=\"https:\/\/medium.com\/health-system-performance\/tagged\/canada\">Canada<\/a><\/li><li><a href=\"https:\/\/medium.com\/health-system-performance\/tagged\/data-visualizations\">Data Visualizations<\/a><\/li><li><a href=\"https:\/\/medium.com\/health-system-performance\/tagged\/python-data-visualization\">Python Data Visualization<\/a><\/li><li><a href=\"https:\/\/medium.com\/health-system-performance\/tagged\/cihi-dataset\">Cihi Dataset<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Justetc Social Services (non-profit)Jan 31&nbsp;\u00b7&nbsp;29&nbsp;min read Indicator visualizations will be in a separate ipynb file (visualize-indicators-final.ipynb) Visualizations can be created using the UI interface i.e. Select options and execute the code block after to get the visualizations. I have placed a separate section at the end of this file where research questions and plots as &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=19912\">Continue reading<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1903,1894,1919,182],"tags":[],"class_list":["post-19912","post","type-post","status-publish","format-standard","hentry","category-data-visualization","category-health-system-performance","category-visualize-health-system-performance","category---blog","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":16155,"url":"http:\/\/bangla.sitestree.com\/?p=16155","url_meta":{"origin":19912,"position":0},"title":"Text Visualization: Concepts, Examples, Code (Python, R, Matlab), Example Projects","author":"Sayed","date":"September 10, 2019","format":false,"excerpt":"Text Visualization Data Visualization Of President Obama's Inauguration Speech https:\/\/blog.capitalogix.com\/public\/2009\/01\/data-visualization-of-president-obamas-inauguration-speech.html Text Visualization Course at Washington University https:\/\/courses.cs.washington.edu\/courses\/cse512\/16sp\/lectures\/CSE512-Text.pdf Why Visualize Text? https:\/\/www.teachervision.com\/reading-comprehension\/visualizing You can visualize text to find key concepts in a speech. Obama's Speech: https:\/\/www.nytimes.com\/2009\/09\/10\/us\/politics\/10obama.text.html Example: Speech\/Article Visualizations https:\/\/economix.blogs.nytimes.com\/2009\/09\/09\/obama-in-09-vs-clinton-in-93\/?mtrref=undefined&gwh=EA5A091DC9E658A2DCC9513805FEAC3F&gwt=pay&assetType=REGIWALL 1993 Speech: Bill Clinton https:\/\/economix.blogs.nytimes.com\/2009\/09\/09\/bill-clinton-on-health-care-1993\/ 1993 vs 2009. https:\/\/economix.blogs.nytimes.com\/2009\/09\/09\/obama-in-09-vs-clinton-in-93\/ Wordtree https:\/\/www.jasondavies.com\/wordtree\/?source=8bd3e76f64f2d614410435434e2fb1fd&amp;prefix\u2026","rel":"","context":"In &quot;AI ML DS RL DL NN NLP Data Mining Optimization&quot;","block_context":{"text":"AI ML DS RL DL NN NLP Data Mining Optimization","link":"http:\/\/bangla.sitestree.com\/?cat=1910"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":19909,"url":"http:\/\/bangla.sitestree.com\/?p=19909","url_meta":{"origin":19912,"position":1},"title":"About the Project : Benchmarking Canada\u2019s Health Care Systems: International Comparisons, 2017","author":"Sayed","date":"February 7, 2021","format":false,"excerpt":"Justetc Social Services (non-profit)Jan 31\u00a0\u00b7\u00a01\u00a0min read Project : Benchmarking Canada\u2019s Health Care Systems: International Comparisons, 2017 By Sayed Ahmed Objective: Visualize the performance of Canadian Healthcare System Performance against other countries Short Description\u00a0: Analyze, compare, and visualize the performance of Canadian healthcare system against other countries using public dataset. The\u2026","rel":"","context":"In &quot;Data Visualization&quot;","block_context":{"text":"Data Visualization","link":"http:\/\/bangla.sitestree.com\/?cat=1903"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26193,"url":"http:\/\/bangla.sitestree.com\/?p=26193","url_meta":{"origin":19912,"position":2},"title":"Text Visualization: Concepts, Examples, Code (Python, R, Matlab), Example Projects #Root","author":"Author-Check- Article-or-Video","date":"April 19, 2021","format":false,"excerpt":"Text Visualization Data Visualization Of President Obama's Inauguration Speech https:\/\/blog.capitalogix.com\/public\/2009\/01\/data-visualization-of-president-obamas-inauguration-speech.html Text Visualization Course at Washington University https:\/\/courses.cs.washington.edu\/courses\/cse512\/16sp\/lectures\/CSE512-Text.pdf Why Visualize Text? https:\/\/www.teachervision.com\/reading-comprehension\/visualizing You can visualize text to find key concepts in a speech. Obama's Speech: https:\/\/www.nytimes.com\/2009\/09\/10\/us\/politics\/10obama.text.html Example: Speech\/Article Visualizations https:\/\/economix.blogs.nytimes.com\/2009\/09\/09\/obama-in-09-vs-clinton-in-93\/?mtrref=undefined&gwh=EA5A091DC9E658A2DCC9513805FEAC3F&gwt=pay&assetType=REGIWALL 1993 Speech: Bill Clinton https:\/\/economix.blogs.nytimes.com\/2009\/09\/09\/bill-clinton-on-health-care-1993\/ 1993 vs 2009. https:\/\/economix.blogs.nytimes.com\/2009\/09\/09\/obama-in-09-vs-clinton-in-93\/ Wordtree https:\/\/www.jasondavies.com\/wordtree\/?source=8bd3e76f64f2d614410435434e2fb1fd&amp;prefix\u2026","rel":"","context":"In &quot;Data Visualization&quot;","block_context":{"text":"Data Visualization","link":"http:\/\/bangla.sitestree.com\/?cat=1903"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":76547,"url":"http:\/\/bangla.sitestree.com\/?p=76547","url_meta":{"origin":19912,"position":3},"title":"Advanced Data Visualization Resources (in Python)","author":"Sayed","date":"January 1, 2025","format":false,"excerpt":"Advanced Data Visualization Advanced Data Visualization Data Visualization Misc Data Visualization Overview: Data Visualization: About Data Visualization http:\/\/guides.library.duke.edu\/c.php?g=289678&p=1930713 I Can See Clearly Now: A Survey of Data Visualization Techniques & Practice https:\/\/www.slideshare.net\/myles_harrison\/i-can-see-clearly-now-a-survey-of-data-visualization-techniques-practice-31179055 Visualization in Data Science: What is it for? http:\/\/guides.library.duke.edu\/c.php?g=289678&p=1930713 Anscombe's quartet https:\/\/en.wikipedia.org\/wiki\/Anscombe's_quartet Storytelling and data visualization\u2026 So what?\u2026","rel":"","context":"In &quot;Data Visualization&quot;","block_context":{"text":"Data Visualization","link":"http:\/\/bangla.sitestree.com\/?cat=1903"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":16171,"url":"http:\/\/bangla.sitestree.com\/?p=16171","url_meta":{"origin":19912,"position":4},"title":"PERCEPTION and Data Visualization: Concepts, Examples, Code, Projects","author":"Sayed","date":"September 10, 2019","format":false,"excerpt":"PERCEPTION Data Visualization for Human Perception \"Data visualization is the graphical display of abstract information for two purposes: sense-making (also called data analysis) and communication. ... In other words, to visualize data effectively, we must follow design principles that are derived from an understanding of human perception.\" https:\/\/www.interaction-design.org\/literature\/book\/the-encyclopedia-of-human-computer-interaction-2nd-ed\/data-visualization-for-human-perception The Role\u2026","rel":"","context":"In &quot;AI ML DS RL DL NN NLP Data Mining Optimization&quot;","block_context":{"text":"AI ML DS RL DL NN NLP Data Mining Optimization","link":"http:\/\/bangla.sitestree.com\/?cat=1910"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":16051,"url":"http:\/\/bangla.sitestree.com\/?p=16051","url_meta":{"origin":19912,"position":5},"title":"Data Visualization in Python (R)","author":"Sayed","date":"September 4, 2019","format":false,"excerpt":"Python Treemaps with Squarify & Matplotlib https:\/\/fcpython.com\/visualisation\/python-treemaps-squarify-matplotlib --- Treemaps With Squarify https:\/\/galaxydatatech.com\/2018\/03\/20\/treemaps-with-squarify\/ --- 200 Basic Treemap with python https:\/\/python-graph-gallery.com\/200-basic-treemap-with-python\/ --- Dendrograms in Python https:\/\/plot.ly\/python\/dendrogram\/ https:\/\/python-graph-gallery.com\/dendrogram\/ --- HIERARCHICAL CLUSTERING IN R: THE ESSENTIALS https:\/\/www.datanovia.com\/en\/lessons\/examples-of-dendrograms-visualization\/ --- Geographic Data with Basemap https:\/\/jakevdp.github.io\/PythonDataScienceHandbook\/04.13-geographic-data-with-basemap.html --- Plotting data on a map (Example Gallery)\u00b6 https:\/\/matplotlib.org\/basemap\/users\/examples.html --- A\u2026","rel":"","context":"In &quot;AI ML DS RL DL NN NLP Data Mining Optimization&quot;","block_context":{"text":"AI ML DS RL DL NN NLP Data Mining Optimization","link":"http:\/\/bangla.sitestree.com\/?cat=1910"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/19912","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=19912"}],"version-history":[{"count":1,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/19912\/revisions"}],"predecessor-version":[{"id":19913,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/19912\/revisions\/19913"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=19912"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=19912"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=19912"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}