Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

several contour plots in the same figures

I have several 3d functions. I would like two plot the contour plots of them in the same figure to see the difference between them. I expect to see some crossings between contours of two functions. Here is my code:

plt.contour(xi, yi, F)
plt.contour(xi, yi, F1)        
plt.show()

But, it seems that the first one is erased at the end, since I see only one function without any crossing of contours. Is it possible to figure this out somehow?

like image 810
freude Avatar asked May 25 '13 15:05

freude


1 Answers

I did a quick test and I see both contours. The fact that they use common colors can be misleading. Try this :

plt.contour(xi, yi, F, colors='red')
plt.contour(xi, yi, F1, colors='blue')
plt.show()

A self-contained example :

import matplotlib.pyplot as plt
import numpy as np

X = np.linspace(0, 1, 10)
Y = np.linspace(0, 1, 10)

x,y = np.meshgrid(X,Y)

f1 = np.cos(x*y)
f2 = x-y

plt.contour(x,y,f2,colors='red')
plt.contour(x,y,f1,colors='blue')
plt.show()
like image 87
deufeufeu Avatar answered Sep 29 '22 15:09

deufeufeu