对添加到条带图中的 errorbar() 的查询 [英] Query on errorbar() added to stripplot

查看:51
本文介绍了对添加到条带图中的 errorbar() 的查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力为我的分类变量 (x=Type) 获得所需的误差条,具有两个不同的标记形状(每个类别 A 和 B)和误差条颜色与相应标记颜色的颜色匹配(即 palette = dict(A ="k",B ="r"))

I've been struggling to get desired errorbars for my categorical variable (x=Type) with two distinct marker shapes (per categories A and B) and errorbar colors matching the color of the respective marker color (that is palette=dict(A= "k", B= "r"))

这是我的数据:

Type         Y              Err
A             3           0.2
A             3.1         0.8
A             4.3         0.6
B             5.9         1.1
B             5.1         0.5

我彻底搜索了这个论坛以获得错误栏,这是我到目前为止所得到的.

I searched this forum thoroughly to get errorbars and here's what I've got so far.

Subplot1 = sns.stripplot(y=DataFrame["Y"], x=DataFrame["Type"], marker='s',
                         palette=dict(A= "k", B="r")`

# Add errorbars to each data point 
for PointPair in Subplot1.collections:
     for x, y in PointPair.get_offsets():
         x_coords.append(x)
         y_coords.append(y)

Subplot1.errorbar(x_coords, y_coords, yerr=DataFrame['Err'], 
                     fmt=' ', 
                     elinewidth=1, ecolor='k', 
                     capsize=3, markeredgewidth=0.81, 
                      )

因此,以通俗的英语来说,我一直在尝试调整 ecolor ='k' marker ='s'以获得单独的错误栏颜色和标记形状类别A和类别B.但是,以下内容似乎无效:ecolor=['k', 'r'] marker = ['s','o']

So in plain English, I've been attempting to tweak ecolor='k' as well as marker='s' to gain individual errorbar color and markershapes for Categories A and B. But yet the following doesn't seem to be working: ecolor=['k', 'r'] marker=['s', 'o']

如果你能对此有所了解.提前非常感谢!

If you could please shed some light on this. Many thanks in advance!

推荐答案

不幸的是,如果您试图摆脱所提供的情节,seaborn 很难处理.

Unfortunately, seaborn is very difficult to work with if you are trying to move away from the plots that are offered.

在您的情况下,我认为完全放弃 seaborn 并使用标准的 matplotlib 函数生成图会容易得多:

In your case, I think it would be much easier to forgo seaborn altogether and to generate a plot using standard matplotlib functions:

markers = ['s','o']
colors = ['k', 'r']
grouped = df.groupby('Type')

fig, ax = plt.subplots()
for i,((g,d),m,c) in enumerate(zip(grouped,markers,colors)):
    # generate scattered x values, adjust scale= as needed
    x = np.random.normal(loc=i,scale=0.05,size=(len(d['Y'],))) 
    ax.errorbar(x,d['Y'],yerr=d['Err'],
                fmt=m, color=c, capsize=3)
ax.set_xticks(list(range(len(grouped))))
ax.set_xticklabels([a for a in grouped.groups])

这篇关于对添加到条带图中的 errorbar() 的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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