Why can't I change my artist's alpha?

Hi
I want my plot to be visible when I display some text over it. Why
doesn't this work?
fig = plt.figure(figsize=(5,5), dpi=100)
ax=fig.add_axes([0.1,0.1,0.8,.8])
ax.hist(data)
box1 = TextArea("Minimum: %f" % mind, textprops=dict(color="k"))
box2 = TextArea("Maximum: %f" % maxd, textprops=dict(color="k"))
box = VPacker(children=[box1,box2],
              align="center",
              pad=0, sep=5)
anchored_box = AnchoredOffsetbox(loc=3,
                                 child=box, pad=0.,
                                 frameon=True,
                                 bbox_to_anchor=(0.8, 0.72),
                                 bbox_transform=ax.transAxes,
                                 borderpad=0.,
                                 )

art=ax.add_artist(anchored_box)
art.set_alpha(0.5)

-Mathew

Mathew,

Could you please include a completely self-contained version of the script for us to try out? Plus, which version of matplotlib are you using?

Ben Root

···

On Mon, Aug 16, 2010 at 10:59 AM, Mathew Yeates <mat.yeates@…878…287…> wrote:

Hi

I want my plot to be visible when I display some text over it. Why

doesn’t this work?

fig = plt.figure(figsize=(5,5), dpi=100)

ax=fig.add_axes([0.1,0.1,0.8,.8])

ax.hist(data)

box1 = TextArea(“Minimum: %f” % mind, textprops=dict(color=“k”))

box2 = TextArea(“Maximum: %f” % maxd, textprops=dict(color=“k”))

box = VPacker(children=[box1,box2],

          align="center",

          pad=0, sep=5)

anchored_box = AnchoredOffsetbox(loc=3,

                             child=box, pad=0.,

                             frameon=True,

                             bbox_to_anchor=(0.8, 0.72),

                             bbox_transform=ax.transAxes,

                             borderpad=0.,

                             )

art=ax.add_artist(anchored_box)

art.set_alpha(0.5)

-Mathew

Thanks, Ben, but I figured out that I just needed to use
frameon=False. This way, I can see teh plot under the text.

Thx

···

On Mon, Aug 16, 2010 at 9:16 AM, Benjamin Root <ben.root@...1304...> wrote:

On Mon, Aug 16, 2010 at 10:59 AM, Mathew Yeates <mat.yeates@...287...> > wrote:

Hi
I want my plot to be visible when I display some text over it. Why
doesn't this work?
fig = plt.figure(figsize=(5,5), dpi=100)
ax=fig.add_axes([0.1,0.1,0.8,.8])
ax.hist(data)
box1 = TextArea("Minimum: %f" % mind, textprops=dict(color="k"))
box2 = TextArea("Maximum: %f" % maxd, textprops=dict(color="k"))
box = VPacker(children=[box1,box2],
align="center",
pad=0, sep=5)
anchored_box = AnchoredOffsetbox(loc=3,
child=box, pad=0.,
frameon=True,
bbox_to_anchor=(0.8, 0.72),
bbox_transform=ax.transAxes,
borderpad=0.,
)

art=ax.add_artist(anchored_box)
art.set_alpha(0.5)

-Mathew

Mathew,

Could you please include a completely self-contained version of the script
for us to try out? Plus, which version of matplotlib are you using?

Ben Root

Those artist in offsetbox module (e.g., TextArea, VPacker,
AnchoredOffsetbox) are mostly a container object, i.e., actual drawing
is done by other artists. And changing the artist attributes of the
container object often does not work.
In your case (I guess you want to make the frame translucent?), the
actual artist responsible for drawing the frame is anchored_box.patch
(==art.patch). So

anchored_box.patch.set_alpha(0.5)

should work.

-JJ

···

On Tue, Aug 17, 2010 at 12:59 AM, Mathew Yeates <mat.yeates@...287...> wrote:

Hi
I want my plot to be visible when I display some text over it. Why
doesn't this work?
fig = plt.figure(figsize=(5,5), dpi=100)
ax=fig.add_axes([0.1,0.1,0.8,.8])
ax.hist(data)
box1 = TextArea("Minimum: %f" % mind, textprops=dict(color="k"))
box2 = TextArea("Maximum: %f" % maxd, textprops=dict(color="k"))
box = VPacker(children=[box1,box2],
align="center",
pad=0, sep=5)
anchored_box = AnchoredOffsetbox(loc=3,
child=box, pad=0.,
frameon=True,
bbox_to_anchor=(0.8, 0.72),
bbox_transform=ax.transAxes,
borderpad=0.,
)

art=ax.add_artist(anchored_box)
art.set_alpha(0.5)

-Mathew

------------------------------------------------------------------------------
This SF.net email is sponsored by

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users