Call Python from matlab, error related to Matplotlib.pyplot
9 views (last 30 days)
Show older comments
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 Comments
Nithin
on 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
on 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
Answers (0)
See Also
Categories
Find more on Call Python from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!