Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Add framealpha argument for legend #1626

Merged
merged 2 commits into from Jan 17, 2013

Conversation

Projects
None yet
5 participants
Contributor

piti118 commented Dec 28, 2012

Straight from matplotlib recipe. I think frame alpha belongs to keyword argument like

ax.legend(framealpha=0.5)

rather than

leg = ax.legend()
leg.get_frame().set_alpha(0.5)
Member

dmcdougall commented Dec 30, 2012

Travis failure looks like a dud.

This seems like a simple enough wrapper around .get_frame().set_alpha(). I'd be happy for this to be merged.

Anybody else want to give a +1 or other feedback?

Edit: Barring minor style issues below.

@dmcdougall dmcdougall commented on an outdated diff Dec 30, 2012

lib/matplotlib/tests/test_legend.py
@@ -46,3 +46,10 @@ def test_fancy():
plt.errorbar(range(10), range(10), xerr=0.5, yerr=0.5, label='XX')
plt.legend(loc="center left", bbox_to_anchor=[1.0, 0.5],
ncol=2, shadow=True, title="My legend", numpoints=1)
+
+@image_comparison(baseline_images=['framealpha'], remove_text=True)
+def test_framealpha():
+ x = np.linspace(1,100,100)
+ y = x
+ plt.plot(x,y, label='mylabel', lw=10)
@dmcdougall

dmcdougall Dec 30, 2012

Member

Could you add a space after the first comma? Like so: plt.plot(x, y, label='mylabel', lw=10).

@dmcdougall dmcdougall commented on an outdated diff Dec 30, 2012

lib/matplotlib/legend.py
@@ -167,6 +167,9 @@ def __init__(self, parent, handles, labels,
# box, none use rc
shadow=None,
title=None, # set a title for the legend
+
+ framealpha=None, #set frame alpha
@dmcdougall

dmcdougall Dec 30, 2012

Member

Another PEP8 issue: Add an extra space before and after the #.

Owner

mdboom commented Jan 16, 2013

Seems fine -- perhaps it's a needless proliferation of keyword arguments -- OTOH, I can see why this is a common thing someone would want to do. @pelson: do you want to ring in on this?

Contributor

piti118 commented Jan 16, 2013

Both ways to get transparency doesn't work well with shadow though since shadow option assume full opacity of the legend frame.

Owner

mdboom commented Jan 16, 2013

Hmmm... should we fix shadow while we're at it, then?

Contributor

piti118 commented Jan 16, 2013

This is what it looks like. It looks funny but I'm not sure what I should expect....
tmp

plot(range(10),range(10),label='hey')
legend(shadow=True).get_frame().set_alpha(0.5)
Member

pelson commented Jan 17, 2013

@pelson: do you want to ring in on this?

No complaints from me.

Owner

mdboom commented Jan 17, 2013

I think the shadow issue is probably fine for now... I agree -- it's not clear what it should do instead. @piti118: can you please rebase this on master so we can hit that big green merge button?

Member

WeatherGod commented Jan 17, 2013

That does look funny to me, but I can understand why some might not think
it is. I have played around a lot with shadowing effects and alphas with
non-white overlays that have taught me otherwise. Try the legend in a
different color, and I think you will see what I mean.

Contributor

piti118 commented Jan 17, 2013

Rebased.. I think I did it right.

Owner

mdboom commented Jan 17, 2013

Yep. Looks good. Merging.

@mdboom mdboom added a commit that referenced this pull request Jan 17, 2013

@mdboom mdboom Merge pull request #1626 from piti118/legend_frame_alpha
Add framealpha argument for legend
a53a6f7

@mdboom mdboom merged commit a53a6f7 into matplotlib:master Jan 17, 2013

Contributor

piti118 commented Jan 17, 2013

Hmmm... I think I didn't write the change log...

@piti118 piti118 added a commit to piti118/matplotlib that referenced this pull request Jan 17, 2013

@piti118 piti118 add changelog for #1626 88554a6
Owner

mdboom commented Jan 17, 2013

Oh, thanks. I should have noticed it before merging. I should be able to merge that manually. No worries.

Contributor

piti118 commented Jan 17, 2013

just pull #1677

@mdboom mdboom added a commit that referenced this pull request Jan 17, 2013

@piti118 @mdboom piti118 + mdboom add changelog for #1626 a6af0b2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment