0

My data is regularly spaced, but not quite a grid - each row of points is slightly offset from the one below.

The data is in the form of 3 1D arrays, x, y, z, with each index corresponding to a point. It is smoothly varying data - approximately Gaussian.

The point density is quite high. What is the best way to plot this data?

I tried meshgrid, but it gives me some bad contours through regions that have no data points near the contour's value.

I have tried rbf interpolation according to this post: Python : 2d contour plot from 3 lists : x, y and rho? but this just gives me nonsense - all the contours are on one edge - does not reflect the data at all.

Any other ideas for what I can try. Maybe I should be using some sort of nearest neighbour interpolation? Here is a picture of about a 1/4 of my data points: https://i.stack.imgur.com/s8Ulf.jpg

I'm surprised it is causing me such difficulty - it seems like it should be fairly easy to plot.

Community
  • 1
  • 1
Tom
  • 223
  • 1
  • 2
  • 11

2 Answers2

1

The easiest way to plot ungridded data is probably tricontour or tricontourf (a filled tricontour plot).

Having 1D arrays of the x, y and z coordinates x, y and z, you'd simply call

plt.tricontourf(x,y,z, n, ...)

to obtain n levels of contours.

The other quick method is to interpolate on a grid using matplotlib.mlab.griddata to obtain a regular grid from the irregular points.

Both methods are compared in an example on the matplotlib page: Tricontour vs. griddata

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
-1

Found the answer: needed to rescale my data.

Tom
  • 223
  • 1
  • 2
  • 11
  • This is not an answer and additionally completely useless for everyone else reading this question. Either you explain in detail how "rescaling" helped you solve the problem, which might then be interesting and/or helpful for others, or you delete those eight words. – ImportanceOfBeingErnest Feb 27 '17 at 20:42
  • Apologies! One axis of the data had numbers of order 1e6. Rescaling these to order unity (unexpectedly?) solved the problem. I have since switched to script.interpolate.Rbf , which I have found to be much better. – Tom Sep 17 '17 at 11:08