本文介绍了以透视方式绘制一系列以3D投影的2D图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想绘制一个似然分布,基本上是一个 NxT 矩阵,其中每一行代表每个时间步长 t(t = 0 ... T)中某个变量的分布,因此我可以可视化最大似然估计会产生的轨迹.
I'd like to plot a likelihood distribution, basically an NxT matrix, where each row represents a distribution on some variable in each timestep t (t=0...T), so I could visualize the trajectory which a Maximum Likelihood Estimation would yield.
我想象有几个2D图,一个在另一个图的前面-像这样:
I imagine several 2D plots, one in front of the other - something like this:
基于这我已经尝试过:
def TrajectoryPlot(P):
P=P[0:4]
fig = plt.figure()
ax = fig.gca(projection='3d')
def cc(arg):
return colorConverter.to_rgba(arg, alpha=0.6)
xs = np.arange(0, len(P[0]))
verts = []
zs = [0.0, 1.0, 2.0, 3.0, 4.0]
for i in range(len(P)):
print(i)
verts.append(list(zip(xs, P[i])))
poly = PolyCollection(verts, facecolors=[cc('r'), cc('g'), cc('b'),
cc('y')])
poly.set_alpha(0.7)
ax.add_collection3d(poly, zs=zs, zdir='y')
ax.set_xlabel('X')
ax.set_ylabel('Likelihood')
ax.set_zlabel('Time')
plt.show()
但这还行不通.
推荐答案
fill_between
例程还返回一个PolyCollection
对象,因此您可以使用fill_between
并使用add_collection3d
进行添加:
The fill_between
routine also returns a PolyCollection
object, so you could use fill_between
and add that using add_collection3d
:
import matplotlib.pylab as pl
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
x = np.linspace(1,5,100)
y1 = np.ones(x.size)
y2 = np.ones(x.size)*2
y3 = np.ones(x.size)*3
z = np.sin(x/2)
pl.figure()
ax = pl.subplot(projection='3d')
ax.plot(x, y1, z, color='r')
ax.plot(x, y2, z, color='g')
ax.plot(x, y3, z, color='b')
ax.add_collection3d(pl.fill_between(x, 0.95*z, 1.05*z, color='r', alpha=0.3), zs=1, zdir='y')
ax.add_collection3d(pl.fill_between(x, 0.90*z, 1.10*z, color='g', alpha=0.3), zs=2, zdir='y')
ax.add_collection3d(pl.fill_between(x, 0.85*z, 1.15*z, color='b', alpha=0.3), zs=3, zdir='y')
ax.set_xlabel('Day')
ax.set_zlabel('Resistance (%)')
这篇关于以透视方式绘制一系列以3D投影的2D图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!