3 回答
TA贡献1854条经验 获得超8个赞
在 R 中,您可以像这样非常接近:
library(ggridges)
set.seed(69)
df <- data.frame(x = as.vector(sapply(14:10, function(i) rnorm(30, i, 2))),
group = rep(letters[1:5], each = 30))
ggplot(df, aes(x, y = group, fill = group)) +
geom_vline(aes(xintercept = 10), size = 2, color = "#5078be") +
geom_density_ridges(size = 2, aes(color = group)) +
geom_vline(aes(xintercept = 3), size = 2) +
scale_fill_manual(values = c("#8f4b4a", "#c08f33", "#e2baba", "#ffe2ae", "#83a8f1")) +
scale_colour_manual(values = c("#5c1a08", "#8c5b01", "#af8987", "#d2ab83", "#5078be")) +
theme_void() +
theme(legend.position = "none")
TA贡献1802条经验 获得超6个赞
您可以使用 z 轴来做到这一点。您仍然可以根据需要调整设计并隐藏轴等。
from scipy import exp
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits import mplot3d
def gaus(x, a, x0, sigma):
return a*exp(-(x-x0)**2/(2*sigma**2))
if __name__ == '__main__':
x = np.array([i for i in range(0, 100)])
y1 = gaus(x, 1, 50, 5)
y2 = gaus(x, 1, 45, 12)
fig = plt.figure()
ax = plt.axes(projection='3d')
ax.view_init(-90, 90)
ax.plot3D(x, y1, 100)
ax.plot3D(x, y2, 1)
plt.show()
添加回答
举报