Call Python from matlab, error related to Matplotlib.pyplot

9 次查看(过去 30 天)
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 个评论
Nithin
Nithin 2022-10-27
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 2022-11-5
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

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Call Python from MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by