Error when setting arrowstyle #1812

Closed
robbertbloem opened this Issue Mar 8, 2013 · 0 comments

1 participant

@robbertbloem

I want to set the arrowstyle in "matplotlib.patches.FancyArrowPatch()". According to the documentation I can set it using a ArrowStyle instance or a string. (http://matplotlib.org/api/artist_api.html#matplotlib.patches.FancyArrowPatch) The method with the ArrowStyle instance gives the following error:

AttributeError: 'Fancy' object has no attribute 'replace'

Code and full traceback are pasted below.

The error occurs for both the "Fancy" and "CurveB" (I didn't test others).
The error occurs in MatPlotLib 1.1.0, backend: WXagg, Python 2.7.3 and in MatPlotLib 1.2.0, backend: MacOSX, Python 3.3.0.
The error occurs with and without IPython.
I use Mac OS X 10.8.2.

import matplotlib 
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)

# ArrowStyle
# does not work
ast = matplotlib.patches.ArrowStyle.Fancy()
# does not work
#ast = matplotlib.patches.ArrowStyle("Fancy")
# does work
#ast = "Fancy"

# ConnectionStyle, two methods, both work
#cs = matplotlib.patches.ConnectionStyle("arc3", rad = 0.3)
cs = "arc3, rad = 0.3"

arrow = matplotlib.patches.FancyArrowPatch(
    posA = [0.25, 0.25], 
    posB = [0.75, 0.75], 
    connectionstyle = cs, 
    arrowstyle = ast
)

ax.add_patch(arrow) 

plt.show()

This is the traceback, for MatPlotLib 1.2.0/Python 3.3:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/ipython-0.13.1-py3.3.egg/IPython/utils/py3compat.py in execfile(fname, glob, loc)
     74     def execfile(fname, glob, loc=None):
     75         loc = loc if (loc is not None) else glob
---> 76         exec(compile(open(fname, 'rb').read(), fname, 'exec'), glob, loc)
     77 
     78     # Refactor print statements in doctests.

/*** redacted ***/902_arrowstyle_test.py in <module>()
     21     posB = [0.75, 0.75],
     22     connectionstyle = cs,
---> 23     arrowstyle = ast
     24 )
     25 

/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/matplotlib/patches.py in __init__(self, posA, posB, path, arrowstyle, arrow_transmuter, connectionstyle, connector, patchA, patchB, shrinkA, shrinkB, mutation_scale, mutation_aspect, dpi_cor, **kwargs)
   3778         self._path_original = path
   3779 
-> 3780         self.set_arrowstyle(arrowstyle)
   3781 
   3782         self._mutation_scale = mutation_scale

/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/matplotlib/patches.py in set_arrowstyle(self, arrowstyle, **kw)
   3878             self._arrow_transmuter = arrowstyle
   3879         else:
-> 3880             self._arrow_transmuter = ArrowStyle(arrowstyle, **kw)
   3881 
   3882     def get_arrowstyle(self):

/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/matplotlib/patches.py in __new__(self, stylename, **kw)
   1648         # a dictionary of stylname, style class paie.
   1649 
-> 1650         _list = stylename.replace(" ", "").split(",")
   1651         _name = _list[0].lower()
   1652         try:

AttributeError: 'Fancy' object has no attribute 'replace'
@pelson pelson closed this in 465b26d Apr 18, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment