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 30e05cc

Browse filesBrowse files
committed
DOC
1 parent a62c549 commit 30e05cc
Copy full SHA for 30e05cc

File tree

Expand file treeCollapse file tree

2 files changed

+53
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+53
-4
lines changed
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
`~.axes.Axes.set_title` gains a y keyword argument to control auto positioning
2+
------------------------------------------------------------------------------
3+
`~.axes.Axes.set_title` tries to auto-position the title to avoid any
4+
decorators on the top x-axis. This is not always desirable so now
5+
*y* is an explicit keyword argument of `~.axes.Axes.set_title`. It
6+
defaults to *None* which means to use auto-positioning. If a value is
7+
supplied (i.e. the pre-3.0 default was ``y=1.0``) then auto-positioning is
8+
turned off. This can also be set with the new rcParameter :rc:`axes.titley`.

‎examples/text_labels_and_annotations/titles_demo.py

Copy file name to clipboardExpand all lines: examples/text_labels_and_annotations/titles_demo.py
+45-4Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""
2-
===========
3-
Titles Demo
4-
===========
2+
=================
3+
Title positioning
4+
=================
55
6-
matplotlib can display plot titles centered, flush with the left side of
6+
Matplotlib can display plot titles centered, flush with the left side of
77
a set of axes, and flush with the right side of a set of axes.
88
99
"""
@@ -16,3 +16,44 @@
1616
plt.title('Right Title', loc='right')
1717

1818
plt.show()
19+
20+
###########################################################################
21+
# The vertical position is automatically chosen to avoid decorations
22+
# (i.e. labels and ticks) on the topmost x-axis:
23+
24+
fig, axs = plt.subplots(1, 2, constrained_layout=True)
25+
26+
ax = axs[0]
27+
ax.plot(range(10))
28+
ax.xaxis.set_label_position('top')
29+
ax.set_xlabel('X-label')
30+
ax.set_title('Center Title')
31+
32+
ax = axs[1]
33+
ax.plot(range(10))
34+
ax.xaxis.set_label_position('top')
35+
ax.xaxis.tick_top()
36+
ax.set_xlabel('X-label')
37+
ax.set_title('Center Title')
38+
plt.show()
39+
40+
###########################################################################
41+
# Automatic positioning can be turned off by manually specifying the
42+
# *y* kwarg for the title or setting :rc:`axes.titley` in the rcParams.
43+
44+
fig, axs = plt.subplots(1, 2, constrained_layout=True)
45+
46+
ax = axs[0]
47+
ax.plot(range(10))
48+
ax.xaxis.set_label_position('top')
49+
ax.set_xlabel('X-label')
50+
ax.set_title('Manual y', y=1.0, pad=-14)
51+
52+
plt.rcParams['axes.titley'] = 1.0 # y is in axes-relative co-ordinates.
53+
plt.rcParams['axes.titlepad'] = -14 # pad is in points...
54+
ax = axs[1]
55+
ax.plot(range(10))
56+
ax.set_xlabel('X-label')
57+
ax.set_title('rcParam y')
58+
59+
plt.show()

0 commit comments

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