From d0a4d7cfc3288bf14520ca08f0e159908f7cd61c Mon Sep 17 00:00:00 2001 From: mehatamm Date: Thu, 19 Dec 2024 14:00:47 -0500 Subject: [PATCH 1/3] add draw_matplotlib toggle for showing a figure --- pyzx/drawing.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pyzx/drawing.py b/pyzx/drawing.py index d1d335f2..9e07a3c1 100644 --- a/pyzx/drawing.py +++ b/pyzx/drawing.py @@ -159,7 +159,8 @@ def draw_matplotlib( figsize:Tuple[FloatInt,FloatInt] =(8,2), h_edge_draw: Literal['blue', 'box'] ='blue', show_scalar: bool =False, - rows: Optional[Tuple[FloatInt,FloatInt]] =None + rows: Optional[Tuple[FloatInt,FloatInt]] =None, + show_fig =False, ) -> Any: # TODO: Returns a matplotlib figure # lazy import matplotlib @@ -270,9 +271,12 @@ def draw_matplotlib( ax.text(x-5,y,g.scalar.to_latex()) ax.axis('equal') - plt.close() + if show_fig: + plt.show() + else: + plt.close() return fig1 - #plt.show() + # Provides functions for displaying pyzx graphs in jupyter notebooks using d3 From 607ebd77680e6e09f965dee3548e576a2b83c4de Mon Sep 17 00:00:00 2001 From: mehatamm Date: Thu, 19 Dec 2024 14:10:23 -0500 Subject: [PATCH 2/3] modify draw_matplotlib to show plot when in shell --- pyzx/drawing.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyzx/drawing.py b/pyzx/drawing.py index 9e07a3c1..5ebc7901 100644 --- a/pyzx/drawing.py +++ b/pyzx/drawing.py @@ -160,7 +160,6 @@ def draw_matplotlib( h_edge_draw: Literal['blue', 'box'] ='blue', show_scalar: bool =False, rows: Optional[Tuple[FloatInt,FloatInt]] =None, - show_fig =False, ) -> Any: # TODO: Returns a matplotlib figure # lazy import matplotlib @@ -271,7 +270,7 @@ def draw_matplotlib( ax.text(x-5,y,g.scalar.to_latex()) ax.axis('equal') - if show_fig: + if get_mode() == "shell": plt.show() else: plt.close() From bc4333592e09a2ad28c44dfc33b3c7fb93df97af Mon Sep 17 00:00:00 2001 From: mehatamm Date: Thu, 19 Dec 2024 14:11:23 -0500 Subject: [PATCH 3/3] fix typo --- pyzx/drawing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyzx/drawing.py b/pyzx/drawing.py index 5ebc7901..34d8cf36 100644 --- a/pyzx/drawing.py +++ b/pyzx/drawing.py @@ -159,7 +159,7 @@ def draw_matplotlib( figsize:Tuple[FloatInt,FloatInt] =(8,2), h_edge_draw: Literal['blue', 'box'] ='blue', show_scalar: bool =False, - rows: Optional[Tuple[FloatInt,FloatInt]] =None, + rows: Optional[Tuple[FloatInt,FloatInt]] =None ) -> Any: # TODO: Returns a matplotlib figure # lazy import matplotlib