如何制作这些顺序 histogram/density 估计图
How to make these sequential histogram/density estimates plots
有谁知道如何制作这些顺序 histogram/density 估计图 (source) in R
or Python
? I think I've also heard them called "waterfall" plots and "cascade" plots. It also kind of looks like the cover art of Joy Division's "Unknown Pleasures" album (c.f. that very popular t-shirt)。
这是另一个例子,来自a book 我喜欢:
作为 python 来自 [matplotlib 示例][1]https://matplotlib.org/examples/mplot3d/polys3d_demo.html
的示例
"""
=============================================
Generate polygons to fill under 3D line graph
=============================================
Demonstrate how to create polygons which fill the space under a line
graph. In this example polygons are semi-transparent, creating a sort
of 'jagged stained glass' effect.
"""
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.random.rand(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)
plt.show()
想法是逐行创建3d线图,让每条线定义一个半透明颜色的多边形,以达到很好的效果。为了使它看起来更像您示例中的那个,只需切换颜色值并使线条之间的偏移更小一些。
编辑:
我在原代码的基础上给大家做了一个例子:
xs = np.arange(0, 10, 0.4)
verts = []
zs = np.arange(0, 5, 0.2)
for z in zs:
r=[int(np.random.normal(5,5)) for i in range(0,10000)]
ys = np.histogram(r,len(xs))[0]/10000
ys[0], ys[-1] = 0, 0
verts.append(list(zip(xs, ys)))
poly = PolyCollection(verts,facecolor='white')
poly.set_edgecolor('black')
这应该非常接近您正在寻找的效果。
有谁知道如何制作这些顺序 histogram/density 估计图 (source) in R
or Python
? I think I've also heard them called "waterfall" plots and "cascade" plots. It also kind of looks like the cover art of Joy Division's "Unknown Pleasures" album (c.f. that very popular t-shirt)。
这是另一个例子,来自a book 我喜欢:
作为 python 来自 [matplotlib 示例][1]https://matplotlib.org/examples/mplot3d/polys3d_demo.html
的示例 """
=============================================
Generate polygons to fill under 3D line graph
=============================================
Demonstrate how to create polygons which fill the space under a line
graph. In this example polygons are semi-transparent, creating a sort
of 'jagged stained glass' effect.
"""
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.random.rand(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)
plt.show()
想法是逐行创建3d线图,让每条线定义一个半透明颜色的多边形,以达到很好的效果。为了使它看起来更像您示例中的那个,只需切换颜色值并使线条之间的偏移更小一些。
编辑: 我在原代码的基础上给大家做了一个例子:
xs = np.arange(0, 10, 0.4)
verts = []
zs = np.arange(0, 5, 0.2)
for z in zs:
r=[int(np.random.normal(5,5)) for i in range(0,10000)]
ys = np.histogram(r,len(xs))[0]/10000
ys[0], ys[-1] = 0, 0
verts.append(list(zip(xs, ys)))
poly = PolyCollection(verts,facecolor='white')
poly.set_edgecolor('black')
这应该非常接近您正在寻找的效果。