Sunday 29 December 2019

django mpld3 1

mpld3 - bringing matplotlib to browser

The mpld3 project brings together Matplotlib, the popular Python-based graphing library, and D3js, the popular JavaScript library for creating interactive data visualizations for the web. The result is a simple API for exporting your matplotlib graphics to HTML code which can be used within the browser, within standard web pages, blogs, or tools such as the IPython notebook.


#powershell

pip install mpld3
pip install Jinja2

-----------------------
#mpld/views

from django.http import  HttpResponse
import matplotlib.pyplot as plt, mpld3

def index(request):
    fig = plt.figure()
    plt.plot([1, 2, 3, 4])
    g = mpld3.fig_to_html(fig)
    return HttpResponse(g)

reference:
https://mpld3.github.io/
https://stackoverflow.com/questions/18944345/importerror-no-module-named-jinja2/18983050
https://stackoverflow.com/questions/24127938/using-mpld3-to-add-graphs-into-django-projects

No comments:

Post a Comment