Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 398e7b5

Browse files
committed
add framealpha argument for legend
1 parent 0179481 commit 398e7b5

File tree

7 files changed

+512
-1
lines changed

7 files changed

+512
-1
lines changed

examples/pylab_examples/legend_auto.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def fig_1():
1818
figure(1)
1919
t = arange(0, 40.0 * pi, 0.1)
2020
l, = plot(t, 100*sin(t), 'r', label='sine')
21-
legend()
21+
legend(framealpha=0.5)
2222

2323
def fig_2():
2424
figure(2)

lib/matplotlib/axes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4448,6 +4448,9 @@ def legend(self, *args, **kwargs):
44484448
If *True*, draw a shadow behind legend. If *None*,
44494449
use rc settings.
44504450
4451+
*framealpha*: [*None* | float]
4452+
If not None, alpha channel for legend frame. Default *None*.
4453+
44514454
*ncol* : integer
44524455
number of columns. default is 1
44534456

lib/matplotlib/legend.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ def __init__(self, parent, handles, labels,
167167
# box, none use rc
168168
shadow=None,
169169
title=None, # set a title for the legend
170+
171+
framealpha=None, #set frame alpha
172+
170173
bbox_to_anchor=None, # bbox that the legend will be anchored.
171174
bbox_transform=None, # transform for the bbox
172175
frameon=None, # draw frame
@@ -195,6 +198,7 @@ def __init__(self, parent, handles, labels,
195198
fancybox if True, draw a frame with a round fancybox.
196199
If None, use rc
197200
shadow if True, draw a shadow behind legend
201+
framealpha If not None, alpha channel for the frame.
198202
ncol number of columns
199203
borderpad the fractional whitespace inside the legend border
200204
labelspacing the vertical space between the legend entries
@@ -384,6 +388,9 @@ def __init__(self, parent, handles, labels,
384388
# init with null renderer
385389
self._init_legend_box(handles, labels)
386390

391+
if framealpha is not None:
392+
self.get_frame().set_alpha(framealpha)
393+
387394
self._loc = loc
388395

389396
self.set_title(title)
Binary file not shown.

0 commit comments

Comments
 (0)