GenericMappingTools / GenericMappingTools/pygmt

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

Open
#1,132 7 comments 0 reactions 0 assignees View on GitHub
bug question
Dominant language
Python
Stars
874
Forks
255
Avg merge
1d 21h
Merged PRs (30d)
40

Description

The issue was first found in https://github.com/GenericMappingTools/pygmt/pull/1070#discussion_r602617399.

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:
```python
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?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.