Jiadong
Jiadong

Reputation: 2072

matplotlib arrow's connectionstyle and width, headwidth are not compatible?

I have the following code:

fig, ax = plt.subplots(1, 1, figsize=(7.2, 7.2))
start = (0.1, 0.1)
end = (0.5, 0.5)
connectionstyle='angle,angleA=-90,angleB=10,rad=5'
ax.annotate("",
            xy=end, xycoords='data',
            xytext=start, textcoords='data',
            arrowprops=dict(arrowstyle="->",
                            color="0.5",
                            shrinkA=5, shrinkB=5,
                            patchA=None,
                            patchB=None,
                            connectionstyle=connectionstyle,
                            ),)

Which can generate a figure like this,

enter image description here

However, if I use parameters like width, headwidth instead of arrowstyle, I always get a error. Same set of code which has a error report:

fig, ax = plt.subplots(1, 1, figsize=(7.2, 7.2))
start = (0.1, 0.1)
end = (0.5, 0.5)
connectionstyle='angle,angleA=-90,angleB=10,rad=5'
ax.annotate("",
            xy=end, xycoords='data',
            xytext=start, textcoords='data',
            arrowprops=dict(#arrowstyle="->",
                            width=10,headwidth=30,
                            color="0.5",
                            shrinkA=5, shrinkB=5,
                            patchA=None,
                            patchB=None,
                            connectionstyle=connectionstyle,
                            ),)

If I change connectionstyle to 'arc3, rad=1', it works fine.

fig, ax = plt.subplots(1, 1, figsize=(7.2, 7.2))
start = (0.1, 0.1)
end = (0.5, 0.5)
connectionstyle='arc3, rad=1'  # connectionstyle NOW arc3
ax.annotate("",
        xy=end, xycoords='data',
        xytext=start, textcoords='data',
        arrowprops=dict(#arrowstyle="->",
                        width=10,headwidth=30,
                        color="0.5",
                        shrinkA=5, shrinkB=5,
                        patchA=None,
                        patchB=None,
                        connectionstyle=connectionstyle,
                        ),)

Upvotes: 0

Views: 1719

Answers (1)

Asmus
Asmus

Reputation: 5247

That's because you're still providing connectionstyle='angle,angleA=-90,angleB=10,rad=5', which can not be applied to an annotation without arrowstyle.

Have a look at the documentation for annotate, especially at arrowprops, where it says:

If arrowprops does not contain the key 'arrowstyle' the allowed keys are: width, headwidth, headlength, shrink, and any key to matplotlib.patches.FancyArrowPatch

Upvotes: 1

Related Questions