Error attempting to plot ellipses

Hi All,

I’m encountering an error when trying to plot ellipses using pygmt in a notebook, and I’m not sure what to make of it.

I tried the following from the tutorial on multi-parameter symbols:

In:
# ELLIPSE
data = [[0.5, 1, 45, 3, 1]]
fig.plot(data=data, style="e", color="orange", pen="2p,black")

AttributeError                            Traceback (most recent call last)
<ipython-input-24-82859c6b5f8c> in <module>
      1 # ELLIPSE
      2 data = [[0.5, 1, 45, 3, 1]]
----> 3 fig.plot(data=data, style="e", color="orange", pen="2p,black")

~\Anaconda3\envs\pygmt\lib\site-packages\pygmt\helpers\decorators.py in new_module(*args, **kwargs)
    268                 if alias in kwargs:
    269                     kwargs[arg] = kwargs.pop(alias)
--> 270             return module_func(*args, **kwargs)
    271 
    272         new_module.aliases = aliases

~\Anaconda3\envs\pygmt\lib\site-packages\pygmt\helpers\decorators.py in new_module(*args, **kwargs)
    409                         kwargs[arg] = separators[fmt].join(f"{item}" for item in value)
    410             # Execute the original function and return its output
--> 411             return module_func(*args, **kwargs)
    412 
    413         return new_module

~\Anaconda3\envs\pygmt\lib\site-packages\pygmt\base_plotting.py in plot(self, x, y, data, sizes, direction, **kwargs)
    817                 )
    818 
--> 819             with file_context as fname:
    820                 arg_str = " ".join([fname, build_arg_string(kwargs)])
    821                 lib.call_module("plot", arg_str)

~\Anaconda3\envs\pygmt\lib\contextlib.py in __enter__(self)
    111         del self.args, self.kwds, self.func
    112         try:
--> 113             return next(self.gen)
    114         except StopIteration:
    115             raise RuntimeError("generator didn't yield") from None

~\Anaconda3\envs\pygmt\lib\site-packages\pygmt\clib\session.py in virtualfile_from_matrix(self, matrix)
   1268         # guarantees that the copy will be around until the virtual file is
   1269         # closed.
-> 1270         matrix = as_c_contiguous(matrix)
   1271         rows, columns = matrix.shape
   1272 

~\Anaconda3\envs\pygmt\lib\site-packages\pygmt\clib\conversion.py in as_c_contiguous(array)
    204 
    205     """
--> 206     if not array.flags.c_contiguous:
    207         return array.copy(order="C")
    208     return array

AttributeError: 'list' object has no attribute 'flags'

I’m on windows 10 using a pygmt environment and I’m still a bit of a noob. Please help!

Cheers,
Tom

It should work if you format the data as a numpy 2d array rather than a list. Here is an example:

import pygmt
import numpy as np
data = np.array([[0.5, 1, 45, 3, 1]])
fig = pygmt.Figure()
fig.plot(data=data, frame=True, region=[0,1,0.5,1.5], projection="X5c", style="e", color="orange", pen="2p,black")
fig.show()
AttributeError: 'list' object has no attribute 'flags'

I think the error you’re having has been fixed in https://github.com/GenericMappingTools/pygmt/pull/990, and your original script should work as expected if you’re using PyGMT v0.3.1.

Thank you both! Updating and converting data to numpy arrays worked a treat. Cheers!