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 8401571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:50:37+00:00 2026-06-09T21:50:37+00:00

I would like to use matplotlib to generate a number of PDF files. My

  • 0

I would like to use matplotlib to generate a number of PDF files. My main problem is that matplotlib is slow, taking order of 0.5 seconds per file.

I tried to figure out why it takes so long, and I wrote the following test program that just plots a very simple curve as a PDF file:

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt

X = range(10)
Y = [ x**2 for x in X ]

for n in range(100):
    fig = plt.figure(figsize=(6,6))
    ax = fig.add_subplot(111)
    ax.plot(X, Y)
    fig.savefig("test.pdf")

But even something as simple as this takes a lot of time: 15–20 second in total for 100 PDF files (modern Intel platforms, I tried both Mac OS X and Linux systems).

Are there any tricks and techniques that I can use to speed up PDF generation in matplotlib? Obviously I can use multiple parallel threads on multi-core platforms, but is there anything else that I can do?

  • 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-06-09T21:50:38+00:00Added an answer on June 9, 2026 at 9:50 pm

    If its practical, you could use multiprocess to do this (assuming you have multiple cores on your machine):

    NOTE: The following code will produce 40 pdfs in the present directory on your machine

    import matplotlib.pyplot as plt
    
    import multiprocessing
    
    
    def do_plot(y_pos):
        fig = plt.figure()
        ax = plt.axes()
        ax.axhline(y_pos)
        fig.savefig('%s.pdf' % y_pos)
    
    pool = multiprocessing.Pool()
    
    for i in xrange(40):
        pool.apply_async(do_plot, [i])
    
    pool.close()
    pool.join()
    

    It doesn’t scale perfectly, but I get a significant boost by doing this on my 4 cores (dual-core with hypertheading):

    $> time python multi_pool_1.py 
    done
    
    real    0m5.218s
    user    0m4.901s
    sys 0m0.205s
    
    $> time python multi_pool_n.py 
    done
    
    real    0m2.935s
    user    0m9.022s
    sys 0m0.420s
    

    I’m sure there is a lot of scope for performance improvements on the pdf backend of mpl, but that is not on the timescale you are after.

    HTH,

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

Sidebar

Related Questions

I would like to use Matplotlib to generate a scatter plot with a huge
I would like use argparse to parse the arguments that it knows and then
I'm trying to generate a 3D scatter plot using Matplotlib. I would like to
I currently have some large strings that I would like use as test data
I would like to use a language that I am familiar with - Java,
I have an array of Integers in Java, I would like use only a
I would like to use R to extract the speaker out of scripts formatted
I would like to use Maven's password encryption such as it uses for nodes
I would like to use the logout function from Django but not sure how
I would like to use D3.js (or maybe Raphaël ) for backend-generated reports using

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.