Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f529ced

Browse filesBrowse files
OriolAbriltimhoffm
authored andcommitted
Add titlecolor in rcParams (#14707)
* make ax.set_title use axes.labelcolor * Add axes.titlecolor to rcParams * Update docs * Add axes title to style_sheets_reference * Update matplotlibrc.template * Add changes to what's new * rename what's new file * Add test * Add auto behaviour in rctemplate comment
1 parent 3ae55e1 commit f529ced
Copy full SHA for f529ced

File tree

Expand file treeCollapse file tree

7 files changed

+24
-6
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+24
-6
lines changed

‎doc/users/next_whats_new/2019-03-29-rcparam-axes-titlelocation.rst

Copy file name to clipboardExpand all lines: doc/users/next_whats_new/2019-03-29-rcparam-axes-titlelocation.rst
-6Lines changed: 0 additions & 6 deletions
This file was deleted.
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
rcParams for default axes title location and color
2+
--------------------------------------------------
3+
4+
Two new rcParams have been added: ``axes.titlelocation`` denotes the default axes title
5+
alignment, and ``axes.titlecolor`` the default axes title color.
6+
7+
Valid values for ``axes.titlelocation`` are: left, center, and right.
8+
Valid values for ``axes.titlecolor`` are: auto or a color. Setting it to auto
9+
will fall back to previous behaviour, which is using the color in ``text.color``.

‎examples/style_sheets/style_sheets_reference.py

Copy file name to clipboardExpand all lines: examples/style_sheets/style_sheets_reference.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def plot_scatter(ax, prng, nb_samples=100):
2323
x, y = prng.normal(loc=mu, scale=sigma, size=(2, nb_samples))
2424
ax.plot(x, y, ls='none', marker=marker)
2525
ax.set_xlabel('X-label')
26+
ax.set_title('Axes title')
2627
return ax
2728

2829

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ def set_title(self, label, fontdict=None, loc=None, pad=None,
164164
165165
{'fontsize': rcParams['axes.titlesize'],
166166
'fontweight' : rcParams['axes.titleweight'],
167+
'color' : rcParams['axes.titlecolor'],
167168
'verticalalignment': 'baseline',
168169
'horizontalalignment': loc}
169170
@@ -199,6 +200,9 @@ def set_title(self, label, fontdict=None, loc=None, pad=None,
199200
'fontweight': rcParams['axes.titleweight'],
200201
'verticalalignment': 'baseline',
201202
'horizontalalignment': loc.lower()}
203+
titlecolor = rcParams['axes.titlecolor']
204+
if not cbook._str_lower_equal(titlecolor, 'auto'):
205+
default["color"] = titlecolor
202206
if pad is None:
203207
pad = rcParams['axes.titlepad']
204208
self._set_title_offset_trans(float(pad))

‎lib/matplotlib/rcsetup.py

Copy file name to clipboardExpand all lines: lib/matplotlib/rcsetup.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,7 @@ def _validate_linestyle(ls):
11321132
# axes title
11331133
'axes.titlelocation': ['center', validate_axes_titlelocation], # alignment of axes title
11341134
'axes.titleweight': ['normal', validate_string], # font weight of axes title
1135+
'axes.titlecolor': ['auto', validate_color_or_auto], # font color of axes title
11351136
'axes.titlepad': [6.0, validate_float], # pad from axes top to title in points
11361137
'axes.grid': [False, validate_bool], # display grid or not
11371138
'axes.grid.which': ['major', validate_axis_locator], # set whether the gid are by

‎lib/matplotlib/tests/test_rcparams.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_rcparams.py
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,13 @@ def test_mec_rcparams():
179179
assert ln.get_markeredgecolor() == 'r'
180180

181181

182+
def test_axes_titlecolor_rcparams():
183+
mpl.rcParams['axes.titlecolor'] = 'r'
184+
_, ax = plt.subplots()
185+
title = ax.set_title("Title")
186+
assert title.get_color() == 'r'
187+
188+
182189
def test_Issue_1713(tmpdir):
183190
rcpath = Path(tmpdir) / 'test_rcparams.rc'
184191
rcpath.write_text('timezone: UTC', encoding='UTF-32-BE')

‎matplotlibrc.template

Copy file name to clipboardExpand all lines: matplotlibrc.template
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,8 @@
358358
#axes.titlelocation : center ## alignment of the title: {left, right, center}
359359
#axes.titlesize : large ## fontsize of the axes title
360360
#axes.titleweight : normal ## font weight of title
361+
#axes.titlecolor : auto ## color of the axes title, auto falls back to text.color
362+
## as default value
361363
#axes.titlepad : 6.0 ## pad between axes and title in points
362364
#axes.labelsize : medium ## fontsize of the x any y labels
363365
#axes.labelpad : 4.0 ## space between label and axis

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.