0

So, I am trying to plot my data with the same code shown in this post, including its latest update. But when I run the code to see the projection grid I get this error:

Traceback (most recent call last):

File "C:\Users\Stefano\Documents\Python files\schmidt_projection.py", line 474, in <module>
    plt.subplot(111, projection="SchmidtProjection")

  File "C:\Users\Stefano\anaconda3\lib\site-packages\matplotlib\pyplot.py", line 1126, in subplot
    ax = fig.add_subplot(*args, **kwargs)

  File "C:\Users\Stefano\anaconda3\lib\site-packages\matplotlib\figure.py", line 1402, in add_subplot
    ax = subplot_class_factory(projection_class)(self, *args, **kwargs)

  File "C:\Users\Stefano\anaconda3\lib\site-packages\matplotlib\axes\_subplots.py", line 42, in __init__
    self._axes_class.__init__(self, fig, self.figbox, **kwargs)

  File "C:\Users\Stefano\Documents\Python files\schmidt_projection.py", line 26, in __init__
    Axes.__init__(self, *args, **kwargs)

  File "C:\Users\Stefano\anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 511, in __init__
    self.cla()

  File "C:\Users\Stefano\Documents\Python files\schmidt_projection.py", line 43, in cla
    self.set_longitude_grid(10)

  File "C:\Users\Stefano\Documents\Python files\schmidt_projection.py", line 309, in set_longitude_grid
    np.linspace(-np.pi, np.pi, number, True)[1:-1]))

  File "<__array_function__ internals>", line 6, in linspace

  File "C:\Users\Stefano\anaconda3\lib\site-packages\numpy\core\function_base.py", line 113, in linspace
    num = operator.index(num)

TypeError: 'float' object cannot be interpreted as an integer

Does anybody know why and what can I do to fix this? I am relatively new in this, I am trying to learn as much as I can, but I can't figure out why this error occurs. I will really much appreciate any help. Thanks

p.s. I know that many years are passed since the post has been updated, but I still wanted to try if I could get help on this.

1 Answers1

0

I didn't go through the code but my guess is that you're trying to use the num variable as an index. Indices (array or other) are typically integers. Your num might be interpreted as a float, so maybe you should cast it as an integer as int(num), when using it as an index.

Botond
  • 2,640
  • 6
  • 28
  • 44