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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:20:27+00:00 2026-06-02T00:20:27+00:00

I would like to compare two different sets of data on the same imshow

  • 0

I would like to compare two different sets of data on the same imshow plot to make it easy to see the differences.
My first instinct is to make the colors in the colormap transparent (the lower values especially) but I haven’t been able to get this to work:

from matplotlib.colors import colorConverter
import matplotlib.pyplot as plt
import numpy as np

# create dummy data
zvals =  np.random.rand(100,100)*10-5
zvals2 = np.random.rand(100,100)*10-5

# generate the transparent colors
color1 = colorConverter.to_rgba('white',alpha=0.0)
color2 = colorConverter.to_rgba('black',alpha=0.8)

# make the colormaps
cmap1 = mpl.colors.LinearSegmentedColormap.from_list('my_cmap',['green','blue'],256)
cmap2 = mpl.colors.LinearSegmentedColormap.from_list('my_cmap2',[color1,color2],256)

img2 = plt.imshow(zvals,interpolation='nearest',cmap=cmap1,origin='lower')
img3 = plt.imshow(zvals2,interpolation='nearest',cmap=cmap2,origin='lower')

plt.show()

There is no error but the white and black of the second plot do not show any transparency. I also tried the colorConverter method to set the color in a normal plt.plot situation and the color also did not become transparent though the correct color was displayed.

Any additional advice on how to overlay/compare imshow plots would be much appreciated

  • 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-02T00:20:29+00:00Added an answer on June 2, 2026 at 12:20 am

    You can set the alpha argument in your imshow command.

    In your example, img3 = plt.imshow(zvals2, interpolation='nearest', cmap=cmap2, origin='lower', alpha=0.6)

    EDIT:

    Thanks for the clarification.
    Here is a description of what you can do:

    • First, choose a matplotlib colormap object (in your case, for white and black, you can take the ‘binary’ colormap). Or create your own colormap as you did, if the colormap you want doesn’t already exist.
    • Then initialize this colormap object: this will cause it to internally create an array called "_lut" which holds rgba values.
    • Then, you can fill the alpha values according to what you want to achieve (in your example, create an array from 0 to 0.8)
    • You can then use this colormap

    Below is an example using your code:

    from matplotlib.colors import colorConverter
    import matplotlib.pyplot as plt
    import numpy as np
    import matplotlib as mpl
    
    # create dummy data
    zvals = np.ones((100,100))# np.random.rand(100,100)*10-5
    zvals2 = np.random.rand(100,100)*10-5
    
    # generate the colors for your colormap
    color1 = colorConverter.to_rgba('white')
    color2 = colorConverter.to_rgba('black')
    
    # make the colormaps
    cmap1 = mpl.colors.LinearSegmentedColormap.from_list('my_cmap',['green','blue'],256)
    cmap2 = mpl.colors.LinearSegmentedColormap.from_list('my_cmap2',[color1,color2],256)
    
    cmap2._init() # create the _lut array, with rgba values
    
    # create your alpha array and fill the colormap with them.
    # here it is progressive, but you can create whathever you want
    alphas = np.linspace(0, 0.8, cmap2.N+3)
    cmap2._lut[:,-1] = alphas
    
    img2 = plt.imshow(zvals, interpolation='nearest', cmap=cmap1, origin='lower')
    img3 = plt.imshow(zvals2, interpolation='nearest', cmap=cmap2, origin='lower')
    
    plt.show()
    

    image

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

Sidebar

Related Questions

I would like to be able to compare two classes derived from the same
I want to compare two List of different lengths and/or same length. The first
I would like to compare two dates in javascript. I have been doing some
I would like to compare two tables and then update if some logic is
I would like to know if there is anyway I can compare two columns
I have two arrays that I would like to compare and ultimately wind up
I'm looking to compare two varchars in SQL, one would be something like Cafe
I would like to compare two versions of a class. I have used WinDiff,
I would like to know if using VBA I can compare two similar excel
I have two files that I would like to compare, however they are each

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.