Skip to content

Commit 7bd9bd9

Browse files
More code review changes and tests
1 parent de45ae1 commit 7bd9bd9

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ def __init__(
107107
focal_length : float, default: None
108108
For a projection type of 'persp', the focal length of the virtual
109109
camera. Must be > 0. If None, defaults to 1.
110+
For a projection type of 'ortho', must be set to either None
111+
or infinity (numpy.inf). If None, defaults to infinity.
110112
The focal length can be computed from a desired Field Of View via
111113
the equation: focal_length = 1/tan(FOV/2)
112114
@@ -1019,7 +1021,7 @@ def set_proj_type(self, proj_type, focal_length=None):
10191021
self._focal_length = focal_length
10201022
elif proj_type == 'ortho':
10211023
if focal_length not in (None, np.inf):
1022-
raise ValueError(f"focal_length = {focal_length} must be"
1024+
raise ValueError(f"focal_length = {focal_length} must be "
10231025
f"None for proj_type = {proj_type}")
10241026
self._focal_length = np.inf
10251027

lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,15 @@ def test_unautoscale(axis, auto):
10361036
np.testing.assert_array_equal(get_lim(), (-0.5, 0.5))
10371037

10381038

1039+
def test_axes3d_focal_length_checks():
1040+
fig = plt.figure()
1041+
ax = fig.add_subplot(projection='3d')
1042+
with pytest.raises(ValueError):
1043+
ax.set_proj_type('persp', focal_length=0)
1044+
with pytest.raises(ValueError):
1045+
ax.set_proj_type('ortho', focal_length=1)
1046+
1047+
10391048
@mpl3d_image_comparison(['axes3d_focal_length.png'], remove_text=False)
10401049
def test_axes3d_focal_length():
10411050
fig, axs = plt.subplots(1, 2, subplot_kw={'projection': '3d'})

0 commit comments

Comments
 (0)