Add the Perspective class for setting perspective view

Open
#4,176 4 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
30/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Active
Tech stack
python

Research direction

The issue names no files or tests; start by reviewing Figure plotting commands and the existing perspective parameter. Compare the proposed Perspective class and set_perspective approach with GMT’s -p syntax. Done requires an agreed API and implementation scope for setting, reusing, and disabling perspective settings.

Written by the indexing model from the issue text.

Description

feature request

GMT’s -p option enables perspective view by setting the azimuth and elevation of the viewpoint. The full documentation is available at:
https://docs.generic-mapping-tools.org/6.6/gmt.html#perspective-full

The GMT command-line syntax is rather complex:

-p[x|y|z]azim[/elev[/zlevel]][+wlon0/lat0[/z0]][+vx0/y0]

At present, we must pass the raw string directly to the perspective parameter in the first plotting command, and then specify perspective=True in subsequent commands. This approach feels un-Pythonic.

One possible improvement is to define an auxiliary class that can be passed to the perspective parameter, for example:

perspective = Perspective(azimuth, elevation, zlevel, ...)

However, a more Pythonic design might be to provide a method—similar to Matplotlib’s [view_init](https://matplotlib.org/stable/api/_as_gen/mpl_toolkits.mplot3d.axes3d.Axes3D.view_init.html)—that allows setting the perspective once and reusing it, like so:

import pygmt

fig = pygmt.Figure()
fig.set_perspective(azimuth=xxx, elevation=xxx, zlevel=xxx)
fig.basemap(region=xxx, projection=xxx, perspective=True)
fig.coast(..., perspective=True)
fig.text(...)  # No perspective parameter needed

With this approach, the perspective parameter can simply take a boolean value—True to apply the perspective settings defined by fig.set_perspective, and False to disable them. This would also simplify the docstring for the perspective parameter.

This is still an early idea, and I’d appreciate any feedback before proceeding with implementation.

Dominant language
Python
Stars
882
Forks
261
Avg merge
1d 3h
Merged PRs (30d)
29

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from GenericMappingTools/pygmt

All issues in GenericMappingTools/pygmt

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.