Skip to content

Commit b0135c7

Browse files
Additional code review changes
1 parent 7bd9bd9 commit b0135c7

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

doc/users/next_whats_new/3d_plot_focal_length.rst

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@ Give the 3D camera a custom focal length
22
----------------------------------------
33

44
Users can now better mimic real-world cameras by specifying the focal length of
5-
the virtual camera in 3D plots. An increasing focal length between 1 and
6-
infinity "flattens" the image, while a decreasing focal length between 1 and 0
7-
exaggerates the perspective and gives the image more apparent depth. The
8-
default focal length of 1 corresponds to a Field of View (FOV) of 90 deg, and
9-
is backwards-compatible with existing 3D plots.
5+
the virtual camera in 3D plots. The default focal length of 1 corresponds to a
6+
Field of View (FOV) of 90 deg, and is backwards-compatible with existing 3D
7+
plots. An increased focal length between 1 and infinity "flattens" the image,
8+
while a decreased focal length between 1 and 0 exaggerates the perspective and
9+
gives the image more apparent depth.
1010

1111
The focal length can be calculated from a desired FOV via the equation:
1212

1313
.. mathmpl::
1414

15-
focal\_length = 1/tan(FOV/2)
15+
focal\_length = 1/\tan(FOV/2)
1616

1717
.. plot::
1818
:include-source: true
1919

2020
from mpl_toolkits.mplot3d import axes3d
2121
import matplotlib.pyplot as plt
22-
fig, axs = plt.subplots(1, 3, subplot_kw={'projection': '3d'})
22+
fig, axs = plt.subplots(1, 3, subplot_kw={'projection': '3d'},
23+
constrained_layout=True)
2324
X, Y, Z = axes3d.get_test_data(0.05)
2425
focal_lengths = [0.25, 1, 4]
2526
for ax, fl in zip(axs, focal_lengths):

examples/mplot3d/projections.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
========================
55
66
Demonstrates the different camera projections for 3D plots, and the effects of
7-
changing the focal length for a perspective projection. Note that matplotlib
7+
changing the focal length for a perspective projection. Note that Matplotlib
88
corrects for the 'zoom' effect of changing the focal length.
99
10-
An increasing focal length between 1 and infinity "flattens" the image, while
11-
a decreasing focal length between 1 and 0 exaggerates the perspective and gives
12-
the image more apparent depth. The default focal length of 1 corresponds to a
13-
Field of View (FOV) of 90 deg. In the limiting case, a focal length of
10+
The default focal length of 1 corresponds to a Field of View (FOV) of 90 deg.
11+
An increased focal length between 1 and infinity "flattens" the image, while a
12+
decreased focal length between 1 and 0 exaggerates the perspective and gives
13+
the image more apparent depth. In the limiting case, a focal length of
1414
infinity corresponds to an orthographic projection after correction of the
1515
zoom effect.
1616

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,12 +1013,11 @@ def set_proj_type(self, proj_type, focal_length=None):
10131013
_api.check_in_list(['persp', 'ortho'], proj_type=proj_type)
10141014
if proj_type == 'persp':
10151015
if focal_length is None:
1016-
self._focal_length = 1
1017-
else:
1018-
if focal_length <= 0:
1019-
raise ValueError(f"focal_length = {focal_length} must be"
1020-
" greater than 0")
1021-
self._focal_length = focal_length
1016+
focal_length = 1
1017+
elif focal_length <= 0:
1018+
raise ValueError(f"focal_length = {focal_length} must be "
1019+
"greater than 0")
1020+
self._focal_length = focal_length
10221021
elif proj_type == 'ortho':
10231022
if focal_length not in (None, np.inf):
10241023
raise ValueError(f"focal_length = {focal_length} must be "

0 commit comments

Comments
 (0)