Skip to content

The color parameter of plot and plot3d methods can be 1d array #1075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
core-man opened this issue Mar 18, 2021 · 7 comments · Fixed by #1260
Closed

The color parameter of plot and plot3d methods can be 1d array #1075

core-man opened this issue Mar 18, 2021 · 7 comments · Fixed by #1260
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers scipy-sprint Things to work on during the SciPy sprint!
Milestone

Comments

@core-man
Copy link
Member

Description of the problem

We need to update the documentation for the color parameter in plot and plot3d because color can also be 1d array (originally posted in #1065 (comment)).


See the description of the color parameter of plot:

color (str) – Select color or pattern for filling of symbols or polygons. Default is no fill.

See the description of the color parameter of plot3d:

color (str) – Select color or pattern for filling of symbols or polygons. Default is no fill.


However, color can also be a 1d array just like the sizes parameter when we use x/y parameters for in the plot and plot3d methods. See the last example in Plotting data points. We can set color=data.depth_km and data.depth_km is a 1d array.

import pygmt
data = pygmt.datasets.load_japan_quakes()
region = [
    data.longitude.min() - 1,
    data.longitude.max() + 1,
    data.latitude.min() - 1,
    data.latitude.max() + 1,
]
print(region)
print(data.head())

fig = pygmt.Figure()
fig.basemap(region=region, projection="M15c", frame=True)
fig.coast(land="black", water="skyblue")
pygmt.makecpt(cmap="viridis", series=[data.depth_km.min(), data.depth_km.max()])
fig.plot(
    x=data.longitude,
    y=data.latitude,
    sizes=0.02 * 2 ** data.magnitude,
    color=data.depth_km,
    cmap=True,
    style="cc",
    pen="black",
)
fig.colorbar(frame='af+l"Depth (km)"')
fig.show()
@core-man core-man added the bug Something isn't working label Mar 18, 2021
@seisman
Copy link
Member

seisman commented Mar 18, 2021

If I understand it correctly, we only need to update the docstrings to mention that color can be a string or a 1darray?

@core-man
Copy link
Member Author

core-man commented Mar 18, 2021

If I understand it correctly, we only need to update the docstrings to mention that color can be a string or a 1darray?

I think so. May better to add an additional note (Only valid if using x/y) like the size parameter for the plot method.

sizes (1d array) – The sizes of the data points in units specified using style. Only valid if using x/y.

Because we raise GMTInvalidInput when color is used with the data parameter just like the sizes parameter.

pygmt/pygmt/src/plot.py

Lines 207 to 211 in 1a2289a

if "G" in kwargs and not isinstance(kwargs["G"], str):
if kind != "vectors":
raise GMTInvalidInput(
"Can't use arrays for color if data is matrix or file."
)

pygmt/pygmt/src/plot.py

Lines 214 to 218 in 1a2289a

if sizes is not None:
if kind != "vectors":
raise GMTInvalidInput(
"Can't use arrays for sizes if data is matrix or file."
)

@seisman
Copy link
Member

seisman commented Mar 18, 2021

Sounds good. Maybe also need to mention that cmap is required if color is a 1darray (I don't check if it's true).

@core-man
Copy link
Member Author

core-man commented Mar 18, 2021

Sounds good. Maybe also need to mention that cmap is required if color is a 1darray (I don't check if it's true).

I think so. See GMT plot:

where the optional z is required when -C is used


@seisman
I use the above Plot data points code but remove cmap=True. Cannot plot the symbols. So you are right.

camp

@seisman seisman added documentation Improvements or additions to documentation good first issue Good for newcomers labels Mar 19, 2021
@seisman seisman added this to the 0.4.0 milestone Mar 19, 2021
@seisman seisman removed the bug Something isn't working label Mar 25, 2021
@weiji14 weiji14 added the scipy-sprint Things to work on during the SciPy sprint! label May 2, 2021
@seisman
Copy link
Member

seisman commented May 4, 2021

@core-man This issue looks easy to fix. Do you want to work on it?

@core-man
Copy link
Member Author

core-man commented May 4, 2021

@core-man This issue looks easy to fix. Do you want to work on it?

So we don't want to leave it to new contributors?

@seisman
Copy link
Member

seisman commented May 4, 2021

So we don't want to leave it to new contributors?

The description of the issue is so long that people may be lost about what they should do.

You may either submit a quick fix or give more details about the expected changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers scipy-sprint Things to work on during the SciPy sprint!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants