简体   繁体   中英

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.

I would look into using 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

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. 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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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