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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:36:10+00:00 2026-06-13T11:36:10+00:00

I am creating a couple of pdf plots with matplotlib which is composed of

  • 0

I am creating a couple of pdf plots with matplotlib which is composed of 400 subplots. Each one has only 5 data points. It takes 420 s on a good computer to save 5 pdf picture. Is there any way to optimize the code or it is just normal for matplotlib?

Portion of code for plotting:

plot_cnt = 1
for k in np.arange(K_min, K_max + 1):
    for l in np.arange(L_min, L_max + 1):
        ax = plt.subplot(grid[0], grid[1], plot_cnt)
        plot_cnt += 1
        plt.setp(ax, 'frame_on', False)
        ax.set_ylim([-0.1, 1.1])
        ax.set_xlabel('K={},L={}'.format(k, l), size=3)
        ax.set_xlim([-0.1, 4.1])
        ax.set_xticks([])
        ax.set_yticks([])
        ax.grid('off')
        ax.plot(np.arange(5), (data['S1']['Azimuth'][:, k - 1, l + offset_l] + \
                data['S1']['Delta Speed'][:, k - 1, l + offset_l] + \
                data['S1']['Speed'][:, k - 1, l + offset_l]) / 3,
                'r-o', ms=1, mew=0, mfc='r')
        ax.plot(np.arange(5), data['S2'][case][:, k - 1, l + offset_l],
                'b-o', ms=1, mew=0, mfc='b')
plt.savefig(os.path.join(os.getcwd(), 'plot-average.pdf'))
plt.clf()
print 'Final plot created.'

Final Picture:
enter image description here

  • 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-13T11:36:10+00:00Added an answer on June 13, 2026 at 11:36 am

    Building off of what @rowman said, you can do this all in one axes (as you turn off all the ticks etc). Something like:

    K_max = 20
    K_min = 0
    L_max = 20
    L_min = 0
    ax = plt.subplot(111)
    x_offset = 7 # tune these
    y_offset = 7 # tune these
    plt.setp(ax, 'frame_on', False)
    ax.set_ylim([0, (K_max-K_min +1)*y_offset ])
    ax.set_xlim([0, (L_max - L_min+1)*x_offset])
    ax.set_xticks([])
    ax.set_yticks([])
    ax.grid('off')
    
    
    
    for k in np.arange(K_min, K_max + 1):
        for l in np.arange(L_min, L_max + 1):
            ax.plot(np.arange(5) + l*x_offset, 5+rand(5) + k*y_offset,
                    'r-o', ms=1, mew=0, mfc='r')
            ax.plot(np.arange(5) + l*x_offset, 3+rand(5) + k*y_offset,
                    'b-o', ms=1, mew=0, mfc='b')
            ax.annotate('K={},L={}'.format(k, l), (2.5+ (k)*x_offset,l*y_offset), size=3,ha='center')
    plt.savefig(os.path.join(os.getcwd(), 'plot-average.pdf'))
    
    print 'Final plot created.'
    

    Runs in about a second or two. I think all of the time is spent setting up the axes object which are rather complex internally.
    output with fake data

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

Sidebar

Related Questions

I am creating a couple different custom controls, each of which implement different base
I am creating an ASP.NET page where I need a couple of variables which
I'm creating XML file which will hold couple of values regarding TCP Connection (IP
I'm creating an iOS5 app (programmed in Objective-C) which provides a couple of functions.
I'm a creating a subclass of UIView (MultiColumnTableView) which will hold a couple of
I'm using a expertPDF to convert a couple webpages to PDF, and there's one
This is perhaps a couple of questions rolled into one here, I am creating
I am developing a .NET Windows service that is creating a couple of threads
I have a couple questions about creating a object (2 values) and how to
I have the following couple of C pre-processor macros for creating test functions: //

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.