0

I'm trying to include an outline to lines plotted with plt.errorbar(). As suggested by Can I give a border (outline) to a line in matplotlib plot function?\,, I tried to use path_effects, however I need a different path_effect for the markers and the line.

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patheffects as pe

x = np.arange(20)
y = x**1.3

# Two lines.
fig, ax = plt.subplots()
ax.errorbar(x, y, fmt='-o', lw=5, mew=3, ms=5, c='k')
ax.errorbar(x, y, fmt='-o', lw=2, mew=0, ms=5, c='r')

# Single line with path_effects.
y += 10
ax.errorbar(x, y, fmt='-o', lw=2, mew=0, ms=5, c='b',
            path_effects=[pe.Stroke(linewidth=5, foreground='k'), pe.Normal()])

which produces the following output:

different outline attemps.

The difference between these methods is that in the former, the outline appears as a constant width around both the line and the marker, while in the one using path_effects, the outline is thicker around the markers. Is there a way to adjust the outline linewidth for the marker and the line separately?

  • Can you describe more in detail what you do and what you don't like about your output and how exactly the desired output should look like? – ImportanceOfBeingErnest Aug 07 '17 at 15:08
  • With the 'overlaying' method, to get an outline of constant width I have to make use a `linewidth` that is twice the width of the `markeredgewidth`. With path_effects, I can only work out how to enter a single linewidth argument so the resulting outline around the markers appears to be twice the width of the outline around the line. – Richard Teague Aug 08 '17 at 07:19

0 Answers0