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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:34:03+00:00 2026-05-20T10:34:03+00:00

So i have a meshgrid (matrices X and Y) together with scalar data (matrix

  • 0

So i have a meshgrid (matrices X and Y) together with scalar data (matrix Z), and i need to visualize this. Preferably some 2D image with colors at the points showing the value of Z there.
I’ve done some research but haven’t found anything which does exactly what i want.

pyplot.imshow(Z) has a good look, but it doesn’t take my X and Y matrices, so the axes are wrong and it is unable to handle non-linearly spaced points given by X and Y.

pyplot.pcolor(X,Y,Z) makes colored squares with colors corresponding to the data at one of its corners, so it kind of misrepresents the data (it should show the data in its center or something). In addition it ignores two of the edges from the data matrix.

I pretty sure there must exist some better way somewhere in Matplotlib, but the documentation makes it hard to get an overview. So i’m asking if someone else knows of a better way. Bonus if it allows me to refresh the matrix Z to make an animation.

  • 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-20T10:34:04+00:00Added an answer on May 20, 2026 at 10:34 am

    This looks nice, but it’s inefficient:

    from pylab import *
    origin = 'lower'
    
    delta = 0.025
    
    x = y = arange(-3.0, 3.01, delta)
    X, Y = meshgrid(x, y)
    Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
    Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
    Z = 10 * (Z1 - Z2)
    
    nr, nc = Z.shape
    
    CS = contourf(
        X, Y, Z,
        levels = linspace(Z.min(), Z.max(), len(x)),
        ls = '-',
        cmap=cm.bone,
        origin=origin)
    
    CS1 = contour(
        CS,
        levels = linspace(Z.min(), Z.max(), len(x)),
        ls = '-',
        cmap=cm.bone,
        origin=origin)
    
    show()
    

    It it were me, I’d re-interpolate (using scipy.interpolate) the data to a regular grid and use imshow(), setting the extents to fix the axes.

    fine contour

    Edit (per comment):

    Animating a contour plot can be accomplished like this, but, like I said, the above is inefficient just plain abuse of the contour plot function. The most efficient way to do what you want is to employ SciPy. Do you have that installed?

    import matplotlib
    matplotlib.use('TkAgg') # do this before importing pylab
    import time
    import matplotlib.pyplot as plt
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    
    def animate():
        origin = 'lower'
        delta = 0.025
    
        x = y = arange(-3.0, 3.01, delta)
        X, Y = meshgrid(x, y)
        Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
        Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
        Z = 10 * (Z1 - Z2)
    
        CS1 = ax.contourf(
            X, Y, Z,
            levels = linspace(Z.min(), Z.max(), 10),
            cmap=cm.bone,
            origin=origin)
    
        for i in range(10):
            tempCS1 = contourf(
                X, Y, Z,
                levels = linspace(Z.min(), Z.max(), 10),
                cmap=cm.bone,
                origin=origin)
            del tempCS1
            fig.canvas.draw()
            time.sleep(0.1)
            Z += x/10
    
    win = fig.canvas.manager.window
    fig.canvas.manager.window.after(100, animate)
    plt.show()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

have such zend query: $select = $this->_table ->select() ->where('title LIKE ?', '%'.$searchWord.'%') ->where('description LIKE
Have a look at the menus on this page: http://www.pieterdedecker.be/labs/vspwpg/?page_id=96 They look okay in
Have a build process that can't be edited and need to pack another war
I have a custom function which returns either 0 or 1 depending on two
Have noticed issue while testing iphone app that if one quickly opens/dismisses a modal
Have I correctly added an element to a hashTable? Flows flows = new Flows(sIP,dIP);
Have you seen library for flexible working with terminal(Unix like)? I want to implement
Have following setup: MainActivity class - extends activity MyLayout class - extends View Prefs
have a table that dynamically generates text boxes in run time. I want to
have anyone seen a Solr plugin example written in Clojure? I guess it should

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.