Viewing figure is not possible.

6 visualizaciones (últimos 30 días)
madhan ravi
madhan ravi el 25 de Sept. de 2020
Comentada: Peter O el 17 de Oct. de 2021
Why can't I view the figure?
P.S: The following is just to familiarise with Python in MATLAB environment.
System: MacOs.
>> py.matplotlib.pyplot.plot([1,2,3,4])
ans =
Python list with no properties.
[<matplotlib.lines.Line2D object at 0x1a9caad90>]
>>
  3 comentarios
madhan ravi
madhan ravi el 25 de Sept. de 2020
Ah You’re absolutely right! Can you post it as an answer?
Peter O
Peter O el 25 de Sept. de 2020
Sure!

Iniciar sesión para comentar.

Respuestas (1)

Peter O
Peter O el 25 de Sept. de 2020
matplotlib takes an explicit "show" command. Try:
py.matplotlib.pyplot.show()
  3 comentarios
Carlos Rondon
Carlos Rondon el 14 de Oct. de 2021
Same here. Any Ideas?
Peter O
Peter O el 17 de Oct. de 2021
I took a look with R2021aSP5 and a clean install of Python 3.8.10 and it seems to be connected to an incompatibility with TCL/TK -- specifically, the stack trace I'm getting is:
Error using __init__ (line 2270)
Python Error: TclError: Can't find a usable init.tcl in the following directories:
C:/Users/USERNAME/AppData/Local/Programs/Python/Python38/lib/tcl8.6 {C:/Program
Files/MATLAB/R2021a/interprocess/bin/win64/lib/tcl8.6} {C:/Program Files/MATLAB/R2021a/interprocess/bin/lib/tcl8.6}
{C:/Program Files/MATLAB/R2021a/interprocess/bin/win64/library} {C:/Program Files/MATLAB/R2021a/interprocess/bin/library}
{C:/Program Files/MATLAB/R2021a/interprocess/bin/tcl8.6.9/library} {C:/Program
Files/MATLAB/R2021a/interprocess/tcl8.6.9/library}
This probably means that Tcl wasn't installed properly.
Error in _backend_tk>new_figure_manager_given_figure (line 883)
Error in backend_bases>new_figure_manager (line 3545)
Error in pyplot>new_figure_manager (line 316)
Error in pyplot>figure (line 797)
Error in pyplot>gcf (line 854)
Error in pyplot>gca (line 2532)
Error in pyplot>plot (line 3019)
And part of the resason is that Python's TCL library doesn't live under LIB. Instead it can be found in C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\tcl\tcl8.6. And none of those paths in the MATLAB directories actually exist.
I'm wondering if this is due to a misconfiguration by either the MATLAB backend or Windows Python installer (or both). It seems to have trouble with both OutOfProcess and InProcess modes. The same install of Python will create charts with matplotlib just fine in the command window (after installing matplotlib).
Pulling that thread, this llittle gem seems to do the trick:
Basically, brute force it and copy the tk8.6 and tcl8.6 folders from Python38/tcl into Python38/lib.
And voila:
If you're using Anaconda (technically not a supported distribution), you need to override the default renderer from Qt back to Tkinter. There's probaby a way to get Qt to work, but that's an extra bit of wrangling I can't do right now.
  1. Copy those same directories, only now the base install is the Anaconda directory, somewhere like C:\Users\USERNAME\anaconda3
  2. Launch Matlab from an Anaconda command or PowerShell prompt (type "matlab")
  3. Override the qt renderer by to TK: py.matplotlib.use('TkAgg')
  4. py.matplotlib.pyplot.plot([1,2,3,4],[1,2,3,4])
  5. py.matplotlib.pyplot.show()

Iniciar sesión para comentar.

Categorías

Más información sobre Call Python from MATLAB en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by