vMeijin / pySmithPlot

Matplotlib extension for creating Smith charts with Python
127 stars 73 forks source link

TypeError when calling np.linespace in in smithies.py grid() #30

Open chrisgmorton opened 4 years ago

chrisgmorton commented 4 years ago

Using NumPy 1.18.4 and Matplotlib 3.2.1. Python version is 3.8.3. Mac OS X Catalina although I doubt this issue is platform dependent.

This looks like the derived value for num, using x_div+1, causes the error, likely because x_div is a float. NumPy is probably no longer doing an automatic type conversion. Anyhow, that's an assumption at this point.

~/fusion/prod/lib/python3.8/site-packages/smithplot/smithaxes.py in cla(self)
    475 
    476         for grid in ['major', "minor"]:
--> 477             self.grid(b=self._get_key("grid.%s.enable" % grid), which=grid)
    478 
    479     def _set_lim_and_transforms(self):

~/fusion/prod/lib/python3.8/site-packages/smithplot/smithaxes.py in grid(self, b, which, fancy, dividers, threshold, **kwargs)
   1062                             x_div, y_div = d_mat[i, k]
   1063 
-> 1064                             for xs in np.linspace(x0, x1, x_div + 1)[1:]:
   1065                                 x_lines.append([xs, y0, y1])
   1066                                 x_lines.append([xs, -y1, -y0])

<__array_function__ internals> in linspace(*args, **kwargs)

~/fusion/prod/lib/python3.8/site-packages/numpy-1.18.4-py3.8-macosx-10.15-x86_64.egg/numpy/core/function_base.py in linspace(start, stop, num, endpoint, retstep, dtype, axis)
    117         num = operator.index(num)
    118     except TypeError:
--> 119         raise TypeError(
    120             "object of type {} cannot be safely interpreted as an integer."
    121                 .format(type(num)))

TypeError: object of type <class 'numpy.float64'> cannot be safely interpreted as an integer.
chrisgmorton commented 4 years ago

I can confirm that x_div is of type numpy.float64. In my case the value is 5.0.

alexpacini commented 4 years ago

This is the bug fixed both with PR #27 and #28. If you want to use it, since it was not merged, you can install it from my github branch (where I applied #27 ).

python3 -m pip install --user --upgrade git+https://github.com/alexpacini/pySmithPlot#egg=pysmithplot