several contour plots in the same figures

10,778

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()
Share:
10,778

Related videos on Youtube

freude
Author by

freude

I am working in the field of computational physics and scientific software development.

Updated on June 04, 2022

Comments

  • freude
    freude almost 2 years

    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?

    • deufeufeu
      deufeufeu almost 11 years
      plt is the usual way to import matplotlib.pyplot. So it's a module and it's instanced at import.
  • freude
    freude almost 11 years
    I will try, but, independently of colors, there should be crossings of contours in my case which i see in octave.
  • deufeufeu
    deufeufeu almost 11 years
    I've added an example script so you can check for yourself.
  • freude
    freude almost 11 years
    Yes, that's working. thank you! Your answer has helped me to realize that I forgot to change one of the functions so I used two equivalent ones.

Related