Skip to content

Better support for plotting text in 3D at different heights #1393

@weiji14

Description

@weiji14

Description of the desired feature

For 3D plots, it should be possible to plot text at different heights based on a 'z' column, see https://docs.generic-mapping-tools.org/6.2/text.html#z. The current implementation of text in PyGMT (see https://www.pygmt.org/v0.4.0/api/generated/pygmt.Figure.text.html) does support this, but users have to provide the xyz input into the textfiles parameter, and it is also not very discoverable for new users.

It would be nice to have a z parameter (in addition to x and y) to be clear that text does support multi-height plotting. Here's a checklist for anyone wanting to work on this 'enhancement'.

TODO:

  1. Alias the -Z, call it zvalue (as in plot3d)?
  2. Add the z parameter here:

    pygmt/pygmt/src/text.py

    Lines 48 to 49 in 945bbc5

    x=None,
    y=None,
  3. Modify the code here to mention that x/y/z triples are also possible (need to wait for Refactor text to use virtualfile_from_data #1121 though edit: done!):

    pygmt/pygmt/src/text.py

    Lines 160 to 170 in 945bbc5

    if position is None:
    kind = data_kind(textfiles, x, y, text)
    else:
    if x is not None or y is not None:
    raise GMTInvalidInput(
    "Provide either position only, or x/y pairs, not both"
    )
    kind = "vectors"
    if kind == "vectors" and text is None:
    raise GMTInvalidInput("Must provide text with x/y pairs or position")
  4. Update the text API docstring to document the new behaviour.
  5. (Optional) Update the tutorial at https://www.pygmt.org/v0.4.0/tutorials/text.html to mention that z-value inputs are supported too.

Are you willing to help implement and maintain this feature? Please wait for #1121 before starting work on this (Edit: that PR is merged, so ready to start)!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions