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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:17:04+00:00 2026-06-04T12:17:04+00:00

I’m plotting several images at once, sharing axes, because I use it for exploratory

  • 0

I’m plotting several images at once, sharing axes, because I use it for exploratory purposes. Each image is the same satellite image at different dates. I’m experimenting a slow response from matplotlib when zooming and panning, and I would like to ask for any tips that could speed up the process.

What I am doing now is:

  • Load data from several netcdf files.

  • Calculate maximum value of all the data, for normalization.

  • Create a grid of subplots using ImageGrid. As each subplot is generated, I delete the array to free some memory (each array is stored in a list, the “deletion” is just a list.pop()). See the code below.

It’s 15 images, single-channel, of 4600×3840 pixels each. I’ve noticed that the bottleneck is not the RAM (I have 8 GB), but the processor. Python spikes to 100% usage on one of the cores when zooming or panning (it’s an Intel(R) Core(TM) i5-2500 CPU @ 3.30GHz, 4 cores, 64 bit).

The code is:

import os
import sys

import numpy as np
import netCDF4 as ncdf
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import ImageGrid
from matplotlib.colors import LogNorm

MIN = 0.001 # Hardcoded minimum data value used in normalization

variable = 'conc_chl'
units = r'$mg/m^3$'
data = []
dates = []

# Get a list of only netCDF files
filelist = os.listdir(sys.argv[1])
filelist = [f for f in filelist if os.path.splitext(f)[1] == '.nc']
filelist.sort()
filelist.reverse()

# Load data and extract dates from filenames
for f in filelist:
    dataset = ncdf.Dataset(os.path.join(sys.argv[1],f), 'r')
    data.append(dataset.variables[variable][:])
    dataset.close()
    dates.append((f.split('_')[2][:-3],f.split('_')[1]))

# Get the maximum value of all data. Will be used for normalization
maxc = np.array(data).max()

# Plot the grid of images + dates
fig = plt.figure()
grid = ImageGrid(fig, 111,\
        nrows_ncols = (3, 5),\
        axes_pad = 0.0,\
        share_all=True,\
        aspect = False,\
        cbar_location = "right",\
        cbar_mode = "single",\
        cbar_size = '2.5%',\
        )
for g in grid:
    v = data.pop()
    d = dates.pop()
    im = g.imshow(v, interpolation='none', norm=LogNorm(), vmin=MIN, vmax=maxc)
    g.text(0.01, 0.01, '-'.join(d), transform = g.transAxes) # Date on a corner
cticks = np.logspace(np.log10(MIN), np.log10(maxc), 5)
cbar = grid.cbar_axes[0].colorbar(im)
cbar.ax.set_yticks(cticks)
cbar.ax.set_yticklabels([str(np.round(t, 2)) for t in cticks])
cbar.set_label_text(units)

# Fine-tune figure; make subplots close to each other and hide x ticks for
# all
fig.subplots_adjust(left=0.02, bottom=0.02, right=0.95, top=0.98, hspace=0, wspace=0)
grid.axes_llc.set_yticklabels([], visible=False)
grid.axes_llc.set_xticklabels([], visible=False)

plt.show()

Any clue about what could be improved to make it more responsive?

  • 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-04T12:17:06+00:00Added an answer on June 4, 2026 at 12:17 pm

    It seems that setting interpolation='none' is significantly slower than setting it to ‘nearest’ (or even ‘bilinear’). On supported backends (e.g. any Agg backend) the code paths for ‘none’ and ‘nearest’ are different: ‘nearest’ gets passed to Agg’s interpolation routine, whereas ‘none’ does an unsampled rescale of the image (I’m just reading the code comments here).

    These different approaches give different qualitative results; for example, the code snippet below gives a slight moiré pattern, which doesn’t appear when interpolation='none'.

    import matplotlib.pyplot as plt
    import numpy as np
    
    img = np.random.uniform(0, 255, size=(2000, 2000)).astype(np.uint8)
    
    plt.imshow(img, interpolation='nearest')
    plt.show()
    

    I think that ‘none’ is roughly the same as ‘nearest’ when zooming in (image pixels are larger than screen pixels) but gives a higher-order interpolation result when zooming out (image pixels smaller than screen pixels). I think the delay comes from some extra Matplotlib/Python calculations needed for the rescaling.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.