Skip to main content

A library to generate Matplotlib graphics within Django applications

Project description

Django-Plottings

Read the Docs Python package

A library to generate Matplotlib graphics within Django applications.

Matplotlib is a Python library for mathematical graphics representations, widely used in science in general and data science in particular.

Django is the leading framework for building web applications in the Python ecosystem.

This library is built with the intention of speeding up the building of data science webapps by generating graphics on the server side.

The library provides three different ways to use the rendered graphics:

  • as a view to be served as a standalone graphics file
  • as a text variable to be rendered within a webpage
  • as a file to be saved and served lately useful for background task geneartion.

To create a Django view that returns a PNG file with the plot. In the views.py file:

...
from plottings import PNGViewPlot
...

class PlotView(PNGViewPlot):
    def get_plot_data(self):
        return np.random.rand(20)

    def get_plot_options(self):
        return {"color": "blue"}

    @staticmethod
    def plotter_function(data, color="orange"):
        fig, ax = plt.subplots()
        ax.plot(data, '-o', ms=20, lw=2, alpha=0.7, mfc=color)
        ax.grid()
        return figure

And in the urls.py:

urlpatterns = [
    ...
    path("myplot", views.PlotView, name="plot"),
    ...
    ]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_plottings-0.0.3.tar.gz (5.2 kB view hashes)

Uploaded Source

Built Distribution

django_plottings-0.0.3-py2.py3-none-any.whl (6.8 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page