Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using <robot>.plot() causes pyplot to crash #405

Open
Alxkory opened this issue Nov 6, 2023 · 1 comment
Open

using <robot>.plot() causes pyplot to crash #405

Alxkory opened this issue Nov 6, 2023 · 1 comment

Comments

@Alxkory
Copy link

Alxkory commented Nov 6, 2023

Describe the bug
While attempting to plot the robot according to the example code of the main readme pyplot crashes,
VSCode is used as the main editor from where the code is run.
when running the script as a regular python file the matplotlib window briefly flashes and closes.
when running from a .ipynb file with QT as a backend (%matplotlib QT as specified on the common issues page) the matplotlib windows opens, plots the Robot incorrectly but stays open until closed manually.

Version information

Did you install from PyPI or GitHub? : PyPi
If PyPI what version number? : roboticstoolbox-python 1.1.0

swift-sim 1.1.0 (while swift also crashes that is not the main focus of this Issue)
matplotlib 3.8.1

Robotics Toolbox depends heavily on two other packages: Swift (3D graphics) and SpatialMath toolbox (underpinning maths utilities). If you think your issue is related to these, then please answer the questions above for them.

To Reproduce
Steps to reproduce the behavior:

Minimum script to reproduce:

import roboticstoolbox as rtb
robot = rtb.models.Panda()

Te = robot.fkine(robot.qr)  # forward kinematics

from spatialmath import SE3

Tep = SE3.Trans(0.6, -0.3, 0.1) * SE3.OA([0, 1, 0], [0, 0, -1])
sol = robot.ik_LM(Tep)         # solve IK

q_pickup = sol[0]

qt = rtb.jtraj(robot.qr, q_pickup, 50)
robot.plot(qt.q, backend='pyplot', movie='panda1.gif')

Terminal trace:

(.venv) C:\Users\sasha\Documents\PruningRobot_Project>c:/Users/sasha/Documents/PruningRobot_Project/.venv/Scripts/python.exe c:/Users/sasha/Documents/PruningRobot_Project/pyrobot_toolbox_test.py
Traceback (most recent call last):
  File "c:\Users\sasha\Documents\PruningRobot_Project\pyrobot_toolbox_test.py", line 14, in <module>
    robot.plot(qt.q, backend='pyplot', movie='panda1.gif')
  File "c:\Users\sasha\Documents\PruningRobot_Project\.venv\lib\site-packages\roboticstoolbox\robot\BaseRobot.py", line 2372, in plot   
    images.append(env.getframe())
  File "c:\Users\sasha\Documents\PruningRobot_Project\.venv\lib\site-packages\roboticstoolbox\backends\PyPlot\PyPlot.py", line 419, in getframe
    self.ax.w_xaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
AttributeError: 'Axes3D' object has no attribute 'w_xaxis'. Did you mean: 'xaxis'?

Jupyter trace:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
[c:\Users\sasha\Documents\PruningRobot_Project\toolbox](file:///C:/Users/sasha/Documents/PruningRobot_Project/toolbox) test.ipynb Cell 6 line 2
      [1](vscode-notebook-cell:/c%3A/Users/sasha/Documents/PruningRobot_Project/toolbox%20test.ipynb#X23sZmlsZQ%3D%3D?line=0) qt = rtb.jtraj(robot.qr, q_pickup, 50)
----> [2](vscode-notebook-cell:/c%3A/Users/sasha/Documents/PruningRobot_Project/toolbox%20test.ipynb#X23sZmlsZQ%3D%3D?line=1) robot.plot(qt.q, backend='pyplot', movie='panda1.gif')

File [c:\Users\sasha\Documents\PruningRobot_Project\.venv\lib\site-packages\roboticstoolbox\robot\BaseRobot.py:2372](file:///C:/Users/sasha/Documents/PruningRobot_Project/.venv/lib/site-packages/roboticstoolbox/robot/BaseRobot.py:2372), in BaseRobot.plot(self, q, backend, block, dt, limits, vellipse, fellipse, fig, movie, loop, **kwargs)
   2369     env.step(dt)
   2371     if movie is not None and isinstance(env, PyPlot):  # pragma nocover
-> 2372         images.append(env.getframe())
   2374 if movie is not None:  # pragma nocover
   2375     # save it as an animated GIF
   2376     images[0].save(
   2377         movie,
   2378         save_all=True,
   (...)
   2382         loop=0,
   2383     )

File [c:\Users\sasha\Documents\PruningRobot_Project\.venv\lib\site-packages\roboticstoolbox\backends\PyPlot\PyPlot.py:419](file:///C:/Users/sasha/Documents/PruningRobot_Project/.venv/lib/site-packages/roboticstoolbox/backends/PyPlot/PyPlot.py:419), in PyPlot.getframe(self)
    414         raise RuntimeError(
    415             "to save movies PIL must be installed:\npip3 install PIL"
    416         )
    418 # make the background white, looks better than grey stipple
--> 419 self.ax.w_xaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
    420 self.ax.w_yaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
    421 self.ax.w_zaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))

AttributeError: 'Axes3D' object has no attribute 'w_xaxis'

Expected behavior
I expect for a window to open and play the animation shown in the README.md
with the robot having the correct shape.

Screenshots
If applicable, add screenshots to help explain your problem.
image

Environment (please complete the following information):
Windows 10 Version: 10.0.19045 Build 19045
Python 3.10.2

Additional Add any other context about the problem here.ontext
I am able to run the "train.py" file from the examples directory without problems

import roboticstoolbox as rtb

# Make a panda robot
panda = rtb.models.DH.Panda()

# Init joint to the 'ready' joint angles
panda.q = panda.qr

# Open a plot with the teach panel
e = panda.teach(panda.q)

Edit: I performed the same scripts inside an Ubuntu 22.04 VM, Swift works without issues while the pyplot based plotter has the exact same error trace and graphical problem.

@alsaibie
Copy link

Deprecated Properties: w_xaxis ...

Regarding the w_xaxis issue, the properties have been deprecated in matplotlib 3.8.

Workaround

Install a prior version of matplotlib==3.7 to work around the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants