How to make a plot with nonstandard borders

Added by Kristof 3 months ago

Dear gurus,

I'm trying to cut out an area of the rectangular plot and have its border behave like a regular plot border with everything -B throws at it (think tickmarks and annotations).

I made a crude mockup to illustrate what I'm trying to achieve:

I experimented a bit with mapproject but was unable to calculate the coordinate of the top-right corner of the cutout. My thinking was to use psbasemap with --MAP_FRAME_TYPE=plain to force the tickmarks to the outside of the plot and just overlay a blank plot with borders only -BNE.

Do you have a clever idea how this look might be achieved?

Thank you for your input,
Kristof

cutout.jpg (186 KB)


Replies (7)

RE: How to make a plot with nonstandard borders - Added by Paul 3 months ago

You could try this approach - I don't know if it will work.
  1. Plot the full big map.
  2. Plot the small (white) corner "map" with
    1. Only the right/top border (-BEN)
    2. Set tickmarks etc on the outside of this box (so they will be inside your desired shape)
    3. Paint it white -B+gwhite); alternatively, use psclip before the first map if you need it to be untouched.

Seems like this should in theory work!

RE: How to make a plot with nonstandard borders - Added by Kristof 2 months ago

I think that is basically the approach I tried to describe in my original posting. However I initially failed at computing the coordinates of the top right corner of the overlaid blank (white) plot.

While I got it to work now there are some cosmetic problems with it. I added all the files to this post so you can have a look for yourself.

Result (cropped)
Cropped part of the resulting plot showing the lower right corner of the cutout

Problems

As already noted in the image above there are two problems with the plot:

  • The cutout is surrounded by a thin black line which is not desired. I assume this is a rounding error and is basically the border of the large plot peeking from behind the "cutout plot". Unfortunately the thin line shows also in the JPG when using psconvert to convert the plot to a raster graphic.
  • The plot border of the psbasemap covering the cutout area protrudes over the border of the large plot giving an unsightly overhang.

I'm scratching my head on how to get around these problems. Your ideas are highly welcome!

test_map_cutout.pdf - PostScript file converted to PDF for easier viewing (88 KB)

test_map_cutout.sh Magnifier - Script (469 Bytes)

test_map_cutout.ps - Resulting PostScript file (335 KB)

crop_result.png - Cropped part of the resulting plot showing the lower right corner of the cutout (35.2 KB)

RE: How to make a plot with nonstandard borders - Added by Paul 2 months ago

Just a quick comment. The overhang is probably a result of the PS_LINE_CAP setting. If it is butt and not square it may look different?

RE: How to make a plot with nonstandard borders - Added by Kristof 2 months ago

I experimented with your suggestion but it seems that the map border is not influenced by PS_LINE_CAP at all. It always behaves like PS_LINE_CAP square.

This behavior is necessary if you have two adjacent borders (like W and S border), otherwise there will be a missing piece in the corner where the borders meet when MAP_FRAME_TYPE plain is used.

However, this kills the effect if, as in my case, you overlay a MAP_FRAME_TYPE plain border over a MAP_FRAME_TYPE inside border.

My usage of gmt is most probably far away from what it was originally envisioned to do. I fully understand if you argue "it was never supposed to do that". However I see a problem with the way gmt handles MAP_FRAME_TYPE inside. When I set a MAP_FRAME_PEN I expect the plot border to be as wide as I set it.

Solution? I have none. The border must be cut in half so it really is "inside". No clever ideas from my side.

Here I exaggerated the line width for illustration purposes:

Have a try for yourself:

#!/bin/bash

FILE=test_map_cutout.ps

gmt set FORMAT_GEO_MAP ddd:mmF
gmt set MAP_FRAME_TYPE inside
gmt set PS_LINE_CAP round
gmt set MAP_FRAME_PEN thicker,black

gmt pscoast \
    -R-15/40/32/60r \
    -JL8.5/50/49.75/50.25/25c \
    -BWESN \
    -Bpa10f1g5 \
    -A200 \
    -Di \
    -Gwhite \
    -S240/248/255 \
    -Wthinnest,black \
    -K \
    > $FILE

gmt set MAP_FRAME_TYPE plain
gmt set PS_LINE_CAP butt
gmt set MAP_FRAME_PEN 10p,red

gmt psbasemap \
    -R-15/40/-12.5129615342/50.4737247249r \
    -JL8.5/50/49.75/50.25/4c \
    -BEN+gwhite \
    -Bpa10f1 \
    -O \
    >> $FILE

psconvert -Tf $FILE

crop.png (22.4 KB)

butt.png (8.87 KB)

square.png (9.03 KB)

inset.png (28.9 KB)

RE: How to make a plot with nonstandard borders - Added by Joaquim 2 months ago

Regarding your first issue. You need to be using a map scale. Not a fix size. Do you want to have a fixed size inset?

Like this you impose the UR corner coordinates

gmt pscoast -R-15/40/32/60r -Jl8.5/50/49.75/50.25/0.7 -BWESN -Bpa10f1g5 -A200 -Di -Gwhite -S240/248/255 -Wthinnest,black -K --MAP_FRAME_TYPE=inside > lixo.ps
gmt psbasemap -R-15/40/-10/50r -Jl8.5/50/49.75/50.25/0.7 -Ben+gwhite -Bpa10f1 -O >> lixo.ps

But if you want to know the coordinates of the UR corner of a rectangle 4.5x6 cm, do

mapproject -R-15/40/32/60r -Jl8.5/50/49.75/50.25/0.7 -I
4.5 6
-9.6175343609 49.9822966769

and now use them in first case.

RE: How to make a plot with nonstandard borders - Added by Kristof 2 months ago

Hi Joaquim,

thank you for looking into this – in the meantime I figured it out (see second reply above). And yes, I need fixed dimensions. It is basically a blank space for information like a small location map, descriptions, additional info etc.

I used:

kristof@h2813222:~$ echo "4 8" | mapproject -JL8.5/50/49.75/50.25/25c -R-15/40/32/60r -I
-12.5129615342    50.4737247249
kristof@h2813222:~$

And then just chopped the decimals at good enough resolution.

As I'm planning to use this on geoPDFs (thank you again for implementing this capability!) I'll experiment next with some obscenely wide pens and check if it breaks geoPDF behavior. Because there is something sticking out the border … and geoPDFs don't like things sticking outside the map border. I'll report back.

All the best,
Kristof

RE: How to make a plot with nonstandard borders - Added by Joaquim 2 months ago

See new extended (today) mapproject -W

(1-7/7)