1

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})

2 Answers2

2

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..

0

I've experienced the same problem between Django runserver and matplotlib with Django 2.0 and python 3.X. Waiting for a patch for this problem, meanwhile, I solved it using gunicorn with nginx as frontend instead of the Django embedded server.

Mario Nikolaus
  • 2,346
  • 1
  • 21
  • 28