I need to make multiple contours plots of several variables on the same page. I can do this with MATLAB (see below for MATLAB code). I cannot get matplotlib to show multiple legends. Any help would be much appreciated.
Python code:
import numpy as np from matplotlib import cm as cm from matplotlib import pyplot as plt delta = 0.25 x = np.arange(-3.0, 3.0, delta) y = np.arange(-2.0, 2.0, delta) X, Y = np.meshgrid(x, y) Z1 = X*np.exp(-X**2-Y**2) Z2 = Y*np.exp(-X**2-Y**2) plt.figure() CS = plt.contour(X, Y, Z1, colors='k') plt.clabel(CS, inline=1, fontsize=10) CS = plt.contour(X, Y, Z2, colors='r') plt.clabel(CS, inline=1, fontsize=10) plt.legend(['case 1', 'case 2']) plt.show()
MATLAB code:
[X,Y] = meshgrid(-2:.2:2,-2:.2:3); Z1 = X.*exp(-X.^2-Y.^2); Z2 = Y.*exp(-X.^2-Y.^2); [C,h] = contour(X,Y,Z1, 'color', 'k'); set(h,'ShowText','on','TextStep',get(h,'LevelStep')*2); hold on [C,h] = contour(X,Y,Z2, 'color', 'r'); set(h,'ShowText','on','TextStep',get(h,'LevelStep')*2); fn = {'case 1', 'case 2'}; legend(fn,'Location','NorthWest');