Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6205487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:16:59+00:00 2026-05-24T05:16:59+00:00

I am drawing some colorful scatter plots using matplotlib in my django app for

  • 0

I am drawing some colorful scatter plots using matplotlib in my django app for some small data sets, but the import statements add about 1-2 seconds to the run time compared to my previous version which used a javascript graphing utility – so now it takes almost 3 seconds instead of under a 1/2 second to load the page. It bugs me, even though most people at my office won’t care.

Here’s the basic code:

from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure

fig = Figure(figsize=[7, 7] )
canvas = FigureCanvas(fig)
ax = fig.add_axes( [1, 1, 5, 5] )
ax.scatter( x, y, c=colors, s=15, linewidth=1.5)
ax.set_xticklabels(labels, rotation=-40, horizontalalignment='left')
fig.savefig(file)

Is there a more light-weight method to load the Figure – or perhaps a different backend is faster?

I switched from the javascript utility because my co-workers needed to be able to copy and paste the image from the website. I like the idea of using matplotlib because now I can make some fancier graphs, but I am open to a different lightweight tool if that would have better performance.

Another idea would be to make some sort of server app which is always running and listens to a port for the query and then sends back the image. Then it would NOT have to load the whole matplotlib library for each query. But, that sounds like a lot of work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:16:59+00:00Added an answer on May 24, 2026 at 5:16 am

    You should render the image in a separate view. This lets your browser start rendering the page while the image (or images) are still being generated.

    def view(request):
        ...
        response=django.http.HttpResponse(content_type='image/png')
        canvas.print_png(response)
        return response
    

    (Code from http://www.scipy.org/Cookbook/Matplotlib/Django)

    Furthermore, Django’s processes shouldn’t die after each page request. Try configuring Apache/Nginx to keep multiple processes alive for future page requests. Each process will have to execute the import statements the first time it renders your image view. After that, you should have speedups.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In VB.NET I'm drawing an ellipse using some code like this. aPen = New
I am drawing some textures with alpha channel, but when they are displayed it
I have developed application for drawing some shapes (lines mostly) , now i need
I'd like to be able to do some drawing to the right of the
I have a view that I want to add some custom drawing to. I
I'm working on drawing an SVG grid using Javascript. I've managed to get the
I'm drawing some UML in which a concrete class inherits from an abstract class
I have recently focused on drawing some cool shapes in a HTML 5.0 canvas.
I've a very simple / minimal code Android application. I'm drawing some lines on
I'm doing some layer drawing on the iPad and have to provide user interaction.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.