Call Python from matlab, error related to Matplotlib.pyplot

14 vues (au cours des 30 derniers jours)
Xingang Bu
Xingang Bu le 27 Jan 2021
Commenté : Al Danial le 5 Nov 2022
Hi, everyone,
I am calling a Python script from Matlab, if the program included code likes 'import matplotlib.backends.qt_editor.figureoptions as figureoptions, or import matplotlib.pyplot as plt', an error 'Python Error: AttributeError: module 'matplotlib' has no attribute 'pyplot'' will was occured. Please help me to fin this problem, thank you.
import numpy
import skimage
import matplotlib.pyplot as plt
from skimage import io
from skimage.morphology import watershed
def imgread():
imgpath='D:/PROJECT/CoreModelingV1.2/Pore_Extr_Sim/Img4codeDev_S35'
imgtype='\*.png'
imgname=imgpath+imgtype
print('the file is: ',imgname)
img=skimage.io.imread_collection(imgname)
imdata=img.concatenate()
# imdata=imdata[:,300:500,300:500]
# imdata=imdata[:,380:480,300:400]
imdata=imdata==0
plt.figure(figsize=[10, 10])
plt.imshow(imdata[0], origin='upper')
plt.show()
return imdata
py.test5.imgread
the file is: D:/PROJECT/CoreModelingV1.2/Pore_Extr_Sim/Img4codeDev_S35\*.png
Error using test5>imgread (line 18)
Python Error: AttributeError: module 'matplotlib' has no attribute 'pyplot'
  2 commentaires
Nithin
Nithin le 27 Oct 2022
Hello,
This error seems to be a Python error and not a MATLAB one. Does the script throw the same error when executed through command line?
Al Danial
Al Danial le 5 Nov 2022
MATLAB and matplotlib both ship with Qt graphics libraries. Try changing matplotlib's graphics backend to a different library to avoid conflicts. Change
import matplotlib.pyplot as plt
to
import matplotlib
matplotlib.use('WXAgg')
import matplotlib.pyplot as plt

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Call Python from MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by