@@ -99,13 +99,14 @@ def is_notebook():
99
99
bool
100
100
"""
101
101
try :
102
+ from IPython import get_ipython
103
+
102
104
shell = get_ipython ().__class__ .__name__
103
- if shell == "ZMQInteractiveShell" :
104
- return True # Jupyter notebook or qtconsole
105
- else :
106
- return False
105
+ # Check if shell is Jupyter notebook or QTconsole
106
+ return shell == "ZMQInteractiveShell"
107
+ # Probably standard Python interpreter
107
108
except NameError :
108
- return False # Probably standard Python interpreter
109
+ return False
109
110
110
111
111
112
def is_float (istring ):
@@ -385,7 +386,7 @@ def plot_polar_chart(
385
386
386
387
@pyaedt_function_handler ()
387
388
@update_plot_settings
388
- def plot_3d_chart (plot_data , size = (2000 , 1000 ), xlabel = "" , ylabel = "" , title = "" , snapshot_path = None ):
389
+ def plot_3d_chart (plot_data , size = (2000 , 1000 ), xlabel = "" , ylabel = "" , title = "" , snapshot_path = None , show = True ):
389
390
"""Create a Matplotlib 3D plot based on a list of data.
390
391
391
392
Parameters
@@ -403,6 +404,9 @@ def plot_3d_chart(plot_data, size=(2000, 1000), xlabel="", ylabel="", title="",
403
404
Plot Title label.
404
405
snapshot_path : str
405
406
Full path to image file if a snapshot is needed.
407
+ show : bool, optional
408
+ Whether to render the figure. The default is ``True``. If ``False``, the
409
+ figure is not drawn.
406
410
407
411
Returns
408
412
-------
@@ -432,14 +436,16 @@ def plot_3d_chart(plot_data, size=(2000, 1000), xlabel="", ylabel="", title="",
432
436
fig .set_size_inches (size [0 ] / dpi , size [1 ] / dpi )
433
437
if snapshot_path :
434
438
fig .savefig (snapshot_path )
435
- else :
439
+ if show :
436
440
fig .show ()
437
441
return fig
438
442
439
443
440
444
@pyaedt_function_handler ()
441
445
@update_plot_settings
442
- def plot_2d_chart (plot_data , size = (2000 , 1000 ), show_legend = True , xlabel = "" , ylabel = "" , title = "" , snapshot_path = None ):
446
+ def plot_2d_chart (
447
+ plot_data , size = (2000 , 1000 ), show_legend = True , xlabel = "" , ylabel = "" , title = "" , snapshot_path = None , show = True
448
+ ):
443
449
"""Create a Matplotlib plot based on a list of data.
444
450
Parameters
445
451
----------
@@ -459,6 +465,9 @@ def plot_2d_chart(plot_data, size=(2000, 1000), show_legend=True, xlabel="", yla
459
465
snapshot_path : str, optional
460
466
Full path to image file if a snapshot is needed.
461
467
The default value is ``None``.
468
+ show : bool, optional
469
+ Whether to render the figure. The default is ``True``. If ``False``, the
470
+ figure is not drawn.
462
471
463
472
Returns
464
473
-------
@@ -489,7 +498,7 @@ def plot_2d_chart(plot_data, size=(2000, 1000), show_legend=True, xlabel="", yla
489
498
490
499
if snapshot_path :
491
500
fig .savefig (snapshot_path )
492
- elif not is_notebook () :
501
+ if show :
493
502
fig .show ()
494
503
return fig
495
504
@@ -540,9 +549,10 @@ def plot_matplotlib(
540
549
Default is `False`.
541
550
annotations : list, optional
542
551
List of annotations to add to the plot. The format is [x, y, string, dictionary of font options].
543
- Default is `None`.
552
+ The default is `` None` `.
544
553
show : bool, optional
545
- Whether to show the plot or return the matplotlib object. Default is `True`.
554
+ Whether to render the figure. The default is ``True``. If ``False``, the
555
+ figure is not drawn.
546
556
547
557
548
558
Returns
@@ -636,10 +646,10 @@ def plot_contour(
636
646
levels : int, optional
637
647
Color map levels. The default is ``64``.
638
648
snapshot_path : str, optional
639
- Full path to save the image save . The default is ``None``.
649
+ Full path to save the image to . The default is ``None``.
640
650
show : bool, optional
641
- Whether to render the figure. The default is ``True``. If
642
- ``False``, the image is not drawn.
651
+ Whether to render the figure. The default is ``True``. If ``False``, the
652
+ figure is not drawn.
643
653
644
654
Returns
645
655
-------
0 commit comments