GenericMappingTools / pygmt

A Python interface for the Generic Mapping Tools.
https://www.pygmt.org
BSD 3-Clause "New" or "Revised" License
747 stars 216 forks source link

Support 2D list as input #1021

Closed seisman closed 3 years ago

seisman commented 3 years ago

Description of the problem

PyGMT doesn't allow 2D list as input.

Full code that generated the error

The script below doesn't work:

import pygmt
fig = pygmt.Figure()

fig.plot(data=[[0, 0]], region=[-2, 2, -2, 2], frame=True, style="c0.5c", pen="1p")
fig.show()

but it works if I convert it to a 2D numpy array:

import pygmt
fig = pygmt.Figure()

fig.plot(data=np.array([[0, 0]]), region=[-2, 2, -2, 2], frame=True, style="c0.5c", pen="1p")
fig.show()

Full error message

---------------------------------------------------------------------------
GMTInvalidInput                           Traceback (most recent call last)
<ipython-input-15-cf008b39b139> in <module>
      2 fig = pygmt.Figure()
      3 
----> 4 fig.plot([[0, 0]], region=[-2, 2, -2, 2], frame=True, style="c0.5c", pen="1p")
      5 fig.show()

~/Gits/gmt/pygmt/pygmt/helpers/decorators.py in new_module(*args, **kwargs)
    286                 if alias in kwargs:
    287                     kwargs[arg] = kwargs.pop(alias)
--> 288             return module_func(*args, **kwargs)
    289 
    290         new_module.aliases = aliases

~/Gits/gmt/pygmt/pygmt/helpers/decorators.py in new_module(*args, **kwargs)
    430                         kwargs[arg] = separators[fmt].join(f"{item}" for item in value)
    431             # Execute the original function and return its output
--> 432             return module_func(*args, **kwargs)
    433 
    434         return new_module

~/Gits/gmt/pygmt/pygmt/src/plot.py in plot(self, x, y, data, sizes, direction, **kwargs)
    202     kwargs = self._preprocess(**kwargs)  # pylint: disable=protected-access
    203 
--> 204     kind = data_kind(data, x, y)
    205 
    206     extra_arrays = []

~/Gits/gmt/pygmt/pygmt/helpers/utils.py in data_kind(data, x, y, z)
     62         raise GMTInvalidInput("Too much data. Use either data or x and y.")
     63     if data is None and (x is None or y is None):
---> 64         raise GMTInvalidInput("Must provided both x and y.")
     65 
     66     if isinstance(data, str):

GMTInvalidInput: Must provided both x and y.
seisman commented 3 years ago

The bug will be fixed by #990.