Python Language Making multiple plots in the same figure by superimposition similar to MATLAB


In this example, a sine curve and a cosine curve are plotted in the same figure by superimposing the plots on top of each other.

# Plotting tutorials in Python
# Adding Multiple plots by superimposition
# Good for plots sharing similar x, y limits
# Using single plot command and legend

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 2.0*np.pi, 101)
y = np.sin(x)
z = np.cos(x)

# values for making ticks in x and y axis
xnumbers = np.linspace(0, 7, 15)
ynumbers = np.linspace(-1, 1, 11)

plt.plot(x, y, 'r', x, z, 'g') # r, g - red, green colour
plt.xlabel("Angle in Radians")
plt.title("Plot of some trigonometric functions")
plt.legend(['sine', 'cosine'])
plt.axis([0, 6.5, -1.1, 1.1]) # [xstart, xend, ystart, yend]

Two Plots superimposed on the same figure