Reputation: 721
I have a 2D objective function that evolves over time, I want to represent it in series of cascaded snapshots as layers in the following image:
I am not looking strictly for the image as above but a close representation. Is it possible in python using Matplotlib or other library? I have a 3D spline that shall pass through all these layers and hence I need to show them in cascaded figures.
Upvotes: 0
Views: 267
Reputation: 126
Using this script in the page that @Junuxx refers, making:
ys = np.repeat(3,len(xs))
instead of
ys = np.random.rand(len(xs))
and adding this:
ax.set_axis_off()
Consequently:
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.collections import PolyCollection
import matplotlib.pyplot as plt
from matplotlib import colors as mcolors
import numpy as np
fig = plt.figure()
ax = fig.gca(projection='3d')
def cc(arg):
return mcolors.to_rgba(arg, alpha=0.6)
xs = np.arange(0, 10, 0.4)
verts = []
zs = [0.0, 1.0, 2.0, 3.0]
for z in zs:
ys = np.repeat(3,len(xs))
ys[0], ys[-1] = 0, 0
verts.append(list(zip(xs, ys)))
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_xlim3d(0, 10)
ax.set_ylabel('Y')
ax.set_ylim3d(-1, 4)
ax.set_zlabel('Z')
ax.set_zlim3d(0, 1)
ax.set_axis_off()
plt.show()
I think you can achieve what you want with a little more changes
Upvotes: 2