简体   繁体   English

如何在散点图上添加箱线图

[英]How to add box plots on top of scatter plot

I want to plot boxplots on top of the scattered points like this.我想在这样的散点之上绘制箱线图。 在此处输入图片说明

I know I have to bin the data into intervals first but I couldn't find the function that does all of this.我知道我必须首先将数据分成间隔,但我找不到执行所有这些操作的函数。 Sample x and y data are saved here as .npy.样本 x 和 y 数据在此处保存为 .npy。

I would look into using matplotlib.我会考虑使用 matplotlib。 Boxes can be drawn as such: https://matplotlib.org/gallery/pyplots/boxplot_demo_pyplot.html?highlight=boxplot and scatter plots can also be drawn as such: https://matplotlib.org/gallery/lines_bars_and_markers/scatter_demo2.html?highlight=scatter框可以这样绘制: https : //matplotlib.org/gallery/pyplots/boxplot_demo_pyplot.html? highlight =boxplot ,散点图也可以这样绘制: https : //matplotlib.org/gallery/lines_bars_and_markers/scatter_demo2。 html?highlight=scatter

There is a search functionality on their site, along with plenty of documentation on how to utilize their library.他们的网站上有一个搜索功能,以及关于如何使用他们的图书馆的大量文档。

As for your specific question, you can specify zorder when drawing many of the things in matplotlib, and you could use that to define your boxplots to be on top.至于你的具体问题,你可以在 matplotlib 中绘制许多东西时指定 zorder,你可以使用它来定义你的箱线图在上面。 I believe if no zorder is defined that it draws items in the order they are encountered in your program (so you could draw scatter plots and then box plots and they should appear correctly as in your diagram above!我相信如果没有定义 zorder ,它会按照它们在您的程序中遇到的顺序绘制项目(因此您可以绘制散点图,然后绘制箱线图,它们应该像上面的图表一样正确显示!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM