import numpy as np import matplotlib.pyplot as plt def f(x): return x**2 + 3 def g(x): return 3*x - 1 xa = np.linspace(-2, 3, 100) plt.close('all') plt.plot(xa, f(g(xa)), xa, g(f(xa))) plt.legend(labels=('f(g(x))','g(f(x))')) plt.savefig('plot_fun_plot_funfun.pdf') plt.show()