Davide-sd / sympy-plot-backends

An improved plotting module for SymPy
BSD 3-Clause "New" or "Revised" License
42 stars 9 forks source link

plot_real_imag fails #6

Closed Davide-sd closed 2 years ago

Davide-sd commented 2 years ago
from sympy import *
from spb import plot_real_imag
phi = symbols('phi', real = True)
vec = cos(phi) + cos(phi - 2*pi/3)*exp(I*2*pi/3) + cos(phi - 4*pi/3)*exp(I*4*pi/3)
plot_real_imag(vec, (phi, 0, 2*pi))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [4], in <module>
----> 1 plot_real_imag(vec, (phi, 0, 2*pi))

File ~/Documents/Development/envs/pygasflow_dev/lib/python3.9/site-packages/spb/ccomplex/complex.py:465, in plot_real_imag(*args, **kwargs)
    463 kwargs.setdefault("real", True)
    464 kwargs.setdefault("imag", True)
--> 465 return _plot_complex(*args, **kwargs)

File ~/Documents/Development/envs/pygasflow_dev/lib/python3.9/site-packages/spb/ccomplex/complex.py:219, in _plot_complex(show, *args, **kwargs)
    217 p = Backend(*series, **kwargs)
    218 if show:
--> 219     p.show()
    220 return p

File ~/Documents/Development/envs/pygasflow_dev/lib/python3.9/site-packages/spb/backends/matplotlib.py:942, in MatplotlibBackend.show(self)
    940 def show(self):
    941     """Display the current plot."""
--> 942     self.process_series()
    943     if _show:
    944         self._fig.tight_layout()

File ~/Documents/Development/envs/pygasflow_dev/lib/python3.9/site-packages/spb/backends/matplotlib.py:938, in MatplotlibBackend.process_series(self)
    934 # create the figure from scratch every time, otherwise if the plot was
    935 # previously shown, it would not be possible to show it again. This
    936 # behaviour is specific to Matplotlib
    937 self._create_figure()
--> 938 self._process_series(self.series)

File ~/Documents/Development/envs/pygasflow_dev/lib/python3.9/site-packages/spb/backends/matplotlib.py:349, in MatplotlibBackend._process_series(self, series)
    347     x, y, param = s.get_data()
    348 else:
--> 349     x, y = s.get_data()
    350 lkw = dict(label=s.label, color=next(self._cl))
    351 if s.is_point:

File ~/Documents/Development/envs/pygasflow_dev/lib/python3.9/site-packages/spb/series.py:401, in Line2DBaseSeries.get_data(self)
    379 """Return coordinates for plotting the line.
    380 
    381 Returns
   (...)
    397     corresponding interactive series).
    398 """
    399 np = import_module('numpy')
--> 401 points = self.get_points()
    402 if self.steps is True:
    403     if self.is_2Dline:

File ~/Documents/Development/envs/pygasflow_dev/lib/python3.9/site-packages/spb/series.py:1703, in ComplexPointSeries.get_points(self)
   1691 def get_points(self):
   1692     """Return arrays of coordinates for plotting.
   1693 
   1694     Returns
   (...)
   1701         the imaginary part.
   1702     """
-> 1703     return self._evaluate(self.expr)

File ~/Documents/Development/envs/pygasflow_dev/lib/python3.9/site-packages/spb/series.py:1688, in ComplexPointSeries._evaluate(points)
   1685 @staticmethod
   1686 def _evaluate(points):
   1687     np = import_module('numpy')
-> 1688     points = np.array([complex(p) for p in points])
   1689     return np.real(points), np.imag(points)

File ~/Documents/Development/envs/pygasflow_dev/lib/python3.9/site-packages/spb/series.py:1688, in <listcomp>(.0)
   1685 @staticmethod
   1686 def _evaluate(points):
   1687     np = import_module('numpy')
-> 1688     points = np.array([complex(p) for p in points])
   1689     return np.real(points), np.imag(points)

File ~/Documents/Development/envs/pygasflow_dev/lib/python3.9/site-packages/sympy/core/expr.py:364, in Expr.__complex__(self)
    362 result = self.evalf()
    363 re, im = result.as_real_imag()
--> 364 return complex(float(re), float(im))

File ~/Documents/Development/envs/pygasflow_dev/lib/python3.9/site-packages/sympy/core/expr.py:359, in Expr.__float__(self)
    357 if result.is_number and result.as_real_imag()[1]:
    358     raise TypeError("can't convert complex to float")
--> 359 raise TypeError("can't convert expression to float")

TypeError: can't convert expression to float