PNG transparency

Hi all,

Is it possible to produce transparent png's with mpl ?

Nils

Yes, but you must explicitly set the transparency on every object you
want to be transparent::

  fig = plt.figure()
  fig.figurePatch.set_alpha(0.5)

  ax = fig.add_subplot(111)
  ax.axesPatch.set_alpha(0.5)

  l, = ax.plot(x, y, alpha=0.8)

  t = ax.set_xlabel('hi', alpha=0.8)

and so on....

I wonder if we should support a global rc alpha....

JDH

PS: these kinds of questions are best for the users list. In general:
"how do I?" or "does such a feature exist?" or "why doesn't this
work?" or "can you add this feature?" should go on users. "this is
broken in svn" or "will you accept this patch" or "shouldn't the
function x do something else?" and the like should be on the devel

···

On Wed, Jun 18, 2008 at 8:56 AM, Nils Wagner <nwagner@...425...> wrote:

Is it possible to produce transparent png's with mpl ?

+1

  Nils

···

On Wed, 18 Jun 2008 09:17:27 -0500 "John Hunter" <jdh2358@...149...> wrote:

On Wed, Jun 18, 2008 at 8:56 AM, Nils Wagner > <nwagner@...425...> wrote:

Is it possible to produce transparent png's with mpl ?

Yes, but you must explicitly set the transparency on every object you
want to be transparent::

fig = plt.figure()
fig.figurePatch.set_alpha(0.5)

ax = fig.add_subplot(111)
ax.axesPatch.set_alpha(0.5)

l, = ax.plot(x, y, alpha=0.8)

t = ax.set_xlabel('hi', alpha=0.8)

and so on....

I wonder if we should support a global rc alpha....

Nils Wagner wrote:

···

  "John Hunter" <jdh2358@...149...> wrote:

I wonder if we should support a global rc alpha....

I'd make it an optional parameter to savefig(), but I like the idea.

Of course one could pretty easily post-process it as well.

-CHB

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...236...

Of course, this depends on what you mean by transparency. If you mean to change the alpha of the entire PNG, then yes, the global parameter (or postprocessing) is the way to go. But I'm not sure how useful that is -- that will still lighten things behind the figure and axes patch.

A more useful option, IMHO, would be to just make the figure patch and axes patch fully transparent and leave everything else "as is". That avoids the "white box on a colored background" problem.

Cheers,
Mike

Christopher Barker wrote:

···

Nils Wagner wrote:
  

  "John Hunter" <jdh2358@...149...> wrote:
    

I wonder if we should support a global rc alpha....
      
I'd make it an optional parameter to savefig(), but I like the idea.

Of course one could pretty easily post-process it as well.

-CHB

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Nils,

I saw your bump about this transparency issue. Before moving forward on this, I'd like to know what your use case is. I've attached a mock-up example. On the left is the effect of changing the alpha value of everything to 50% (what you and Christopher had suggested). But it seems to me what you really want is on the right -- making only the figure and axes patch fully-transparent. This is what one would want, for example, when putting a plot on the colored background of a webpage. I don't understand why anyone would want the one on the left, but if you can provide a use case for it, it should be implementable.

Cheers,
Mike

Michael Droettboom wrote:

transparency_examples.png

···

Of course, this depends on what you mean by transparency. If you mean to change the alpha of the entire PNG, then yes, the global parameter (or postprocessing) is the way to go. But I'm not sure how useful that is -- that will still lighten things behind the figure and axes patch.

A more useful option, IMHO, would be to just make the figure patch and axes patch fully transparent and leave everything else "as is". That avoids the "white box on a colored background" problem.

Cheers,
Mike

Christopher Barker wrote:
  

Nils Wagner wrote:
  

  "John Hunter" <jdh2358@...149...> wrote:
    

I wonder if we should support a global rc alpha....
      

I'd make it an optional parameter to savefig(), but I like the idea.

Of course one could pretty easily post-process it as well.

-CHB

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

John wrote:

"I believe the unspoken consensus was it is easy to set the alpha on
the figurePatch and axesPatch so a global alpha was unneccessary."

It still might be convenient to make this an option on savefig. Sure it's only a few lines of code, but not necessarily obvious lines of code.

Waiting to hear back from Nils as to whether this is really what he wants, though.

Cheers,
Mike

Michael Droettboom wrote:

···

Nils,

I saw your bump about this transparency issue. Before moving forward on this, I'd like to know what your use case is. I've attached a mock-up example. On the left is the effect of changing the alpha value of everything to 50% (what you and Christopher had suggested). But it seems to me what you really want is on the right -- making only the figure and axes patch fully-transparent. This is what one would want, for example, when putting a plot on the colored background of a webpage. I don't understand why anyone would want the one on the left, but if you can provide a use case for it, it should be implementable.

Cheers,
Mike

Michael Droettboom wrote:

Of course, this depends on what you mean by transparency. If you mean to change the alpha of the entire PNG, then yes, the global parameter (or postprocessing) is the way to go. But I'm not sure how useful that is -- that will still lighten things behind the figure and axes patch.
A more useful option, IMHO, would be to just make the figure patch and axes patch fully transparent and leave everything else "as is". That avoids the "white box on a colored background" problem.

Cheers,
Mike

Christopher Barker wrote:

Nils Wagner wrote:
     

  "John Hunter" <jdh2358@...149...> wrote:
         

I wonder if we should support a global rc alpha....
              

I'd make it an optional parameter to savefig(), but I like the idea.

Of course one could pretty easily post-process it as well.

-CHB

------------------------------------------------------------------------

------------------------------------------------------------------------

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
------------------------------------------------------------------------

_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
  
--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Michael Droettboom wrote:

I don't understand why anyone would want the one on the left, but if you can provide a use case for it, it should be implementable.

I know I can't. I think john may be right that it's just not that hard to do by hand.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...236...