Reputation: 24121
In views.py
of my Django project, at a certain point in the code, I want to display a graph plot on the server to visualise in real-time the user input. So, I created another file plotter.py
in the same folder as views.py
, with the following content to display a simple graph:
import numpy import matplotlib.pyplot
def plot():
N = 50
x = numpy.random.rand(N)
y = numpy.random.rand(N)
colors = numpy.random.rand(N)
area = numpy.pi * (15 * numpy.random.rand(N))**2
matplotlib.pyplot.scatter(x, y, s=area, c=colors, alpha=0.5)
matplotlib.pyplot.show()
Then, in views.py
, I import plotter
, and then at my desired point in the file, I have plotter.plot()
. However, this gives the following error:
Request Method: POST
Request URL: http://localhost:8000/teacher/
Django Version: 1.7
Exception Type: ValueError
Exception Value:
signal only works in main thread
Exception Location: C:\Anaconda\lib\site-packages\matplotlib\backends\backend_qt5.py in mainloop, line 150
Python Executable: C:\Anaconda\python.exe
Python Version: 2.7.8
How can I achieve this without causing such an error?
Upvotes: 2
Views: 3668
Reputation: 366
run your server as follows
python manage.py runserver --nothreading --noreload
Upvotes: 7