Repository navigation
Description
As shown below, I have tried to change the arrow cap style on an annotation using rcParams, changing the cap style on the arrow path directly, and specifying the cap style in the arrowprops dictionary. None of them worked.
import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.rcParams['lines.solid_capstyle'] = 'butt'
fig = plt.figure()
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
anno = ax.annotate('5 mm', xytext = [0.5, 0.25], textcoords = 'axes fraction', \
xy = [0.0, 0.25], xycoords = 'axes fraction', clip_on = False, \
arrowprops=dict(arrowstyle='-', connectionstyle='arc3, rad=0.0', \
fc='none', shrinkA = 10, shrinkB = 0.0, \
linewidth = 8))
anno.arrow_patch.set_capstyle('butt')
anno = ax.annotate('5 mm', xytext = [0.5, 0.5], textcoords = 'axes fraction', \
xy = [0.0, 0.5], xycoords = 'axes fraction', clip_on = False, \
arrowprops=dict(arrowstyle='-', connectionstyle='arc3, rad=0.0', \
fc='none', shrinkA = 10, shrinkB = 0.0, \
linewidth = 8, capstyle = 'butt'))
fig.canvas.draw()
fig.savefig('scale_bar_issue.png')
anno = ax.annotate('5 mm', xytext = [0.5, 0.75], textcoords = 'axes fraction', \
xy = [0.0, 0.75], xycoords = 'axes fraction', clip_on = False, \
arrowprops=dict(arrowstyle='-', connectionstyle='arc3, rad=0.0', \
fc='none', shrinkA = 10, shrinkB = 0.0, \
linewidth = 8, solid_capstyle = 'butt'))
Right after the figure.canvas.draw() the window looks like this
Clearly, I still have rounded caps on my lines (arrows).
Furthermore, in the last attempt, I specified solid_capstyle = 'butt' in the arrowprops dictionary, and it failed with the following traceback
File "/Users/breedlu/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/axes/_axes.py", line 651, in annotate
a = mtext.Annotation(*args, **kwargs)
File "/Users/breedlu/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/text.py", line 1812, in __init__
**arrowprops)
File "/Users/breedlu/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/patches.py", line 3888, in __init__
Patch.__init__(self, **kwargs)
File "/Users/breedlu/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/patches.py", line 118, in __init__
self.update(kwargs)
File "/Users/breedlu/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/artist.py", line 757, in update
raise AttributeError('Unknown property %s' % k)
AttributeError: Unknown property solid_capstyle
It appears that the arrowprops dictionary can include patch properties, such as capstyle, but not line properties, such as solid_capstyle. This seems to be counter to the documentation here, where it says that "arrowprops, if not None, is a dictionary of line properties (see matplotlib.lines.Line2D) for the arrow that connects annotation to the point."

Activity
Fix matplotlib#4332. Fix flicker in wx* backends
Merge pull request #5352 from mdboom/fix-wx-flicker
tacaswell commentedon Oct 29, 2015
mis-aimed commit message
mtiberti commentedon Jun 14, 2017
Any news or workaround on this? I'm facing this same problem.
breedlun commentedon Jun 14, 2017
No workarounds I know of, other than to use a 2D line instead of an annotation.
Dhrumil0 commentedon Mar 14, 2018
This no longer appears to be a bug and can probably be closed. Maybe there were changes to the API since this was posted. The
arrowpropsdictionary only takes patch properties so line properties such assolid_capstylewill not work.@breedlun's code snippets are also using the
arrowstyleproperty inarrowpropsdictionary and this is why thecapstyleproperty is being ignored. According to the API, ifarrowpropscontainsarrowstyle, it will ignore patch properties and this is exactly the case. Ifarrowstyleis not inarrowprops, thecapstyleis changed correctly.mpetroff commentedon Oct 17, 2019
It looks like this was fixed in #13647, which is targeted for v3.2.
Specifically, setting
capstyleandjoinstyleinarrowpropsnow works.jklymak commentedon Oct 17, 2019
Thanks for checking!