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

  • Home
  • SEARCH
  • 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 6391017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:37:13+00:00 2026-05-25T03:37:13+00:00

I need to visualize some data. It’s basic 2D grid, where each cell have

  • 0

I need to visualize some data. It’s basic 2D grid, where each cell have float value. I know how to e.g. assign color to value and paint grid in OpenCV. But the point here is that there are so many values so it’s nearly impossible to do that. I am looking for some method, where I could use gradient. For example value -5.0 will be represented by blue, 0 – black, and +5.0 as red. Is there any way to do that in Python?

Here is sample data I am talking about

        A       B       C        D
A    -1.045    2.0     3.5    -4.890
B    -5.678    3.2     2.89    5.78
  • 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-25T03:37:13+00:00Added an answer on May 25, 2026 at 3:37 am

    Matplotlib has the imshow method for plotting arrays:

    import matplotlib as mpl
    from matplotlib import pyplot
    import numpy as np
    
    # make values from -5 to 5, for this example
    zvals = np.random.rand(100,100)*10-5
    
    # make a color map of fixed colors
    cmap = mpl.colors.ListedColormap(['blue','black','red'])
    bounds=[-6,-2,2,6]
    norm = mpl.colors.BoundaryNorm(bounds, cmap.N)
    
    # tell imshow about color map so that only set colors are used
    img = pyplot.imshow(zvals,interpolation='nearest',
                        cmap = cmap,norm=norm)
    
    # make a color bar
    pyplot.colorbar(img,cmap=cmap,
                    norm=norm,boundaries=bounds,ticks=[-5,0,5])
    
    pyplot.show()
    

    This is what it looks like:

    enter image description here

    The details for the color bar setup were taken from a matplotlib example: colorbar_only.py. It explains that the number of boundaries need to be one larger then then number of colors.

    EDIT

    You should note, that imshow accepts the origin keyword, which sets the where the first point is assigned. The default is ‘upper left’, which is why in my posted plot the y axis has 0 in the upper left and 99 (not shown) in the lower left. The alternative is to set origin="lower", so that first point is plotted in the lower left corner.

    EDIT 2

    If you want a gradient and not a discrete color map, make a color map by linearly interpolating through a series of colors:

    fig = pyplot.figure(2)
    
    cmap2 = mpl.colors.LinearSegmentedColormap.from_list('my_colormap',
                                               ['blue','black','red'],
                                               256)
    
    img2 = pyplot.imshow(zvals,interpolation='nearest',
                        cmap = cmap2,
                        origin='lower')
    
    pyplot.colorbar(img2,cmap=cmap2)
    
    fig.savefig("image2.png")
    

    This produces:
    enter image description here

    EDIT 3

    To add a grid, as shown in this example, use the grid method. Setting the grid color to ‘white’ works well with the colors used by the colormap (ie the default black does not show up well).

    pyplot.grid(True,color='white')
    

    Including this before the savefig call produces this plot (made using 11×11 grid for clarity):
    enter image description here
    There are many options for grid, which are described in the matplotlib documentation. One you might be interested in is linewidth.

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

Sidebar

Related Questions

I have a structure I need to visualize. It contains of a set of
need ask you about some help. I have web app running in Net 2.0.
Need some help about with Memcache. I have created a class and want to
I have an application, which performs some custom data gathering, transformation and reporting. Currently,
I'm facing the need to enter ragged data in a WinForms application. Some columns
I have an xml file which I need to visualize in a pdf file.
I have some audio data (raw AAC) inside a byte array for playback. During
I am producing graphs in a Python program, and now I need to visualize
I need to process DICOM formatted medical images and visualize them in 3D, also
I'm thinking about creating a tool to visualize scientific data on a website. For

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.