Skip to content

Commit

Permalink
Merge pull request #23452 from scottshambaugh/axes3d_repr
Browse files Browse the repository at this point in the history
Generalize Axes __repr__ to 3D
  • Loading branch information
QuLogic committed Jul 21, 2022
2 parents 11a3e1b + c419cef commit 8afcbc2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/matplotlib/axes/_base.py
Expand Up @@ -732,10 +732,9 @@ def __repr__(self):
titles.append(f"{k!r}:{title!r}")
if titles:
fields += ["title={" + ",".join(titles) + "}"]
if self.get_xlabel():
fields += [f"xlabel={self.get_xlabel()!r}"]
if self.get_ylabel():
fields += [f"ylabel={self.get_ylabel()!r}"]
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) + ">"

@_api.delete_parameter("3.6", "args")
Expand Down
10 changes: 10 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Expand Up @@ -59,6 +59,16 @@ def test_get_labels():
assert ax.get_ylabel() == 'y label'


def test_repr():
fig, ax = plt.subplots()
ax.set_label('label')
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'>")


@check_figures_equal()
def test_label_loc_vertical(fig_test, fig_ref):
ax = fig_test.subplots()
Expand Down
13 changes: 13 additions & 0 deletions lib/mpl_toolkits/tests/test_mplot3d.py
Expand Up @@ -34,6 +34,19 @@ def test_aspect_equal_error():
ax.set_aspect('equal')


def test_axes3d_repr():
fig = plt.figure()
ax = fig.add_subplot(projection='3d')
ax.set_label('label')
ax.set_title('title')
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'>")


@mpl3d_image_comparison(['bar3d.png'])
def test_bar3d():
fig = plt.figure()
Expand Down

0 comments on commit 8afcbc2

Please sign in to comment.