Dec-27-2018, 07:59 PM
I would like to create a dashboard webpage with plots. I'm using Visual Studio Code IDE. I went through the tutorials to generate a webpage with variable inputs (the tutorial uses text input). And I went thorugh the Matplotlib example to create a plot. But when I go to my webpage it creates the plot in a new window. I'm not sure how to get it into my webpage.
In Visual Studio Code views.py file:
My web address 127.0.0.1:8000/dashboard/ brings up the plot as a popup window (from plt.show(). And when I close that window the webpage is shown but can't find the plot reference. So obviously 'plotDisp': plt is not correct .
In Visual Studio Code views.py file:
from django.http import HttpResponse from django.shortcuts import render from datetime import datetime import matplotlib.pyplot as plt import numpy as np # matplotlib https://matplotlib.org/ def dashboard(request): np.random.seed(2000000) x = np.arange(0.0, 50.0, 2.0) y = x**1.3 + np.random.rand(*x.shape) * 30.0 s = np.random.rand(*x.shape) * 800 + 500 plt.scatter(x, y, s, c="g", alpha=0.5, marker=r'$\clubsuit$', label='luck') plt.xlabel("leprechauns") plt.ylabel("gold") plt.legend(loc='upper left') plt.show() return render( request, 'dashboard/singleplot.html', { 'plotDisp': plt } )in the webpage template I'm not sure what format to show the plot. For instance: <img src={{ plotDisp }} /> or some sort of frame object?
My web address 127.0.0.1:8000/dashboard/ brings up the plot as a popup window (from plt.show(). And when I close that window the webpage is shown but can't find the plot reference. So obviously 'plotDisp': plt is not correct .