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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:05:34+00:00 2026-05-14T03:05:34+00:00

How does one control the transparency over a 2D image in pylab? I’d like

  • 0

How does one control the transparency over a 2D image in pylab? I’d like to give two sets of values (X,Y,Z,T) where X,Y are arrays of positions, Z is the color value, and T is the transparency to a function like imshow but it seems that the function only takes alpha as a scalar. As a concrete example, consider the code below that attempts to display two Gaussians. The closer the value is to zero, the more transparent I’d like the plot to be.

from pylab import *

side = linspace(-1,1,100)
X,Y  = meshgrid(side,side)

extent = (-1,1,-1,1)

Z1  = exp(-((X+.5)**2+Y**2))
Z2  = exp(-((X-.5)**2+(Y+.2)**2))

imshow(Z1, cmap=cm.hsv, alpha=.6, extent=extent)
imshow(Z2, cmap=cm.hsv, alpha=.6, extent=extent)
show()

Note: I am not looking for a plot of Z1+Z2 (that would be trivial) but for a general way to specify the alpha blending across an image.

  • 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-14T03:05:35+00:00Added an answer on May 14, 2026 at 3:05 am

    One thing that you can do is modify what you put into imshow. The first variable can be grayscale values as you have used or it can be RGB or RGBA values. If you RGB/RGBA values then the cmap is ignored. So for instance,

    imshow(Z1, cmap=cm.hsv, alpha=.6, extent=extent)
    

    will generate the same image as

    imshow(cm.hsv(Z1), alpha=.6, extent=extent)
    

    because cm.hsv()just returns RGBA values. If you take a look at the values it returns, they all have 1.0 as the A value (the transparency). So one way to make variable transparency would be something like this:

    def mycmap(x):
        tmp = cm.hsv(x)
        for i in xrange(tmp.shape[0]):
            for j in xrange(tmp.shape[0]):
                tmp[i,j][3] = somefunction of x[i,j] that generates the transparency
        return tmp
    
    imshow(mycmap(Z1), extent=extent)
    imshow(mycmap(Z2), extent=extent)
    

    You might find a little more elegant way of doing this, but hopefully you get the idea.

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

Sidebar

Related Questions

How does one bind an iPhone SDK control (say a UISlider) using Interface Builder?
I have an ASP.NET webforms application with a Menu control. How does one hide
Does any one know of a control that i can use with a ASP.Net
Does any one know of a way to control how Visual Studio handles curly
does anybody know how to make a numericupdown control for asp. There's one for
How does one convert an image from one color profile to another (screen to
How does one go about authoring a Regular Expression that matches against all strings
How does one go about referencing a class's static properties in xaml? In other
How does one go about programatically building a TemplateColumn object and adding it to
How does one handle a DateTime with a NOT NULL ? I want to

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.