#! /usr/bin/env python3 # def schoolyear_barh ( ): #*****************************************************************************80 # ## schoolyear_barh() makes a horizontal bar plot of schoolyear lengths. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 28 February 2023 # # Author: # # John Burkardt # import csv import matplotlib.pyplot as plt import numpy as np print ( '' ) print ( 'schoolyear_barh():' ) print ( ' Create a horizontal bar plot of the length of schoolyears.' ) # # Read the values from the file. # types = [ 'U20', 'i4' ] data = np.genfromtxt ( 'schoolyear_data.csv', dtype = types, \ delimiter=',', names = True ) days = data['Days'] name = data['Country'] # # We want the list to be plotted in alphabetic order, reading # from top down to bottom. To do this, we have to reverse our data. # days = np.flip ( days ) name = np.flip ( name ) n = len ( days ) country = np.linspace ( 1, n, n ) # # Create the bar plot. # plt.barh ( country, days ) plt.grid ( True ) plt.title ( 'Schoolyear lengths', fontsize = 16 ) plt.xlabel ( '<-- Days -->', fontsize = 16 ) plt.yticks ( country, name, fontsize = 6 ) filename = 'schoolyear_barh.png' plt.savefig ( filename ) plt.show ( ) plt.close ( ) print ( ' Graphics saved as "%s"' % ( filename ) ) return if ( __name__ == '__main__' ): schoolyear_barh ( )