matplotlib/python中错误栏上的边框

matplotlib/python中错误栏上的边框,python,matplotlib,Python,Matplotlib,我正在寻找一种方法,在我的情节中的错误栏上设置黑色边框 以下代码: ax.errorbar(x, y, yerr, fmt='o', label='label',color="#8da0cb",capthick=2, elinewidth=2,zorder=10) 产生: 我发现如果在错误条周围有一个黑色的边框,就像在标记上一样,会更美观 感谢您提供的任何帮助从中提供的信息中我看不到有效的kwargs,该kwargs可满足您的要求 存在mfc、mec、ms和mew,它们是markerface

我正在寻找一种方法,在我的情节中的错误栏上设置黑色边框

以下代码:

ax.errorbar(x, y, yerr, fmt='o', label='label',color="#8da0cb",capthick=2, elinewidth=2,zorder=10)
产生:

我发现如果在错误条周围有一个黑色的边框,就像在标记上一样,会更美观


感谢您提供的任何帮助

从中提供的信息中我看不到有效的
kwargs
,该kwargs可满足您的要求

存在
mfc、mec、ms
mew
,它们是
markerfacecolor、MarkerEdge Color、markersize
MarkerEdge With
。人们可能会考虑到这一点,并将其添加到matplotlib的下一个版本中


再看一看,我认为这是不可能的。

从中提供的信息来看,我没有看到一个有效的
kwargs
,可以满足您的要求

存在
mfc、mec、ms
mew
,它们是
markerfacecolor、MarkerEdge Color、markersize
MarkerEdge With
。人们可能会考虑到这一点,并将其添加到matplotlib的下一个版本中


再看一看,我认为这是不可能的。

这不是一个很好的解决方案,但是你可以在原来的错误条后面用更宽的线和帽状厚度重新绘制错误条,并将这些错误条的颜色设置为黑色。我们可以利用zorderkwarg把他们排在其他人后面

这里有一个MWE:

import matplotlib.pyplot as plt
import numpy as np

# Fake data
x=np.arange(0,5,1)
y=np.ones(x.shape)
yerr = np.ones(x.shape)/4.

# Create figure
fig,ax = plt.subplots(1)

# Set some limits
ax.set_xlim(-1,5)
ax.set_ylim(-2,4)

# Plot errorbars with the line color you want
ax.errorbar(x,y,yerr, fmt='o',color='r',capthick=2,elinewidth=2,capsize=3,zorder=10)

# Plot black errorbars behind (lower zorder) with a wider line and cap thinkness
ax.errorbar(x,y,yerr, fmt='o',color='k',capthick=4,elinewidth=4,capsize=4,zorder=5)

plt.show()


同样,这不是一个完美的解决方案,但至少它允许您将其包含在图例中。这一次,我们将使用模块向errorbars中添加a,而不是两次绘制errorbars

errorbar
返回多个
Line2D
LineCollection
对象,因此我们需要对每个相关对象应用笔划

import matplotlib.patheffects as path_effects

e = ax.errorbar(x,y,yerr, fmt='o',color='r',capthick=2,elinewidth=2, label='path effects')

e[1][0].set_path_effects([path_effects.Stroke(linewidth=4, foreground='black'),
                          path_effects.Normal()])
e[1][1].set_path_effects([path_effects.Stroke(linewidth=4, foreground='black'),
                          path_effects.Normal()])
e[2][0].set_path_effects([path_effects.Stroke(linewidth=4, foreground='black'),
                          path_effects.Normal()])

ax.legend(loc=0)

这不是一个很好的解决方案,但是你可以在原来的错误条后面用更宽的线和帽子厚度再次绘制错误条,并将这些错误条的颜色设置为黑色。我们可以利用zorderkwarg把他们排在其他人后面

这里有一个MWE:

import matplotlib.pyplot as plt
import numpy as np

# Fake data
x=np.arange(0,5,1)
y=np.ones(x.shape)
yerr = np.ones(x.shape)/4.

# Create figure
fig,ax = plt.subplots(1)

# Set some limits
ax.set_xlim(-1,5)
ax.set_ylim(-2,4)

# Plot errorbars with the line color you want
ax.errorbar(x,y,yerr, fmt='o',color='r',capthick=2,elinewidth=2,capsize=3,zorder=10)

# Plot black errorbars behind (lower zorder) with a wider line and cap thinkness
ax.errorbar(x,y,yerr, fmt='o',color='k',capthick=4,elinewidth=4,capsize=4,zorder=5)

plt.show()


同样,这不是一个完美的解决方案,但至少它允许您将其包含在图例中。这一次,我们将使用模块向errorbars中添加a,而不是两次绘制errorbars

errorbar
返回多个
Line2D
LineCollection
对象,因此我们需要对每个相关对象应用笔划

import matplotlib.patheffects as path_effects

e = ax.errorbar(x,y,yerr, fmt='o',color='r',capthick=2,elinewidth=2, label='path effects')

e[1][0].set_path_effects([path_effects.Stroke(linewidth=4, foreground='black'),
                          path_effects.Normal()])
e[1][1].set_path_effects([path_effects.Stroke(linewidth=4, foreground='black'),
                          path_effects.Normal()])
e[2][0].set_path_effects([path_effects.Stroke(linewidth=4, foreground='black'),
                          path_effects.Normal()])

ax.legend(loc=0)

我还想添加'Cossize=x',使瓶盖的侧面也显示为黑色。你知道怎样才能让它也出现在图例中吗?好主意,关于:
Cossize
。不知道这个传说,sorry@AnthonyLethuillier好的,我有一个主意-我们可以使用
patheffects
。我已经编辑了答案。它仍然不完美,但可能会给你一些东西玩。那太好了,我现在使用它,我在Gihub上发布了一个问题,我们将看到它的结果。我还将添加“Cossize=x”以使盖子的侧面也以黑色显示。你知道如何让它也出现在图例中吗?好主意是:
Cossize
。不知道这个传说,sorry@AnthonyLethuillier好的,我有一个主意-我们可以使用
patheffects
。我已经编辑了答案。它仍然不完美,但可能会给你一些可以玩的东西。太好了,我现在就用它,我在Gihub上发布了一个问题,我们将看看它会带来什么。