@@ -71,7 +71,7 @@ def scatter_3D(a, cmap="jet", sca_args=None, control="color", size=60):
7171 sm = matplotlib .cm .ScalarMappable (cmap = cmap , norm = norm )
7272 sm .set_array ([])
7373 # different option
74- cm = matplotlib .cm .get_cmap (cmap )
74+ cm = matplotlib .colormaps .get_cmap (cmap )
7575 colors = cm (norm (a )).reshape (a .shape [0 ] * a .shape [1 ] * a .shape [2 ], 4 ) #
7676 # plotting
7777 nan_filter = ~ np .isnan (a .flatten ())
@@ -83,7 +83,7 @@ def scatter_3D(a, cmap="jet", sca_args=None, control="color", size=60):
8383 s = size ,
8484 ** scatter_args
8585 )
86- plt .colorbar (sm )
86+ fig .colorbar (sm , ax = ax )
8787
8888 if control == "alpha" :
8989 # untested #
@@ -92,8 +92,12 @@ def scatter_3D(a, cmap="jet", sca_args=None, control="color", size=60):
9292 plt .show ()
9393
9494 if control == "size" :
95- sizes = (a - a .min ()) * size / a .ptp ()
96- ax .scatter (x , y , z , a , s = sizes , ** scatter_args )
95+ value_range = np .ptp (a )
96+ if value_range == 0 :
97+ sizes = np .full (a .shape , size , dtype = float )
98+ else :
99+ sizes = (a - a .min ()) * size / value_range
100+ ax .scatter (x , y , z , c = a .flatten (), s = sizes .flatten (), ** scatter_args )
97101 ax_scale = plt .axes ([0.88 , 0.1 , 0.05 , 0.7 ])
98102 # ax_scale.set_ylim((0.1,1.2))
99103 nm = 5
@@ -172,12 +176,13 @@ def plot_3D_alpha(data):
172176 z [:, :, 1 ::2 ] += 0.95
173177
174178 fig = plt .figure ()
175- ax = fig .gca (projection = "3d" )
179+ ax = fig .add_subplot (projection = "3d" )
176180 ax .voxels (x , y , z , fill , facecolors = col_exp , edgecolors = col_exp )
177181 ax .set_xlabel ("x" )
178182 ax .set_ylabel ("y" )
179183 ax .set_zlabel ("z" )
180184 plt .show ()
185+ return fig
181186
182187
183188def quiver_3D (
@@ -332,11 +337,11 @@ def quiver_3D(
332337
333338 # plotting
334339 fig = plt .figure ()
335- ax = fig .gca (projection = "3d" , rasterized = True )
340+ ax = fig .add_subplot (projection = "3d" , rasterized = True )
336341 ax .quiver (
337342 xf , yf , zf , vf * scale , uf * scale , wf * scale , colors = colors , ** quiver_args
338343 )
339- plt .colorbar (sm )
344+ fig .colorbar (sm , ax = ax )
340345
341346 ax .set_xlim (ax_dims [0 ])
342347 ax .set_ylim (ax_dims [1 ])
@@ -348,8 +353,9 @@ def quiver_3D(
348353 ax .set_xlabel ("x" )
349354 ax .set_ylabel ("y" )
350355 ax .set_zlabel ("z" )
351- ax .w_xaxis .set_pane_color ((0.2 , 0.2 , 0.2 , 1.0 ))
352- ax .w_yaxis .set_pane_color ((0.2 , 0.2 , 0.2 , 1.0 ))
353- ax .w_zaxis .set_pane_color ((0.2 , 0.2 , 0.2 , 1.0 ))
356+ for axis in (ax .xaxis , ax .yaxis , ax .zaxis ):
357+ pane = getattr (axis , "pane" , None )
358+ if pane is not None :
359+ pane .set_facecolor ((0.2 , 0.2 , 0.2 , 1.0 ))
354360
355361 return fig
0 commit comments