Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f8c5550

Browse files
Code review changes
1 parent 81f3a23 commit f8c5550

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

doc/users/next_whats_new/3d_plot_focal_length.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ Give the 3D camera a custom focal length
33

44
Users can now better mimic real-world cameras by specifying the focal length of
55
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
6+
infinity "flattens" the image, while a decreasing focal length between 1 and 0
77
exaggerates the perspective and gives the image more apparent depth. The
88
default focal length of 1 corresponds to a Field of View (FOV) of 90 deg, and
99
is backwards-compatible with existing 3D plots.
1010

1111
The focal length can be calculated from a desired FOV via the equation:
12-
| ``focal_length = 1/tan(FOV/2)``
12+
13+
.. mathmpl::
14+
15+
focal_length = 1/tan(FOV/2)
1316

1417
.. plot::
1518
:include-source: true

examples/mplot3d/projections.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
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
10+
An increasing focal length between 1 and infinity "flattens" the image, while
1111
a decreasing focal length between 1 and 0 exaggerates the perspective and gives
1212
the image more apparent depth. The default focal length of 1 corresponds to a
1313
Field of View (FOV) of 90 deg. In the limiting case, a focal length of
14-
+infinity corresponds to an orthographic projection after correction of the
14+
infinity corresponds to an orthographic projection after correction of the
1515
zoom effect.
1616
1717
You can calculate focal length from a FOV via the equation:
18-
focal_length = 1/tan(FOV/2)
18+
:mathmpl:`1/tan(FOV/2)`
19+
20+
Or vice versa: :mathmpl:`FOV = 2*atan(1/focal_length)`
1921
20-
Or vice versa:
21-
FOV = 2*atan(1/focal_length)
2222
"""
2323

2424
from mpl_toolkits.mplot3d import axes3d
@@ -36,7 +36,7 @@
3636

3737
# Set the orthographic projection.
3838
axs[0].set_proj_type('ortho') # FOV = 0 deg
39-
axs[0].set_title("'ortho'\nfocal_length = +∞", fontsize=10)
39+
axs[0].set_title("'ortho'\nfocal_length = ∞", fontsize=10)
4040

4141
# Set the perspective projections
4242
axs[1].set_proj_type('persp') # FOV = 90 deg

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,22 +1046,20 @@ def set_proj_type(self, proj_type, focal_length=None):
10461046
The focal length can be computed from a desired Field Of View via
10471047
the equation: focal_length = 1/tan(FOV/2)
10481048
"""
1049+
_api.check_in_list(['persp', 'ortho'], proj_type=proj_type)
10491050
if proj_type == 'persp':
10501051
if focal_length is None:
10511052
self.focal_length = 1
10521053
else:
10531054
if focal_length <= 0:
1054-
raise ValueError(f"focal_length = {focal_length} must be" +
1055+
raise ValueError(f"focal_length = {focal_length} must be"
10551056
" greater than 0")
10561057
self.focal_length = focal_length
10571058
elif proj_type == 'ortho':
10581059
if focal_length not in (None, np.inf):
1059-
raise ValueError(f"focal_length = {focal_length} must be" +
1060+
raise ValueError(f"focal_length = {focal_length} must be"
10601061
f"None for proj_type = {proj_type}")
10611062
self.focal_length = np.inf
1062-
else:
1063-
raise ValueError(f"proj_type = {proj_type} must be in" +
1064-
f"{'persp', 'ortho'}")
10651063

10661064
def _roll_to_vertical(self, arr):
10671065
"""Roll arrays to match the different vertical axis."""

0 commit comments

Comments
 (0)