Skip to content

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

Closed

Description

@core-man

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()

Activity

  1. added
    bug
    on Mar 18, 2021
  2. seisman commented on Mar 18, 2021

    @seisman
    Member

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

  3. core-man commented on Mar 18, 2021

    @core-man
    MemberAuthor

    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."
    )

  4. seisman commented on Mar 18, 2021

    @seisman
    Member

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

  5. core-man commented on Mar 18, 2021

    @core-man
    MemberAuthor

    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

  6. added
    documentation
    good first issue
    on Mar 19, 2021
  7. added this to the 0.4.0 milestone on Mar 19, 2021
  8. removed
    bug
    on Mar 25, 2021
  9. added
    scipy-sprint
    on May 2, 2021
  10. seisman commented on May 4, 2021

    @seisman
    Member

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

  11. core-man commented on May 4, 2021

    @core-man
    MemberAuthor

    @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?

  12. seisman commented on May 4, 2021

    @seisman
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationgood first issuescipy-sprint

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions