From cced8cc039f800aab196465401c764ea61485e29 Mon Sep 17 00:00:00 2001 From: Sam Lubelsky Date: Tue, 9 Apr 2024 16:36:22 -0500 Subject: [PATCH 1/3] Fixed text plotting with backend renderer For some reason, the bounds of the backend renderer became complex at some point. I just check if they are complex and then convert them to real if the complex part is equal to 0. --- sympy/plotting/textplot.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sympy/plotting/textplot.py b/sympy/plotting/textplot.py index 2ba83ad0fbfb..5f1f2b639d6c 100644 --- a/sympy/plotting/textplot.py +++ b/sympy/plotting/textplot.py @@ -50,6 +50,12 @@ def textplot_str(expr, a, b, W=55, H=21): .format(free)) x = free.pop() if free else Dummy() f = lambdify([x], expr) + if isinstance(a, complex): + if a.imag == 0: + a = a.real + if isinstance(b, complex): + if b.imag == 0: + b = b.real a = float(a) b = float(b) From cf57b4f3631eba99cc379a458076fa0e992dcc61 Mon Sep 17 00:00:00 2001 From: Sam Lubelsky Date: Tue, 9 Apr 2024 16:59:05 -0500 Subject: [PATCH 2/3] added regression tests --- sympy/plotting/tests/test_plot.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sympy/plotting/tests/test_plot.py b/sympy/plotting/tests/test_plot.py index dc6950de2224..b62ec113bfeb 100644 --- a/sympy/plotting/tests/test_plot.py +++ b/sympy/plotting/tests/test_plot.py @@ -60,6 +60,13 @@ def save(self): def close(self): pass +def test_basic_plotting_backend(): + x = Symbol('x') + try: + plot(x, (x, 0, 3), backend='text') + plot(x**2 + 1, (x, 0, 3), backend='text') + except TypeError as exc: + assert False, f"{exc}" @pytest.mark.parametrize("adaptive", [True, False]) def test_plot_and_save_1(adaptive): From 8757b8879934776241fe84138b38c1ad19b577b0 Mon Sep 17 00:00:00 2001 From: SamLubelsky Date: Sun, 14 Apr 2024 13:06:02 -0500 Subject: [PATCH 3/3] changed test to not catch errors Co-authored-by: S.Y. Lee --- sympy/plotting/tests/test_plot.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/sympy/plotting/tests/test_plot.py b/sympy/plotting/tests/test_plot.py index b62ec113bfeb..bf09e825e744 100644 --- a/sympy/plotting/tests/test_plot.py +++ b/sympy/plotting/tests/test_plot.py @@ -62,11 +62,8 @@ def close(self): def test_basic_plotting_backend(): x = Symbol('x') - try: - plot(x, (x, 0, 3), backend='text') - plot(x**2 + 1, (x, 0, 3), backend='text') - except TypeError as exc: - assert False, f"{exc}" + plot(x, (x, 0, 3), backend='text') + plot(x**2 + 1, (x, 0, 3), backend='text') @pytest.mark.parametrize("adaptive", [True, False]) def test_plot_and_save_1(adaptive):