简体   繁体   中英

Plotting a series of 2D plots projected in 3D in a perspectival way

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.

I imagine several 2D plots, one in front of the other - something like this:

请忽略轴标签

so far based on this I've tried:

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()

But this does not work yet.

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 (%)')

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM