0

I'm on Python 3.4.3 and cannot upgrade the system. My issue is that I want do generate 3d wireframe plot using matplotlib and mpl_toolkits.mplot3d

ax.plot_wireframe(*a,b, rstride=1, cstride=2)
>> SyntaxError: only named arguments may follow *expression

From this question I get, that prior Python 3.5 a starred expression is only allowed as the last item in the exprlist.

Doing ax.plot_wireframe(b,*a, rstride=1, cstride=2) works, but this - of course - yields in a plot with twisted-up axes.

My question: Is there a possibilty to swap the axis from the wirefram plot (e.q. ax.plot_wireframe(Z,X,Y) instead (X,Y,Z), or is there another workaround for my problem with the unpacking?

Further details:

a = np.meshgrid(np.arange(ys.shape[0]),xs)
b = ys.T

print(ys.shape)
>>(448, 33)
print(ys.shape[0])
>>488
print(b.shape)
>>(33,448)
print(xs.shape)
>>(33,)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ I was able to circumvent the problem by giving Python what it wanted, namely a named argument. So the line now reads:

ax.plot_wireframe(*a,Z=b)
Community
  • 1
  • 1
rtime
  • 349
  • 6
  • 23

1 Answers1

1

How about chain b to a using itertools.chain and unpack both of them in one piece:

from itertools import chain

ax.plot_wireframe(*chain(a, (b,)), rstride=1, cstride=2)

If a is a list or tuple, you can of course simply use addition after putting b in a container of type a.


Demo:

>>> a = [1,2,3]
>>> b = 4
>>> print(*a, b)
  File "<stdin>", line 1
SyntaxError: only named arguments may follow *expression
>>> print(b, *a)
4 1 2 3
>>> print(*chain(a, (b,)))
1 2 3 4
Moses Koledoye
  • 77,341
  • 8
  • 133
  • 139
  • ax.plot_wireframe(*chain(a, (b,))) yields File "~/Python-3.4.3/lib/python3.4/site-packages/matplotlib-1.4.3-py3.4-linux-x86_64.egg/mpl_toolkits/mplot3d/axes3d.py", line 1775, in plot_wireframe linec = art3d.Line3DCollection(lines, *args, **kwargs) File "~/Python-3.4.3/lib/python3.4/site-packages/matplotlib-1.4.3-py3.4-linux-x86_64.egg/mpl_toolkits/mplot3d/art3d.py", line 171, in __init__ LineCollection.__init__(self, segments, *args, **kwargs) TypeError: __init__() takes from 2 to 12 positional arguments but 34 were given – rtime Nov 21 '16 at 20:34
  • @t.rathjen Have a look at the demo. – Moses Koledoye Nov 21 '16 at 20:40
  • Be sure the case you have an error with works with `b, *a` – Moses Koledoye Nov 21 '16 at 21:11
  • 'b, *a' works just fine, but than again, the axes don't match up – rtime Nov 21 '16 at 21:15