DataFrames中的点盒图 [英] Dot-boxplots from DataFrames

查看:99
本文介绍了DataFrames中的点盒图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Pandas中的数据框具有 boxplot 方法,但是有什么方法可以在Pandas中创建点箱图,否则可以使用

Dataframes in Pandas have a boxplot method, but is there any way to create dot-boxplots in Pandas, or otherwise with seaborn?

用点箱图表示,是指在图中显示实际数据点(或其中的相关样本)的箱图,例如像下面的示例(在R中获得).

By a dot-boxplot, I mean a boxplot that shows the actual data points (or a relevant sample of them) inside the plot, e.g. like the example below (obtained in R).

推荐答案

有关与OP的问题(与Pandas有关)的更精确答案:

For a more precise answer related to OP's question (with Pandas):

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

data = pd.DataFrame({ "A":np.random.normal(0.8,0.2,20),
                      "B":np.random.normal(0.8,0.1,20), 
                      "C":np.random.normal(0.9,0.1,20)} )

data.boxplot()

for i,d in enumerate(data):
    y = data[d]
    x = np.random.normal(i+1, 0.04, len(y))
    plt.plot(x, y, mfc = ["orange","blue","yellow"][i], mec='k', ms=7, marker="o", linestyle="None")

plt.hlines(1,0,4,linestyle="--")

旧版本(更通用):

使用matplotlib:

With matplotlib :

import numpy as np
import matplotlib.pyplot as plt

a = np.random.normal(0,2,1000)
b = np.random.normal(-2,7,100)
data = [a,b]

plt.boxplot(data) # Or you can use the boxplot from Pandas

for i in [1,2]:
    y = data[i-1]
    x = np.random.normal(i, 0.02, len(y))
    plt.plot(x, y, 'r.', alpha=0.2)

给出以下内容:

灵感来自希望这会有所帮助!

这篇关于DataFrames中的点盒图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆