#! /usr/bin/env python3 # def bulgaria_plot1 ( ): #*****************************************************************************80 # ## bulgaria_plot1() plots the population of Bulgaria over time. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 28 February 2023 # # Author: # # John Burkardt # import matplotlib.pyplot as plt import numpy as np print ( '' ) print ( 'bulgaria_plot1():' ) print ( ' Plot the population of Bulgaria over time.' ) # # Read the pairs "Year, Population" from the file. # filename = 'bulgaria_data.txt' data = np.loadtxt ( filename ) # # Split data into separate year and population vectors. # year = data[:,0] population = data[:,1] # # Plot the data. # plt.plot ( year, population, 'b-', linewidth = 3 ) filename = 'bulgaria_plot1.png' plt.savefig ( filename ) print ( ' Graphics saved as "%s"' % ( filename ) ) plt.show ( ) plt.close ( ) return def bulgaria_plot2 ( ): #*****************************************************************************80 # ## bulgaria_plot2() plots the population of Bulgaria over time. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 28 February 2023 # # Author: # # John Burkardt # import matplotlib.pyplot as plt import numpy as np print ( '' ) print ( 'bulgaria2_plot():' ) print ( ' Plot the population of Bulgaria over time.' ) # # Read the pairs "Year, Population" from the file. # filename = 'bulgaria_data.txt' data = np.loadtxt ( filename ) # # Split data into separate year and population vectors. # year = data[:,0] population = data[:,1] # # Plot the data. # plt.plot ( year, population, 'mo-', linewidth = 3 ) plt.annotate ( 'Maximum', [1985,8975291] ) plt.plot ( 1985, 8975291, 'ro' ) plt.grid ( True ) plt.xlabel ( '<--- Year --->', fontsize = 16 ) plt.ylabel ( '<--- Population --->', fontsize = 16 ) plt.title ( 'The Population of Bulgaria', fontsize = 16 ) # # Save the plot as a file. # filename = 'bulgaria_plot2.png' plt.savefig ( filename ) print ( ' Graphics saved as "%s"' % ( filename ) ) # # Display the plot. # plt.show ( ) plt.close ( ) return if ( __name__ == '__main__' ): bulgaria_plot1 ( ) bulgaria_plot2 ( )