python 3d绘图 范围_python – 在3D绘图中绘制所有三个轴上的分布轮廓

我在三维空间中有一堆点,并估计了这些点上的一些分布(也在3D空间中;使用

kernel density estimation虽然这与这个问题无关).我想将该分布的投影绘制为所有三个轴(x,y和z)上的等高线图.对于z轴执行此操作非常简单(即投影到具有相同z坐标的平面上):

import numpy as np

import scipy as sp

import scipy.stats

import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import axes3d

# generate some points of a 3D Gaussian

points = np.random.normal(size=(3, 50))

# do kernel density estimation to get smooth estimate of distribution

# make grid of points

x, y, z = np.mgrid[-4:4:100j, -4:4:100j, -4:4:100j]

kernel = sp.stats.gaussian_kde(points)

positions = np.vstack((x.ravel(), y.ravel(), z.ravel()))

density = np.reshape(kernel(positions).T, x.shape)

# now density is 100x100x100 ndarray

# plot points

ax = plt.subplot(projection='3d')

ax.plot(points[0,:], points[1,:], points[2,:], 'o')

# plot projection of density onto z-axis

plotdat = np.sum(density, axis=2)

plotdat = plotdat / np.max(plotdat)

plotx, ploty = np.mgrid[-4:4:100j, -4:4:100j]

ax.contour(plotx, ploty, plotdat, offset=-4)

ax.set_xlim((-4, 4))

ax.set_ylim((-4, 4))

ax.set_zlim((-4, 4))

wKUua.png

但是,对其他轴执行此操作似乎未在Matplotlib中实现.如果我使用this example中概述的方法,并指定zdir关键字参数:

# plot projection of density onto x-axis

plotdat = np.sum(density, axis=0)

plotdat = plotdat / np.max(plotdat)

ploty, plotz = np.mgrid[-4:4:100j, -4:4:100j]

ax.contour(ploty, plotz, plotdat, offset=-4, zdir='x')

轮廓的生成是“沿另一个切片”完成的,所以说:

zAr1O.png

虽然我想要这样的东西(糟糕的油漆技能;希望这个想法很清楚):

75WAP.png

我想到的一个选项是沿着默认的zdir =’z’生成轮廓,然后在3D空间中旋转生成的曲线,但我不知道如何处理它.我会非常感谢任何指针!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值