'''Python file for Experiment 2.8 and Figure 2.6'''

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0,1.2,0.05)
y = x**2

fig = plt.figure() # produces a figure window
                
plt.plot(x, y, 'k')   # plot of the graph of y = x**2
plt.plot(y, x, 'k')   # plot of the graph of the inverse function

plt.plot(x, x, 'k--')   # plot of diagonal, dashed line style

        
''' annotations with font size and position '''        
plt.text(1.3,0,'x', fontsize = 14,
         horizontalalignment='left', verticalalignment='center')
plt.text(0,1.3,'y', fontsize = 14,
         horizontalalignment='center', verticalalignment='center')

plt.text(0.65, 0.25, 'y = f(x)', fontsize = 14,
         horizontalalignment='left', verticalalignment='center')
plt.text(0.35, 0.85, 'y = f'+'$^{-1}$'+'(x)', fontsize = 14, 
         horizontalalignment='center', verticalalignment='center')

''' axes '''
plt.plot([-0.2, 1.25],[0,0],'k')
plt.plot([0, 0],[-0.2, 1.2],'k')

''' arrows '''
plt.plot(1.25,0,'k>')
plt.plot(0,1.2,'k^')

''' scaling of visible axis window '''
plt.axis([-0.3,1.5,-0.3,1.5])

plt.show()