3
3
import warnings
4
4
import numpy as np
5
5
import scipy as sp
6
- from scipy .stats .distributions import chi2
7
6
8
7
from spatialmath import base
9
8
9
+ # Only import chi2 from scipy.stats.distributions when used
10
+ _chi2 = None
11
+
12
+
10
13
try :
11
14
import matplotlib .pyplot as plt
12
15
from matplotlib .patches import Circle
15
18
Line3DCollection ,
16
19
pathpatch_2d_to_3d ,
17
20
)
21
+
18
22
_matplotlib_exists = True
19
23
except ImportError : # pragma: no cover
20
24
_matplotlib_exists = False
@@ -74,7 +78,9 @@ def plot_text(pos, text=None, ax=None, color=None, **kwargs):
74
78
return [handle ]
75
79
76
80
77
- def plot_point (pos , marker = "bs" , label = None , text = None , ax = None , textargs = None , ** kwargs ):
81
+ def plot_point (
82
+ pos , marker = "bs" , label = None , text = None , ax = None , textargs = None , ** kwargs
83
+ ):
78
84
"""
79
85
Plot a point using matplotlib
80
86
@@ -130,7 +136,7 @@ def plot_point(pos, marker="bs", label=None, text=None, ax=None, textargs=None,
130
136
"""
131
137
132
138
if text is not None :
133
- raise DeprecationWarning (' use label not text' )
139
+ raise DeprecationWarning (" use label not text" )
134
140
135
141
if isinstance (pos , np .ndarray ):
136
142
if pos .ndim == 1 :
@@ -399,7 +405,8 @@ def plot_box(
399
405
400
406
return [r ]
401
407
402
- def plot_poly (vertices , * fmt , close = False ,** kwargs ):
408
+
409
+ def plot_poly (vertices , * fmt , close = False , ** kwargs ):
403
410
404
411
if close :
405
412
vertices = np .hstack ((vertices , vertices [:, [0 ]]))
@@ -523,6 +530,10 @@ def ellipse(E, centre=(0, 0), scale=1, confidence=None, resolution=40, inverted=
523
530
raise ValueError ("ellipse is defined by a 2x2 matrix" )
524
531
525
532
if confidence :
533
+ # Import chi2 if first time used
534
+ if _chi2 is None :
535
+ from scipy .stats .distributions import chi2
536
+
526
537
# process the probability
527
538
s = math .sqrt (chi2 .ppf (confidence , df = 2 )) * scale
528
539
else :
@@ -601,6 +612,7 @@ def plot_ellipse(
601
612
602
613
# =========================== 3D shapes =================================== #
603
614
615
+
604
616
def sphere (radius = 1 , centre = (0 , 0 , 0 ), resolution = 50 ):
605
617
"""
606
618
Points on a sphere
@@ -850,6 +862,7 @@ def plot_cylinder(
850
862
851
863
return handles
852
864
865
+
853
866
def plot_cone (
854
867
radius ,
855
868
height ,
@@ -895,7 +908,7 @@ def plot_cone(
895
908
:seealso: :func:`~matplotlib.pyplot.plot_surface`, :func:`~matplotlib.pyplot.plot_wireframe`
896
909
"""
897
910
ax = axes_logic (ax , 3 )
898
-
911
+
899
912
# https://stackoverflow.com/questions/26874791/disconnected-surfaces-when-plotting-cones
900
913
# Set up the grid in polar coords
901
914
theta = np .linspace (0 , 2 * np .pi , resolution )
@@ -905,7 +918,7 @@ def plot_cone(
905
918
# Then calculate X, Y, and Z
906
919
X = R * np .cos (T ) + centre [0 ]
907
920
Y = R * np .sin (T ) + centre [1 ]
908
- Z = np .sqrt (X ** 2 + Y ** 2 ) / radius * height + centre [2 ]
921
+ Z = np .sqrt (X ** 2 + Y ** 2 ) / radius * height + centre [2 ]
909
922
if flip :
910
923
Z = height - Z
911
924
@@ -924,6 +937,7 @@ def plot_cone(
924
937
925
938
return handles
926
939
940
+
927
941
def plot_cuboid (
928
942
sides = [1 , 1 , 1 ], centre = (0 , 0 , 0 ), pose = None , ax = None , filled = False , ** kwargs
929
943
):
@@ -1040,13 +1054,16 @@ def _axes_dimensions(ax):
1040
1054
elif classname in ("AxesSubplot" , "Animate2" ):
1041
1055
return 2
1042
1056
1057
+
1043
1058
def axes_get_limits (ax ):
1044
1059
return np .r_ [ax .get_xlim (), ax .get_ylim ()]
1045
1060
1061
+
1046
1062
def axes_get_scale (ax ):
1047
1063
limits = axes_get_limits (ax )
1048
1064
return max (abs (limits [1 ] - limits [0 ]), abs (limits [3 ] - limits [2 ]))
1049
1065
1066
+
1050
1067
def axes_logic (ax , dimensions , projection = "ortho" , autoscale = True ):
1051
1068
"""
1052
1069
Axis creation logic
@@ -1093,7 +1110,7 @@ def axes_logic(ax, dimensions, projection="ortho", autoscale=True):
1093
1110
# axis was given
1094
1111
1095
1112
if _axes_dimensions (ax ) == dimensions :
1096
- #print("use existing axes")
1113
+ # print("use existing axes")
1097
1114
return ax
1098
1115
# mismatch in dimensions, create new axes
1099
1116
# print('create new axes')
@@ -1128,9 +1145,9 @@ def plotvol2(dim, ax=None, equal=True, grid=False, labels=True):
1128
1145
================== ====== ======
1129
1146
input xrange yrange
1130
1147
================== ====== ======
1131
- A (scalar) -A:A -A:A
1132
- [A, B] A:B A:B
1133
- [A, B, C, D, E, F] A:B C:D
1148
+ A (scalar) -A:A -A:A
1149
+ [A, B] A:B A:B
1150
+ [A, B, C, D, E, F] A:B C:D
1134
1151
================== ====== ======
1135
1152
1136
1153
:seealso: :func:`plotvol3`, :func:`expand_dims`
@@ -1153,7 +1170,9 @@ def plotvol2(dim, ax=None, equal=True, grid=False, labels=True):
1153
1170
return ax
1154
1171
1155
1172
1156
- def plotvol3 (dim = None , ax = None , equal = True , grid = False , labels = True , projection = "ortho" ):
1173
+ def plotvol3 (
1174
+ dim = None , ax = None , equal = True , grid = False , labels = True , projection = "ortho"
1175
+ ):
1157
1176
"""
1158
1177
Create 3D plot volume
1159
1178
@@ -1287,4 +1306,3 @@ def isnotebook():
1287
1306
/ "test_graphics.py"
1288
1307
).read ()
1289
1308
) # pylint: disable=exec-used
1290
-
0 commit comments