Search code examples
djangopython-3.xmatplotlibmpld3

Segmentation fault (core dumped) in django alongside server also disconnected


i'm trying to plot line chart using Matplotlib and mpld3 with Django . its working properly but if i hit refresh button in browser to reload the page suddenly server getting stopped with error message [Segmentation fault (core dumped)]

bellow i mentioned my code . thanks in advance !!

in views.py :

from django.shortcuts import render

from django.http import HttpResponse

import matplotlib.pyplot as plt , mpld3

def index(request):
   fig = plt.figure()
   plt.plot([1,2,3,4,5],[5,4,3,2,1],'r--')
   g = mpld3.fig_to_html(fig)
   return render(request,'index.html',{'a' : g})

Solution

  • Here is the fix simply add the below mentioned line along with your import statement.

    import matplotlib matplotlib.use('Agg')

    matplotlib.use('Agg') should be next to import matplotlib Hope this will help you..