python - Gaps in border around text -


i add border around texts in matplotlib plot, can using patheffects.withstroke. however, letters , number there small gap top right of symbol.

is there way not have gap?

minimal working example:

import matplotlib.pyplot plt import matplotlib.patheffects 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") 

this gives image, shows gap in s , 6 symbols. enter image description here

i'm using matplotlib 1.5.1.

the documentation not mention (or did not found it) but, searching in code, can see patheffects.withstroke method accepts lot of keyword arguments.

you can have list of keyword arguments executing in interactive session:

>>> matplotlib.backend_bases import graphicscontextbase gcb >>> print([attr[4:] 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'] 

the argument looking capstyle accepts 3 possible values:

  • "butt"
  • "round"
  • "projecting"

in case, "round" value seems fix problem. consider code below...

import matplotlib.pyplot plt import matplotlib.patheffects 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") 

... produces this:

enter image description here


the accepted keywords arguments set_* (minus "set_" prefixe) methods of graphicscontextbase class. can find details on accepted values class documentation.


Comments

Popular posts from this blog

Java Entity Manager - JSON reader was expecting a value but found 'db' -

many to many - Django Rest Framework ManyToMany filter multiple values -

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -