1

I have a function who plot a line, something like that:

def tmp_plot(*args, **kwargs):
    plt.plot([1,2,3,4,5],[1,2,3,4,5], *args, **kwargs)

and when I'm calling it with by passing line as a keyword argument like that:

tmp_plot(line = '-')

I get this error:

TypeError: set_lineprops() got multiple values for keyword argument 'line'

but it work fine with color argument.

I'm using matplotlib 1.4.3 and python 2.7.7

Any clues?

2 Answers 2

3

You can see where Matplotlib adds its own line argument in the Traceback below. This means your own keyword argument is a duplicate of Matplotlib's own one in the set_lineprops call:

In [1]: import matplotlib.pyplot as plt
In [2]: plt.plot([1,2,3], [1,4,9], line='-')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-82-f298702afcfe> in <module>()
----> 1 plt.plot([1,2,3], [1,4,9], line='-')

/Users/xnx/anaconda/envs/py33/lib/python3.3/site-packages/matplotlib/pyplot.py in plot(*args, **kwargs)
   2985         ax.hold(hold)
   2986     try:
-> 2987         ret = ax.plot(*args, **kwargs)
   2988         draw_if_interactive()
   2989     finally:

/Users/xnx/anaconda/envs/py33/lib/python3.3/site-packages/matplotlib/axes.py in plot(self, *args, **kwargs)
   4137         lines = []
   4138 
-> 4139         for line in self._get_lines(*args, **kwargs):
   4140             self.add_line(line)
   4141             lines.append(line)

/Users/xnx/anaconda/envs/py33/lib/python3.3/site-packages/matplotlib/axes.py in _grab_next_args(self, *args, **kwargs)
    317                 return
    318             if len(remaining) <= 3:
--> 319                 for seg in self._plot_args(remaining, kwargs):
    320                     yield seg
    321                 return

/Users/xnx/anaconda/envs/py33/lib/python3.3/site-packages/matplotlib/axes.py in _plot_args(self, tup, kwargs)
    305         ncx, ncy = x.shape[1], y.shape[1]
    306         for j in range(max(ncx, ncy)):
--> 307             seg = func(x[:, j % ncx], y[:, j % ncy], kw, kwargs)
    308             ret.append(seg)
    309         return ret

/Users/xnx/anaconda/envs/py33/lib/python3.3/site-packages/matplotlib/axes.py in _makeline(self, x, y, kw, kwargs)
    257                             **kw
    258                             )
--> 259         self.set_lineprops(seg, **kwargs)
    260         return seg
    261 

TypeError: set_lineprops() got multiple values for argument 'line'

Perhaps you mean ls or linestyle instead of line in any case?

In [83]: plt.plot([1,2,3], [1,4,9], ls='-')
Out[83]: [<matplotlib.lines.Line2D at 0x10ed65610>]
Sign up to request clarification or add additional context in comments.

Comments

0

I would guess the internals of matplotlib are unpacking an internal dictionary of parameters in addition to the caller provided ones, without stripping out duplicates so both you and matplot lib internals are providing separate keyword parameters of the same name via two parallel routes.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.