Skip to content
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

POC: Implement the general BaseParams class for any class-like parameters #2895

Closed
wants to merge 1 commit into from

Conversation

seisman
Copy link
Member

@seisman seisman commented Dec 18, 2023

This PR contains some experimental codes towards the Pythonic interface discussed in #1082. Generally speaking, this PR implements the base class BaseParams and any parameters that expect a class-like argument can inherit from it (a similar work is done in PR #1239).

In this PR, a Box class is implemented showing how the BaseParams can be used. The Box class can be passed to the box parameter in multiple modules (image, logo, basemap, coast, inset, legend and colorbar). The full syntax of the box parameter is (https://docs.generic-mapping-tools.org/dev/image.html#f):

-F[+cclearances][+gfill][+i[[gap/]pen]][+p[pen]][+r[radius]][+s[[dx/dy/][shade]]]

Here is an example showing how the Box class can be used:

import pygmt
from pygmt import params

fig = pygmt.Figure()
for i, box in enumerate(
    [
        params.Box(fill="red@20"),
        params.Box(clearance=(0.2, 0.2), fill="red@20", pen="blue"),
        params.Box(clearance=(0.2, 0.2), pen="blue", radius=True),
        params.Box(clearance=(0.1, 0.2, 0.3, 0.4), pen="blue", radius="10p"),
        params.Box(
            clearance=0.2, pen="blue", radius="10p", shading=("5p", "5p", "lightred")
        ),
        params.Box(clearance=0.2, pen="blue", innerborder=("2p", "1p,red")),
    ]
):
    print("###", i)
    print(repr(box))
    print(str(box))
    print()
    fig.logo(position="x0/0+w3c", box=box)
    fig.shift_origin(xshift=4)
fig.show()

The console outputs are:

### 0
Box(fill='red@20')
+gred@20

### 1
Box(clearance=(0.2, 0.2), fill='red@20', pen='blue')
+c0.2/0.2+gred@20+pblue

### 2
Box(clearance=(0.2, 0.2), pen='blue', radius=True)
+c0.2/0.2+pblue+r

### 3
Box(clearance=(0.1, 0.2, 0.3, 0.4), pen='blue', radius='10p')
+c0.1/0.2/0.3/0.4+pblue+r10p

### 4
Box(clearance=0.2, pen='blue', radius='10p', shading=('5p', '5p', 'lightred'))
+c0.2+pblue+r10p+s5p/5p/lightred

### 5
Box(clearance=0.2, innerborder=('2p', '1p,red'), pen='blue')
+c0.2+i2p/1p,red+pblue

The generated image is:
box

Known limitations that should be addressed:

  • innerborder=('2p', '1p,red') is not ideal. I expect to see innergap="2p", innerpen="1p,red" instead.
  • shading=('5p', '5p', 'lightred') is not idea, shading_offset=("5p", "5p") and shading_fill="lightred" is better

@seisman
Copy link
Member Author

seisman commented Sep 25, 2024

Superseded by the new implementation in #3238. Closing.

@seisman seisman closed this Sep 25, 2024
@seisman seisman deleted the options branch September 25, 2024 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

1 participant