mjpython and matplotlib #2310
Replies: 2 comments 1 reply
-
I'd also be curious to know whether there is a fix for this problem. I started encountering it when I needed to start using mjpython to run a passive viewer on my Mac while still plotting some data with matplotlib on the side. In my particular case, the error message is the result of an NSInternalInconsistencyException with the message 'NSWindow should only be instantiated on the main thread!'. Digging a bit into the problem, the exception is raised when instantiating the FigureManagerMac class in the backend_macosx.py file of the Matplotlib library (version 3.7.5). This error makes sense to me given that mjpython seems to essentially make the user code run in a newly created thread which is different from the main thread. |
Beta Was this translation helpful? Give feedback.
-
There's probably multiple different ways to do it, but as help I can offer this tutorial exercise I wrote that uses real time plotting of a mujoco scene with matplotlib in one script, and PyQt in another. It is done with the interactive viewer not the passive, but it may be adapted in a straightforward fashion to it. https://github.com/Balint-H/ssnr_sim/tree/main/challenges/Day_3/foot_drop As @psclklnk suggests, the solution is with multithreading/multiprocessing, posting data in a queue from mujoco, and consuming it in the visualisation thread. |
Beta Was this translation helpful? Give feedback.
-
Intro
Interested in learning about MuJoCo for fun.
My setup
I am using python 3.11, mujoco 3.1.6 on a mac intel (sonoma)
My question
I am trying to graph using matplotlib.pyplot. My code is something like this and I run it like this on a mac
mjpython <filename.py>
My question: This code crashes at the plt.figure(). Is there no way to use plt.figure with mjpython? If not, are there other options to make plots. NOTE: I could save the data in a csv and plot in a separate call to python3 but I want to avoid that.
Minimal model and/or code that explain my question
If you encountered the issue in a complex model, please simplify it as much as possible (while still reproducing the issue).
Model:
minimal XML
Code:
Confirmations
Beta Was this translation helpful? Give feedback.
All reactions