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."
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 thearrowpropsdictionary. None of them worked.Right after the
figure.canvas.draw()the window looks like thisClearly, I still have rounded caps on my lines (arrows).
Furthermore, in the last attempt, I specified
solid_capstyle = 'butt'in thearrowpropsdictionary, and it failed with the following tracebackIt appears that the
arrowpropsdictionary can include patch properties, such as capstyle, but not line properties, such assolid_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."