1

I would like to make a 2D contour plot given 3 numpy arrays of same size X Y Z with (X,Y) the coordinates and Z the value at (X,Y).

Now, the function plt.contour seems to work only with a grid, and values at the intersection of the grid, and takes as input a rectangular grid only with 2D matrices as input.

see http://matplotlib.org/examples/pylab_examples/contour_demo.html

If the input for that function is (XX,YY,ZZ) then XX is a 2D rectangular array where every line is the same and every column is constant, while YY is a 2D rectangular array where every column is the same, and every line is constant.

Now, what function should I use, or what procedure should I follow, if I want to make the contour plot when the input values are NOT values taken on a grid?

thanks

1 Answer 1

1

Try to use plt.tricontour: http://matplotlib.org/api/pyplot_api.html?highlight=tricontour#matplotlib.pyplot.tricontour

It draws contours on an unstructured triangular grid.

Little example:

import numpy as np
import matplotlib.pyplot as plt
x = np.random.rand(100)
y = np.random.rand(100)
z = x**2+np.sin(y)*y
f, ax = plt.subplots(1,1)
ax.tricontour(x,y,z)
ax.plot(x,y, 'r. ')
plt.show()

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.