Skip to content

Let PyGMT accept a 1d array when 2d array is needed #1132

@seisman

Description

@seisman

The issue was first found in #1070 (comment).

Below is a simple example plotting a circular vector. The data parameter expects a 2D array/list. Each row is a record, and the 5 columns are [x_start, y_start, radius, degree_start, degree_stop].

The following script works as expected because the variable data is a 2D array/list:

import numpy as np
import pygmt

fig = pygmt.Figure()
fig.plot(
    region=[-10, 10, -10, 10],
    projection="X10c",
    frame="ag",
    data=[[0, 0, 2.5, 90, 270], [0, 0, 1.5, 90, 270]],
    style="m0.5c+ea",
    pen="2p",
    color="red3",
)
fig.show()

When users want to plot a single circular vector, they still have to pass a 2D list, so the code looks like:

data=[[0, 0, 2.5, 90, 270]]

However, most people may first try a 1D array and then realize it doesn't work as expected.

data=[0, 0, 2.5, 90, 270]

As I understand it, data always expects a 2D array/list. When a 1D array is given, can we convert it to a 2D array? Are there any negative effects?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions