- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我在使用 Seaborn 在 Python 中创建的绘图中添加误差条时遇到了一些困难。
我目前有一个“csv”格式的数据框;
TSMdatabase = 'TSMvsRunmaster.csv';
tsmdf = pd.read_csv(TSMdatabase, sep=',');
Dataframe 的标题格式如下:
Run,TSMX_Value,TSMX_Error,TSMX+1_Value,TSMX+1_Error,Source
然后我使用 for 循环读取不同的 TSM 值:
TSM = ['001', '002', '003', '004', '010', '011', '012',
'013', '016', '017', '101', '102', '104', '105', '106']
for x in TSM:
tsm = x
最后我密谋给我:
plt.figure()
sns.set_style("darkgrid")
ax = sns.stripplot(x="Run", y='TSM'+str(tsm)+'_Value', hue="Source", data=tsmdf,
jitter=True, palette="Set2", split=True)
plt.xticks(rotation=40)
plt.title('Run TSM'+str(tsm)+' Comparison')
plt.show()
某些 TSM 的绘图没有错误栏
如果我随后尝试添加错误栏,我最终会在每个子数据集的中间只有一个错误栏:
每个来源,Python 和 Matlab 实际上在数据框中都有自己的错误!
有没有人有什么想法!真的非常感谢!
最佳答案
绘制均值 + 误差比 sns.stripplot()
更适合 sns.pointplot()
。这在 Seaborn 文档中有说明:
sns.pointplot Show point estimates and confidence intervals using scatter plot glyphs. A point plot represents an estimate of central tendency for a numeric variable by the position of scatter plot points and provides some indication of the uncertainty around that estimate using error bars.
sns.stripplot Draw a scatterplot where one variable is categorical. A strip plot can be drawn on its own, but it is also a good complement to a box or violin plot in cases where you want to show all observations along with some representation of the underlying distribution.
如果您可以访问所有观察结果,而不仅仅是均值 + 误差,则可以通过以下方式简单地实现您想要的:
import seaborn as sns
%matplotlib inline
tips = sns.load_dataset('tips')
sns.pointplot('sex', 'tip', hue='smoker',
data=tips, dodge=True, join=False)
您可以使用 ci
参数更改默认 95% 的置信区间类型:
sns.pointplot('sex', 'tip', hue='smoker',
data=tips, dodge=True, join=False, ci='sd')
在上面,Seaborn 计算了误差和集中趋势的测量值。如果您已经预先计算了这些,那就有点棘手了,因为目前无法将 sns.pointplot()
与预先计算的误差条一起使用。在使用 sns.pointplot()
绘制均值后,我使用 plt.errorbar()
添加了错误:
ax = sns.pointplot('sex', 'tip', hue='smoker',
data=tips, dodge=True, join=False, ci=None)
# Find the x,y coordinates for each point
x_coords = []
y_coords = []
for point_pair in ax.collections:
for x, y in point_pair.get_offsets():
x_coords.append(x)
y_coords.append(y)
# Calculate the type of error to plot as the error bars
# Make sure the order is the same as the points were looped over
errors = tips.groupby(['smoker', 'sex']).std()['tip']
colors = ['steelblue']*2 + ['coral']*2
ax.errorbar(x_coords, y_coords, yerr=errors,
ecolor=colors, fmt=' ', zorder=-1)
您也可以直接对整个图使用 matplotlib,如果您手动提供 x 位置,类似于 this example .
关于python - Seaborn 和 Stripplot 的误差线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43159528/
我有一个任务,必须求解线性方程组 Ax =B,其中 A 是 10000 量级的稀疏矩阵。我正在使用 csparse 来求解它。在我的初始实现中,出于演示目的,A 是 3*3 阶单位矩阵,B ={1,2
我正在尝试训练随机森林模型,但出现以下错误。我需要对分类模型使用不同的设置来解决 RMSE 问题吗?我尝试将“好”转换为一个因素,但这引发了一个新错误。 错误: Error in train.defa
当使用 %Lf 打印时,一个大的 double 值被改变以下组合的值给出正确的结果小数点前9位/小数点后6位例如用 %Lf 打印的小数点前 9 位的值输入:3435537287.32输出:343553
我正在尝试实现高度为 100% 的重复垂直背景。遗憾的是,每当我试图通过仅添加纯文本来扩展页面的高度时,具有 100% 高度和背景重复的背景就会被切掉。我只想让背景重复。这是屏幕截图。 http://
所以我有: t = [0.0, 3.0, 5.0, 7.2, 10.0, 13.0, 15.0, 20.0, 25.0, 30.0, 35.0] U = [12.5, 10.0, 7.6, 6.0,
我使用了 Nister 的 5 点法来计算基本矩阵。使用 RANSAC 和 Sampson 错误阈值进一步改进了异常值拒绝。我随机选择 5 个点集,估计基本矩阵并评估匹配向量的 Sampson 误差。
为分类问题运行 gbm 函数时。我收到以下错误: Error in res[flag, ] 0.5,1,0) table(pred,df$Group) pred 0 1 0 98
我使用 Angular ngTagsInput,我的列表如下: [{text: "4353453"}, {text: "453453"}, {text: "4534534"}, {text: "53
我正在尝试 Angular 问题,并且坚持理解错误,这意味着如果我无法理解错误,我将无法前进,例如 zone.js:654 Unhandled Promise rejection: Failed to
我有一个关于在线性混合模型上运行事后测试的问题: 我正在 lme4 中运行一个线性混合模型,分为 3 组,每组 5 条蛇,每组采用不同的通气率 (Vent),在不同的位置进行测量时间点 (Time),
我正在尝试运行逻辑回归并不断收到“NA”错误。问题是它说有 NA 的列没有 NA,全是 0 或 1。我的代码如下: #V1=race, V2=momcounts of breast cancer, V
我在输出之间得到随机 NaN。 Random Temp:61.816288952756864 'F Random Temp:NaN 'F Random Temp:NaN 'F Random Temp:
我正在尝试通过取下平板框架来减少我的大炮天文图像,这很有效。但它使所有值都非常低(所以几乎是黑色图片),这就是为什么我也想将其乘以平均值。然而这给了我一个错误。 (虽然没有乘法它也能工作。) 有人知道
我正在使用 adaboost 构建一个模型,并尝试让 roc 图发挥作用。这是我的代码: ens=fitensemble(X,y,'AdaBoostM1',100,'Tree'); [ytest, s
当尝试使用 Protractor 和 Angular Testing 模态窗口上的可见按钮时,我收到以下错误: UnknownError: unknown error: Element is not
我正在尝试使用命令通过 Yeoman 构建 Angular “哟有 Angular ” 一切正常,直到我到达 tmp 目录: npm ERR! Error: EACCES, mkdir '/home/
我在使用 OpenCV 计算立体声对的校正时遇到一些问题:stereoCalibrate 返回高均方根误差,我得到了错误的校正对。我尝试了我的整改程序和 opencv 提供的 stereo_calib
我在 Mac (OS X 10.9) 上安装了 Yeoman,并且正在尝试运行 yo angular。 我收到以下错误: path.js:384 throw new TypeError('Ar
我有运行循环的线程。我需要该循环每 5 毫秒运行一次(1 毫秒错误)。我知道 Sleep() 函数并不精确。 你有什么建议吗? 更新。我不能用其他方式做到这一点。在循环结束时,我需要某种 sleep
我一直在试验 FFT 算法。我使用 NAudio 以及来自互联网的 FFT 算法的工作代码。根据我对性能的观察,生成的音调不准确。 我将 MIDI(从 GuitarPro 生成)转换为 WAV 文件(
我是一名优秀的程序员,十分优秀!