Plot points over contour - Matplotlib / Python
If you don't provide x
and y
data corresponding to the scalar field, contour
uses integer values up to the size of the array. That is why the axes are displaying the dimension of the array. The parameters extent
should give the minimum and maximum x
and y
values; I assume this is what you mean by "data space." So the call to contour
would be:
contour(scalar_field,extent=[-4,4,-4,4])
This can be reproduced by specifying x
and y
data:
contour(numpy.linspace(-4,4,20),numpy.linspace(-4,4,20),scalar_field)
Then the contour looks exactly as in your first plot. I assume the reason this is incorrect because the min and max points are not in the right places. Based on the info you gave, this is because min_points
and max_points
which you pass to your function are indices to the array scalar_field
, so they correspond to integers, not the actual x
and y
values. Try to use these indices to access the x
and y
points by defining:
x=numpy.linspace(-4,4,20)
y=numpy.linspace(-4,4,20)
For example, if you have a min point of (0,1)
, it would correspond to (x[0], y[1])
. I think a similar thing can be done with the mgrid
, but I've never used that myself.