@@ -2979,7 +2979,9 @@ def _plot_point_scalars(
29792979 Increases or decreases displacement by a factor.
29802980
29812981 add_text : bool, optional
2982- Adds information about the result when rnum is given.
2982+ Adds information about the result when rnum is given. Control the
2983+ font size with the ``font_size`` parameter and text color with
2984+ ``text_color``.
29832985
29842986 overlay_wireframe : bool, optional
29852987 Overlay a wireframe of the original undeformed mesh.
@@ -3090,7 +3092,7 @@ def _plot_point_scalars(
30903092 # remove extra keyword args
30913093 kwargs .pop ("node_components" , None )
30923094 kwargs .pop ("sel_type_all" , None )
3093-
3095+ font_size = kwargs . pop ( "font_size" , 16 )
30943096 if overlay_wireframe :
30953097 plotter .add_mesh (self .grid , style = "wireframe" , color = "w" , opacity = 0.5 )
30963098
@@ -3117,10 +3119,11 @@ def _plot_point_scalars(
31173119 else :
31183120 plotter .open_movie (movie_filename )
31193121
3120- # add table
31213122 if add_text and rnum is not None :
31223123 result_text = self .text_result_table (rnum )
3123- plotter .add_text (result_text , font_size = 20 , color = text_color )
3124+ if not animate :
3125+ # avoid adding twice
3126+ plotter .add_text (result_text , font_size = font_size , color = text_color )
31243127
31253128 # camera position added in 0.32.0
31263129 show_kwargs = {}
@@ -3164,6 +3167,13 @@ def exit_callback(plotter, RenderWindowInteractor, event):
31643167 lambda render , event : exit_callback (plotter , render , event ),
31653168 )
31663169
3170+ # setup text
3171+ if add_text :
3172+ # results in a corner annotation actor
3173+ text_actor = plotter .add_text (
3174+ " " , font_size = font_size , color = text_color
3175+ )
3176+
31673177 first_loop = True
31683178 cached_normals = [None for _ in range (n_frames )]
31693179 while self ._animating :
@@ -3184,8 +3194,10 @@ def exit_callback(plotter, RenderWindowInteractor, event):
31843194 copied_mesh .point_data ["Normals" ][:] = cached_normals [j ]
31853195
31863196 if add_text :
3187- phase = angle * 180 / np .pi
3188- plotter .add_text (f"{ result_text } \n Phase { phase } Degrees" )
3197+ text_actor .set_text (
3198+ 2 , # place in the upper left
3199+ f"{ result_text } \n Phase: { np .rad2deg (angle ):.1f} Degrees" ,
3200+ )
31893201
31903202 # at max supported framerate
31913203 plotter .update (1 , force_redraw = True )
@@ -3311,6 +3323,7 @@ def _animate_point_scalars(
33113323 # screenshot = kwargs.pop('screenshot', None)
33123324 # interactive = kwargs.pop('interactive', True)
33133325 text_color = kwargs .pop ("text_color" , None )
3326+ font_size = kwargs .pop ("font_size" , 16 )
33143327
33153328 kwargs .setdefault ("smooth_shading" , True )
33163329 kwargs .setdefault ("color" , "w" )
@@ -3360,7 +3373,9 @@ def _animate_point_scalars(
33603373 if text is not None :
33613374 if len (text ) != len (scalars ):
33623375 raise ValueError ("Length of ``text`` must be the same as ``scalars``" )
3363- plotter .add_text (text [0 ], font_size = 20 , color = text_color )
3376+ text_actor = plotter .add_text (
3377+ text [0 ], font_size = font_size , color = text_color
3378+ )
33643379
33653380 # orig_pts = copied_mesh.points.copy()
33663381 plotter .show (
@@ -3391,7 +3406,7 @@ def q_callback():
33913406 copied_mesh .active_scalars [:] = data
33923407
33933408 if text is not None :
3394- plotter . add_text ( text [i ])
3409+ text_actor . set_text ( 2 , text [i ]) # place in the upper left
33953410
33963411 # at max supported framerate
33973412 plotter .update (1 , force_redraw = True )
0 commit comments