1from matplotlib import pyplot as plt
2plt.plot([0, 1, 2, 3, 4, 5], [0, 1, 4, 9, 16, 25])
3plt.show()
1import matplotlib.pyplot as plt
2fig = plt.figure(1) #identifies the figure
3plt.title("Y vs X", fontsize='16') #title
4plt.plot([1, 2, 3, 4], [6,2,8,4]) #plot the points
5plt.xlabel("X",fontsize='13') #adds a label in the x axis
6plt.ylabel("Y",fontsize='13') #adds a label in the y axis
7plt.legend(('YvsX'),loc='best') #creates a legend to identify the plot
8plt.savefig('Y_X.png') #saves the figure in the present directory
9plt.grid() #shows a grid under the plot
10plt.show()
1import matplotlib.pyplot as plt
2plt.plot([1, 2, 3, 4], [1, 4, 9, 16])
3plt.show()
1>>> rng = np.arange(50)
2>>> rnd = np.random.randint(0, 10, size=(3, rng.size))
3>>> yrs = 1950 + rng
4
5>>> fig, ax = plt.subplots(figsize=(5, 3))
6>>> ax.stackplot(yrs, rng + rnd, labels=['Eastasia', 'Eurasia', 'Oceania'])
7>>> ax.set_title('Combined debt growth over time')
8>>> ax.legend(loc='upper left')
9>>> ax.set_ylabel('Total debt')
10>>> ax.set_xlim(xmin=yrs[0], xmax=yrs[-1])
11>>> fig.tight_layout()
12