How to project 2d plots (e.g. boxplot) to 3d in matplotlib?

Viewed 150

I have found code to project 2d bar plots or scatter plots into 3d. For example, with the following code:

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

fig = plt.figure(figsize=(8,8))
ax = fig.add_subplot(111, projection='3d')
nbins = 50
for i, c, z in zip([0,1,2],['r', 'g', 'b', 'y'], [30, 20, 10, 0]):
    ys = np.random.normal(loc=10, scale=10, size=2000)

    hist, bins = np.histogram(ys, bins=nbins)
    xs = (bins[:-1] + bins[1:])/2
    ax.bar(xs, hist,zs=z, zdir='y', color=c, ec=c, alpha=0.8)

ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

plt.show()

enter image description here

However, I want to project other 2d plots into 3d, for example, boxplot. When I modified the code above to boxplot, I cannot use arguments including "zs=z" and "zdir='y'" to set apart 2d plots at different positions. What should I do to make boxplots into figure above? Thanks!

0 Answers
Related