#! /usr/bin/env python3 # def album_bar ( ): #*****************************************************************************80 # ## album_bar() makes a bar graph of music album sales over 11 years. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 21 April 2019 # # Author: # # John Burkardt # import matplotlib.pyplot as plt import numpy as np print ( '' ) print ( 'album_bar():' ) print ( ' Read a data file of yearly music album sales.' ) print ( ' Plot the data as a bar chart.' ) # # Read the year and sales from the data file. # filename = 'album_data.txt' data = np.loadtxt ( filename ) year = data[:,0] sales = data[:,1] # # Create the bar plot. # plt.bar ( year, sales, color = 'g' ) plt.grid ( True ) plt.title ( 'Music album sales, all formats', fontsize = 16 ) plt.xlabel ( '<-- Year -->', fontsize = 16 ) plt.ylabel ( '<-- Sales (millions) -->', fontsize = 16 ) filename = 'album_bar.png' plt.savefig ( filename ) plt.show ( ) plt.close ( ) print ( ' Graphics saved as "%s"' % ( filename ) ) return if ( __name__ == '__main__' ): album_bar ( )