0

I am running a set of python scripts on my visual studio code on windows 10. It seems that there is a bug in matplotlib package of the anaconda3. Specifically, I notice that saving a figure as a .png utilizing matplotlib.pyplot.savefig function produces a segmentation fault error message as the following. I search alot in the past few days and still could not figure out what is the issue. Specifically, the following explanation (#12286) helped me to understand the issue but did not give me any workaround. I would need your help on this matter.

Update1: Here is the content of Plotter module:

import faulthandler
faulthandler.enable()
from Utilities import *

class Plotter:
    def __init__(self, lst1: list, lst2: list, lst3: list):
        self.lst1 = lst1
        self.lst2 = lst2
        self.lst3 = lst3

    def plotterFunc(self) -> mpl.pyplot.axes:
        fig, ax = mpl.pyplot.subplots(figsize=(12, 12))
        setScaleLabelTickLimit(ax, t3)
        ax.set_ylabel('Intensity [$\\frac{{W}}{{cm^{{2}}}}$]')
        plotter2(ax, x3, self.lst3)
        mpl.pyplot.savefig(PLOT_DIR/'Intensity/Intensity.png', 
                    orientation='landscape', bbox_inches='tight')
        mpl.pyplot.clf()
        
    def plotterFunc2():
        pass
    
    def plotterFunc3():
        pass

--Thank you,

Windows fatal exception: access violation

Current thread 0x0001fb6c (most recent call first):
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 240 in get_text_width_height_descent
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\text.py", line 306 in _get_layout
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\text.py", line 903 in get_window_extent
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axis.py", line 1068 in
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axis.py", line 1068 in _get_tick_bboxes
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axis.py", line 1142 in draw
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\artist.py", line 51 in draw_wrapper
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\image.py", line 132 in _draw_list_compositing_images
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axes_base.py", line 2921 in draw
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib_api\deprecation.py", line 431 in wrapper
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\artist.py", line 51 in draw_wrapper File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\image.py", line 132 in _draw_list_compositing_images
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\figure.py", line 2790 in draw
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\artist.py", line 51 in draw_wrapper
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\artist.py", line 74 in draw_wrapper
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\backend_bases.py", line 2230 in print_figure
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\backends\backend_qt5agg.py", line 78 in print_figure
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\figure.py", line 3015 in savefig
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\pyplot.py", line 966 in savefig
File "c:\Users\username...\Plotter.py", line 41 in plotterFunc

File "c:/Users/username/.../my_script.py", line 199 in main
File "c:/Users/username/.../my_script.py", line 211 in

Segmentation fault

Ash
  • 41
  • 8
  • Plotter.py isnt matplotlib, so the bug is likely elsewhere. It would be nice to know what Plotter.py is and how it was installed. – Jody Klymak Nov 19 '21 at 16:48
  • Thank you Jody, Plotter.py is just a utility plotter class I have created myself. Let me see if I can post its content. – Ash Nov 19 '21 at 16:53
  • I see now, sorry. This is also it certainly a bad version of fontconfig on conda for windows. Update your install . – Jody Klymak Nov 19 '21 at 16:57
  • I added the Plotter. Do you mean to do "conda update conda" followed by "conda update anaconda"? – Ash Nov 19 '21 at 17:06
  • Just try updating fontconfig. – Jody Klymak Nov 19 '21 at 17:40
  • 1
    Sorry freetype. Relatively sure this is a duplicate of https://stackoverflow.com/questions/69786885/after-conda-update-python-kernel-crashes-when-matplotlib-is-used – Jody Klymak Nov 19 '21 at 17:43
  • Thank you very much, the issue is resolved. – Ash Nov 19 '21 at 18:18
  • I have to downgrade freetype to an earlier version. – Ash Nov 19 '21 at 18:19
  • 1
    Does this answer your question? [After conda update, python kernel crashes when matplotlib is used](https://stackoverflow.com/questions/69786885/after-conda-update-python-kernel-crashes-when-matplotlib-is-used) – Trenton McKinney Nov 19 '21 at 21:57
  • Thank you Trenton, the issue is resolved now. – Ash Nov 24 '21 at 16:23

0 Answers0