- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这似乎是一个微不足道的问题,但我已经搜索了一段时间,似乎找不到答案。它似乎也应该成为这些软件包的标准部分。有谁知道是否有一种标准方法可以在seaborn中的分布图之间包含统计注释?
例如,在两个方框图或群图之间?
最佳答案
大括号/括号可以直接用 matplotlib.pyplot.plot
绘制或matplotlib.axes.Axes.plot
,并且可以使用 matplotlib.pyplot.text
添加注释或matplotlib.axes.Axes.text
.
seaborn
分类图的索引为 0,而默认情况下,matplotlib
和 pandas
的箱线图从 range( 1, N+1)
,可以通过positions
参数进行调整。
seaborn
是 matplotlib
的高级 API,pandas.DataFrame.plot
使用 matplotlib
作为默认后端。
import seaborn as sns
import matplotlib.pyplot as plt
# dataframe in long form for seaborn
tips = sns.load_dataset("tips")
# dataframe in wide form for plotting with pandas.DataFrame.plot
df = tips.pivot(columns='day', values='total_bill')
# data as a list of lists for plotting directly with matplotlib (no nan values allowed)
data = [df[c].dropna().tolist() for c in df.columns]
seaborn
sns.boxplot(x="day", y="total_bill", data=tips, palette="PRGn")
# statistical annotation
x1, x2 = 2, 3 # columns 'Sat' and 'Sun' (first column: 0, see plt.xticks())
y, h, col = tips['total_bill'].max() + 2, 2, 'k'
plt.plot([x1, x1, x2, x2], [y, y+h, y+h, y], lw=1.5, c=col)
plt.text((x1+x2)*.5, y+h, "ns", ha='center', va='bottom', color=col)
plt.show()
pandas.DataFrame.plot
ax = df.plot(kind='box', positions=range(len(df.columns)))
x1, x2 = 2, 3
y, h, col = df.max().max() + 2, 2, 'k'
ax.plot([x1, x1, x2, x2], [y, y+h, y+h, y], lw=1.5, c=col)
ax.text((x1+x2)*.5, y+h, "ns", ha='center', va='bottom', color=col)
matplotlib
plt.boxplot(data, positions=range(len(data)))
x1, x2 = 2, 3
y, h, col = max(map(max, data)) + 2, 2, 'k'
plt.plot([x1, x1, x2, x2], [y, y+h, y+h, y], lw=1.5, c=col)
plt.text((x1+x2)*.5, y+h, "ns", ha='center', va='bottom', color=col)
<小时/>
tips.head()
total_bill tip sex smoker day time size
0 16.99 1.01 Female No Sun Dinner 2
1 10.34 1.66 Male No Sun Dinner 3
2 21.01 3.50 Male No Sun Dinner 3
3 23.68 3.31 Male No Sun Dinner 2
4 24.59 3.61 Female No Sun Dinner 4
df.head()
day Thur Fri Sat Sun
0 NaN NaN NaN 16.99
1 NaN NaN NaN 10.34
2 NaN NaN NaN 21.01
3 NaN NaN NaN 23.68
4 NaN NaN NaN 24.59
数据
[[27.2, 22.76, 17.29, ..., 20.53, 16.47, 18.78],
[28.97, 22.49, 5.75, ..., 13.42, 16.27, 10.09],
[20.65, 17.92, 20.29, ..., 29.03, 27.18, 22.67, 17.82],
[16.99, 10.34, 21.01, ..., 18.15, 23.1, 15.69]]
关于python - 如何插入统计注释(星号或 p 值),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36578458/
*args 和 **kwargs 是什么意思? def foo(x, y, *args): def bar(x, y, **kwargs): 最佳答案 *args 和 **kwargs 是一个常见的惯
*args 和 **kwargs 是什么意思? def foo(x, y, *args): def bar(x, y, **kwargs): 最佳答案 *args 和 **kwargs 是一个常见的惯
*args 和 **kwargs 是什么意思? def foo(x, y, *args):def bar(x, y, **kwargs): 最佳答案
在python文档中2.4.3. Formatted string literals ,似乎可以在 f 字符串的 {} 中写一个星号后跟一个表达式,但我找不到如何使用它。 那是什么以及如何使用它?它是
这些函数定义中的*args和**kwargs是什么意思? def foo(x, y, *args): pass def bar(x, y, **kwargs): pass 参见Wha
这些函数定义中的*args和**kwargs是什么意思? def foo(x, y, *args): pass def bar(x, y, **kwargs): pass 参见Wha
这个问题在这里已经有了答案: Delegated yield (yield star, yield *) in generator functions (3 个答案) 关闭 6 年前。 假设我创建了
我有时注意到使用 *偶尔搜索光标下的单词会有略微不同的行为(通常是当我在不同的计算机之间切换时)。问题是当我搜索前面有 * 的单词时(如 c++ 指针)。例如: MyPointer *foo; ...
This question already has answers here: Keyword only parameter (1个答案) Python documentation for os.re
这是我的数据: dput(dt) structure(c(15236000, 0, 0, 0, 0, 36722900, 45971100, 0, 0, 0, 0, 99067
所以我有一个看起来像这样但有 6k 行的数据框: AWC, LocationID 333, *Yukon 485, *Lewis Rich 76, *Kodiak 666, Kodiak 54, *R
我有一个简单的问题。我想列出我们可以使用关键字星号(或星号)* 的所有场景。 我只知道这些场景: Select * from Customers; Select Count(*) from Custo
瑞安·贝茨的Railscast about git ,他的 .gitignore 文件包含以下行: tmp/**/* 使用双星号后跟一个星号的目的是什么:**/*?简单地使用 tmp/* 而不是 tm
我想以这种方式选择带有 class="x"的元素的所有后代元素: .x * { color: red; } a b
这个问题在这里已经有了答案: What does ** (double star/asterisk) and * (star/asterisk) do for parameters? (25 个答案
最近我在 Programming Paradigms 上看到了这个视频和教授。使用星号、星形和符号等术语。 这就是他如何使用这些运算符的: int i = 37; float f = *(float*
我尝试在自定义按钮中居中对齐符号星号 (*),但我做不到。 如何像其他字符一样垂直居中对齐(1,2...)? 最佳答案 只需使用不同的字符。除了 * (ASTERISK U+002A),还有许多其他类
结论 概括的来说,就是对修饰的变量进行拆分, 对修饰的形式参数进行参数聚集。 单*号,将被修饰的变量按元素方式拆分, 对修饰的形式参数进行参数聚集。 双**号,将被修饰的变量按键值对进行拆分, 对
如果我想保持功能,并且不想在中间使用 *,那么等效的替代函数是什么?例如, import operator as op print(op.eq(*map(str.upper, ['a', 'A']))
我窥视 ng2-dropdown 我可以看到(ng2-dropdown-menu.ts) 除其他事项外 transition('hidden => visible', [
我是一名优秀的程序员,十分优秀!