使用不带griddata()的1D数组的2D图 [英] 2D plot using 1D arrays without griddata()

查看:49
本文介绍了使用不带griddata()的1D数组的2D图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用matplotlib绘制两个变量的函数.函数存储在三个1d数组XYF中,分别对应于x坐标,y坐标和函数值.是否可以将这些数据绘制为等高线图?在我看到griddata()解决方案之前,但是我想避免进行插值,因为x和y坐标已经很好地定义了.

I am trying to plot the function of two variables using matplotlib. The function is stored in three 1d arrays X, Y and F corresponding to x-coordinate, y-coordinate and the value of the function. Is it possible to plot these data as a contour plot? Before I saw the solution with griddata(), but I would like to avoid interpolating since x and y coordinates are already well defined.

推荐答案

看看轮廓matplotlib文档的演示.正如您所说的,您可以精确地在任意给定点计算函数F:

Take a look at the contour demo of the matplotlib docs. Since you say you can calculate your function F exactly at any given point:

delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-2.0, 2.0, delta)
X, Y = np.meshgrid(x, y)
F = your_function(X.ravel(), Y.ravel())
CS = plt.contour(X, Y, F.reshape(X.shape))
plt.clabel(CS, inline=1, fontsize=10)

这篇关于使用不带griddata()的1D数组的2D图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆