从matplotlib中的数组绘制隐式曲面 [英] Plot implicit surface from arrays in matplotlib

查看:101
本文介绍了从matplotlib中的数组绘制隐式曲面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有四个一维numpy数组,分别为xyzvalue.当且仅当value[i]=0时,点(x[i],y[i],z[i])是表面的一部分.有没有办法在matplotlib中绘制此表面?

Suppose I have four one-dimensional numpy arrays, x, y, z, and value. The point (x[i],y[i],z[i]) is part of the surface if and only if value[i]=0. Is there a way to plot this surface in matplotlib?

推荐答案

您可以在numpy数组x,y,z上应用布尔索引,如下所示.

you can apply boolean indexing on numpy arrays x,y,z like shown below.

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

x = np.random.random(10)
y = np.random.random(10)
z = np.random.random(10)
value = np.random.randint(2,size=10)

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(x[value==0], y[value==0], z[value==0])
plt.show()

在此示例中,显示了散点图,但您可以对表面图执行相同的操作.

In this example, scatter plot is shown but you can do the same thing for surface plot.

这篇关于从matplotlib中的数组绘制隐式曲面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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