Python - Problems contour plotting offset grid of data

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 05:48:04

问题


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: http://imgur.com/a/b00R6

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


回答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




回答2:


Found the answer: needed to rescale my data.



来源:https://stackoverflow.com/questions/42494642/python-problems-contour-plotting-offset-grid-of-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!