GenericMappingTools / GenericMappingTools/pygmt
Add the Perspective class for setting perspective view
- Dominant language
- Python
- Stars
- 874
- Forks
- 255
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 40
Description
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](https://docs.generic-mapping-tools.org/6.6/gmt.html#perspective-full)
The GMT command-line syntax is rather complex:
```bash
-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:
```python
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)`](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:
```python
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.
Contributor guide
Assessment
This issue has not been assessed yet.