Call Python from matlab, error related to Matplotlib.pyplot

조회 수: 9 (최근 30일)
Xingang Bu
Xingang Bu 2021년 1월 27일
댓글: Al Danial 2022년 11월 5일
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