On Thu, Sep 2, 2010 at 9:11 AM, Ryan May <rma...@gmail.com> wrote:
> On Thu, Sep 2, 2010 at 2:15 AM, Mitesh Patel <qed...@gmail.com> wrote:
> > Hello,
> >
> > Is it possible to specify both an alpha level and a background color so
> > that an entire saved image has a uniform transparency and color? For
> > example, with matplotlib 1.0.0, this script yields the attached image:
> >
> > from matplotlib.pyplot import figure, savefig, show
> >
> > fig = figure()
> > ax = fig.add_subplot(111)
> > ax.plot([1,2,3])
> >
> > fig.patch.set_alpha(0.5)
> > for ax in fig.axes:
> > ax.patch.set_alpha(0.5)
> >
> > fig.patch.set_facecolor('red')
> > for ax in fig.axes:
> > ax.patch.set_facecolor('red')
> >
> > savefig('test.png', facecolor='red')
> >
> >
> > In particular, the areas inside and outside the axes have different
> > transparency level and color. Perhaps I'm over/mis/ab-using the options
> > here?
>
> It's not that they're not uniform--you're seeing alpha blending
> between the figure patch and the axes patch. Within the axes, both are
> being rendered and blended together. This is more readily apparent if
> you use blue for the axes patch, as I did for the attached image. When
> the red and blue are blended together, you end up with purple. If you
> want it all uniform, you'd be better off setting the axes patch to an
> alpha of 0.0.
>
> Ryan
>
>
This also raises another pet peeve of mine. The Agg backend seems to use
linear blending for alpha. This is inconsistent with how the world works.
It is more realistic for logarithmic blending, or at least, a piece-wise
linear blending.
Imagine I have two overlapping objects with alpha set to .5 (a_1 and a_2).
What is rendered in matplotlib is completely opaque. A more realistic
result would have a final alpha setting of .75 (i.e. - the first item takes
away half the transparency, then the second item takes away half of the
remaining transparency.
I am not nearly familiar enough with the Agg backend to know how to
implement this. Is this at all feasible?
Ben Root
------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:
Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users