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

Skip to content

Commit 64661db

Browse files
committed
Add legend.labelcolor in rcParams
1 parent 93e716d commit 64661db

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
New rcParams for ledend: set legend labelcolor globaly
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
The new :rc:`legend.labelcolor` allows toggling valid color string(for example, 'black'),
5+
versus choosing to match the color of the line of marker using 'linecolor',
6+
'markerfacecolor'(or 'mfc'), or 'markeredgecolor' (or 'mec').
7+
8+
.. plot::
9+
10+
import numpy as np
11+
import matplotlib.pyplot as plt
12+
13+
# Make some fake data.
14+
a = np.arange(0, 3, .02)
15+
c = np.exp(a)
16+
d = c[::-1]
17+
plt.rcParams['legend.labelcolor'] = 'linecolor'
18+
19+
20+
fig, ax = plt.subplots()
21+
ax.plot(a, c, 'g--', label='Model length')
22+
ax.plot(a, d, 'r:', label='Data length')
23+
24+
legend = ax.legend()
25+
26+
plt.show()

lib/matplotlib/legend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,8 @@ def __init__(self, parent, handles, labels,
544544
'mec': ['get_markeredgecolor', 'get_edgecolor'],
545545
}
546546
if labelcolor is None:
547-
pass
548-
elif isinstance(labelcolor, str) and labelcolor in color_getters:
547+
labelcolor = mpl.rcParams['legend.labelcolor']
548+
if isinstance(labelcolor, str) and labelcolor in color_getters:
549549
getter_names = color_getters[labelcolor]
550550
for handle, text in zip(self.legendHandles, self.texts):
551551
for getter_name in getter_names:

lib/matplotlib/mpl-data/matplotlibrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@
530530
#legend.scatterpoints: 1 # number of scatter points
531531
#legend.markerscale: 1.0 # the relative size of legend markers vs. original
532532
#legend.fontsize: medium
533+
#legend.labelcolor: black
533534
#legend.title_fontsize: None # None sets to the same as the default axes.
534535

535536
## Dimensions as fraction of font size:

lib/matplotlib/rcsetup.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,17 @@ def validate_color_for_prop_cycle(s):
289289
return validate_color(s)
290290

291291

292+
def validate_color_or_linecolor(s):
293+
if cbook._str_equal(s, 'linecolor'):
294+
return s
295+
elif cbook._str_equal(s, 'mfc') or cbook._str_equal(s, 'markerfacecolor'):
296+
return 'markerfacecolor'
297+
elif cbook._str_equal(s, 'mec') or cbook._str_equal(s, 'markerfacecolor'):
298+
return 'markeredgecolor'
299+
300+
return validate_color(s)
301+
302+
292303
def validate_color(s):
293304
"""Return a valid color arg."""
294305
if isinstance(s, str):
@@ -1017,6 +1028,7 @@ def _convert_validator_spec(key, conv):
10171028
"legend.scatterpoints": validate_int,
10181029
"legend.fontsize": validate_fontsize,
10191030
"legend.title_fontsize": validate_fontsize_None,
1031+
"legend.labelcolor": validate_color_or_linecolor, #color of the legend
10201032
# the relative size of legend markers vs. original
10211033
"legend.markerscale": validate_float,
10221034
"legend.shadow": validate_bool,

0 commit comments

Comments
 (0)