#! /usr/bin/env python3 # def price_subplots ( ): #*****************************************************************************80 # ## price_subplots() reads price data and makes 6 subplots. # import matplotlib.pyplot as plt import numpy as np print ( '' ) print ( 'pricer_subplots():' ) print ( ' Make 6 subplots of price data over time.' ) # # Read the data. # price = np.loadtxt ( 'price_data.txt' ) month_num = price.shape[0] month = np.arange ( month_num ) label = [ \ 'Month', 'Year', 'Bananas', 'Oranges', 'Bread', \ 'Tomatoes', 'Chicken', 'Electricity', 'Eggs', 'Gasoline', \ 'Beef', 'Heating gas', 'Milk' ]; # # Plot the data. # m = 2 n = 3 fig, ax = plt.subplots ( m, n ) fig.suptitle ( '2x3 Price Subplots' ) # # Create 6 plots: # # (0,0) (0,1) (0,2) # (1,0) (1,1) (1,2) # k = 1 for i in range ( 0, m ): for j in range ( 0, n ): k = k + 1 ax[i,j].plot ( month, price[:,k] ) ax[i,j].set_title ( label[k] ) filename = 'price_subplots.png' plt.savefig ( filename ) print ( ' Graphics saved as "%s"' % ( filename ) ) plt.show ( ) plt.close ( ) # # Terminate. # print ( '' ) print ( 'iris_subplots():' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): price_subplots ( )