Skip to content

Tweak Axes repr. #23461

New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,18 +724,18 @@ def __repr__(self):
fields = []
if self.get_label():
fields += [f"label={self.get_label()!r}"]
titles = []
for k in ["left", "center", "right"]:
if hasattr(self, 'get_title'):
if hasattr(self, "get_title"):
titles = {}
for k in ["left", "center", "right"]:
title = self.get_title(loc=k)
if title:
titles.append(f"{k!r}:{title!r}")
if titles:
fields += ["title={" + ",".join(titles) + "}"]
titles[k] = title
if titles:
fields += [f"title={titles}"]
for name, axis in self._axis_map.items():
if axis.get_label() and axis.get_label().get_text():
fields += [f"{name}label={axis.get_label().get_text()!r}"]
return f"<{self.__class__.__name__}:" + ", ".join(fields) + ">"
return f"<{self.__class__.__name__}: " + ", ".join(fields) + ">"

@_api.delete_parameter("3.6", "args")
@_api.delete_parameter("3.6", "kwargs")
Expand Down
7 changes: 4 additions & 3 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ def test_repr():
ax.set_title('title')
ax.set_xlabel('x')
ax.set_ylabel('y')
assert repr(ax) == ("<AxesSubplot:label='label', " +
"title={'center':'title'}, xlabel='x', ylabel='y'>")
assert repr(ax) == (
"<AxesSubplot: "
"label='label', title={'center': 'title'}, xlabel='x', ylabel='y'>")


@check_figures_equal()
Expand Down Expand Up @@ -7046,7 +7047,7 @@ def test_secondary_formatter():
def test_secondary_repr():
fig, ax = plt.subplots()
secax = ax.secondary_xaxis("top")
assert repr(secax) == '<SecondaryAxis:>'
assert repr(secax) == '<SecondaryAxis: >'


def color_boxes(fig, ax):
Expand Down
6 changes: 3 additions & 3 deletions lib/mpl_toolkits/tests/test_mplot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def test_axes3d_repr():
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
assert repr(ax) == ("<Axes3DSubplot:label='label', " +
"title={'center':'title'}, " +
"xlabel='x', ylabel='y', zlabel='z'>")
assert repr(ax) == (
"<Axes3DSubplot: label='label', "
"title={'center': 'title'}, xlabel='x', ylabel='y', zlabel='z'>")


@mpl3d_image_comparison(['bar3d.png'])
Expand Down