如何制作带有前景和背景的线图?

你究竟如何在一个图中制作多条线的线图,但每条线都设置在背景中,几乎就像是 3D 的?

请参阅下面的示例图片:

http://img.mukewang.com/64477e22000143a306560126.jpg

http://img4.mukewang.com/64477e2b0001594d06580133.jpg

慕雪6442864
浏览 87回答 3
3回答

哔哔one

在 R 中,您可以像这样非常接近:library(ggridges)set.seed(69)df <- data.frame(x = as.vector(sapply(14:10, function(i) rnorm(30, i, 2))),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;group = rep(letters[1:5], each = 30))ggplot(df, aes(x, y = group, fill = group)) +&nbsp;&nbsp; geom_vline(aes(xintercept = 10), size = 2, color = "#5078be") +&nbsp; geom_density_ridges(size = 2, aes(color = group)) +&nbsp; geom_vline(aes(xintercept = 3), size = 2) +&nbsp; scale_fill_manual(values = c("#8f4b4a", "#c08f33", "#e2baba", "#ffe2ae", "#83a8f1")) +&nbsp; scale_colour_manual(values = c("#5c1a08", "#8c5b01", "#af8987", "#d2ab83", "#5078be")) +&nbsp; theme_void() +&nbsp; theme(legend.position = "none")

白衣染霜花

R如果你想在检查包中做那种情节(山脊线情节)ggridges。这将向您展示一堆很酷的例子:browseVignettes("ggridges")

呼啦一阵风

您可以使用 z 轴来做到这一点。您仍然可以根据需要调整设计并隐藏轴等。from scipy import expimport matplotlib.pyplot as pltimport numpy as npfrom mpl_toolkits import mplot3ddef gaus(x, a, x0, sigma):&nbsp; &nbsp; return a*exp(-(x-x0)**2/(2*sigma**2))if __name__ == '__main__':&nbsp; &nbsp; x = np.array([i for i in range(0, 100)])&nbsp; &nbsp; y1 = gaus(x, 1, 50, 5)&nbsp; &nbsp; y2 = gaus(x, 1, 45, 12)&nbsp; &nbsp; fig = plt.figure()&nbsp; &nbsp; ax = plt.axes(projection='3d')&nbsp; &nbsp; ax.view_init(-90, 90)&nbsp; &nbsp; ax.plot3D(x, y1, 100)&nbsp; &nbsp; ax.plot3D(x, y2, 1)&nbsp; &nbsp; plt.show()
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python