带有包含分位数的数据框的 Seaborn 箱线图
Seaborn boxplot with dataframe containting quantiles
如果我有一个分位数已知的数据框,我可以让 Seaborn 箱线图在每个百分位数上显示小菱形吗?
test = pd.DataFrame(
{
"id": ["A", "A", "A", "B", "B", "B", "C", "C", "C"],
"q": [0.16, 0.5, 0.84, 0.16, 0.5, 0.84, 0.16, 0.5, 0.84],
"value": [0.2, 0.56, 0.84, 0.14, np.nan, 0.78, 0.125, 0.4, 0.62],
}
)
display(test)
sns.boxplot(data=test, x="value", y="id")
也许这对你有帮助:
import seaborn as sns
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
test = pd.DataFrame(
{
"id": ["A", "A", "A", "B", "B", "B", "C", "C", "C"],
"q": [0.16, 0.5, 0.84, 0.16, 0.5, 0.84, 0.16, 0.5, 0.84],
"value": [0.2, 0.56, 0.84, 0.14, np.nan, 0.78, 0.125, 0.4, 0.62],
}
)
display(test)
g = sns.boxplot(data=test, x="value", y="id")
for index, row in test.iterrows():
if(row['id']=='A'):
g.plot((row['q']), (row['id']), 'o', color='y')
if(row['id']=='B'):
g.plot((row['q']), (row['id']), 'o', color='b')
if(row['id']=='C'):
g.plot((row['q']), (row['id']), 'o', color='r')
plt.show()
输出:
如果我有一个分位数已知的数据框,我可以让 Seaborn 箱线图在每个百分位数上显示小菱形吗?
test = pd.DataFrame(
{
"id": ["A", "A", "A", "B", "B", "B", "C", "C", "C"],
"q": [0.16, 0.5, 0.84, 0.16, 0.5, 0.84, 0.16, 0.5, 0.84],
"value": [0.2, 0.56, 0.84, 0.14, np.nan, 0.78, 0.125, 0.4, 0.62],
}
)
display(test)
sns.boxplot(data=test, x="value", y="id")
也许这对你有帮助:
import seaborn as sns
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
test = pd.DataFrame(
{
"id": ["A", "A", "A", "B", "B", "B", "C", "C", "C"],
"q": [0.16, 0.5, 0.84, 0.16, 0.5, 0.84, 0.16, 0.5, 0.84],
"value": [0.2, 0.56, 0.84, 0.14, np.nan, 0.78, 0.125, 0.4, 0.62],
}
)
display(test)
g = sns.boxplot(data=test, x="value", y="id")
for index, row in test.iterrows():
if(row['id']=='A'):
g.plot((row['q']), (row['id']), 'o', color='y')
if(row['id']=='B'):
g.plot((row['q']), (row['id']), 'o', color='b')
if(row['id']=='C'):
g.plot((row['q']), (row['id']), 'o', color='r')
plt.show()
输出: