Gaps in border around text
<p>I would like to add a border around some texts in a matplotlib plot, which I can do using <code>patheffects.withStroke</code>. However, for some letters and number there is a small gap to the top right of the symbol.</p>

<p>Is there a way to not have this gap?</p>

<p>Minimal working example:</p>

<pre><code>import matplotlib.pyplot as plt
import matplotlib.patheffects as patheffects

fig, ax = plt.subplots()
ax.text(
    0.1, 0.5, "test: S6",
    color='white',
    fontsize=90,
    path_effects=[patheffects.withStroke(linewidth=13, foreground='black')])
fig.savefig("text_stroke.png")
</code></pre>

<p>This gives the image, which shows the gap in S and 6 symbols.
<a href="http://i.stack.imgur.com/Ffjhl.png" rel="nofollow"><img src="http://i.stack.imgur.com/Ffjhl.png" alt="enter image description here"></a></p>

<p>I'm using matplotlib 1.5.1.</p>

<p>The documentation does not mention it (or I did not found it) but, searching in the code, we can see that the <code>patheffects.withStroke</code> method accepts a lot of keyword arguments.</p>

<p>You can have the list of those keyword arguments by executing this in interactive session:</p>

<pre><code>&gt;&gt;&gt; from matplotlib.backend_bases import GraphicsContextBase as gcb
&gt;&gt;&gt; print([attr[4:] for attr in dir(gcb) if attr.startswith("set_")])
['alpha', 'antialiased', 'capstyle', 'clip_path', 'clip_rectangle', 'dashes', 'foreground', 'gid', 'graylevel', 'hatch', 'joinstyle', 'linestyle', 'linewidth', 'sketch_params', 'snap', 'url']
</code></pre>

<p>The argument you are looking for is <code>capstyle</code> which accepts 3 possible values:</p>

<ul>
<li>"butt"</li>
<li>"round"</li>
<li>"projecting"</li>
</ul>

<p>In you case, the "round" value seems to fix the problem.
Consider the code below...</p>

<pre><code>import matplotlib.pyplot as plt
import matplotlib.patheffects as patheffects

fig, ax = plt.subplots()
ax.text(
    0.1, 0.5, "test: S6",
    color='white',
    fontsize=90,
    path_effects=[patheffects.withStroke(linewidth=13, foreground='black', capstyle="round")])
fig.savefig("text_stroke.png")
</code></pre>

<p>... it produces this:</p>

<p><a href="http://i.stack.imgur.com/LmZT9.png" rel="nofollow"><img src="http://i.stack.imgur.com/LmZT9.png" alt="enter image description here"></a></p>

<hr>

<p>The accepted keywords arguments are actually all the <code>set_*</code> (minus the "set_" prefixe) methods of the <a href="http://matplotlib.org/api/backend_bases_api.html?highlight=graphicscontextbase#matplotlib.backend_bases.GraphicsContextBase" rel="nofollow">GraphicsContextBase</a> class. You can find details on the accepted values into the class documentation.</p>

python matplotlib