PyGMT: customize "grid" in vector PDF export

Hello everyone,

our team is facing an issue with exporting maps in PDF format. The goal is to obtain a vector map that can then be imported and further customized in programs such as Adobe Illustrator. For this, landmasses should be separate objects whose color etc. can be adjusted. However, when producing and exporting such maps with PyGMT, the maps are always “sliced” with grid lines into multiple objects, and at highest resolution, for example the island of Madagascar consists just of a large number of small squares.

The following picture illustrates the problem: We export Madagascar with landmasses in orange. In low resolution (right), all of Madagascar is one vector object that I can recolor in yellow. In medium resolution, the grid is finer and Madagascar consists of two separate objects (middle). At highest resolution, Madagascar consists of many separate square objects (left).

If there a way to adjust this grid (these probably correspond to degrees / minutes), or better, altogether remove it for the exported image?

Thanks a lot in advance!

Miguel

I’m not sure what your referring to.
“Grid” as in “gridline” are controlled through frame mechanisms (frame=“g1 will create a gridline every “1” unit).
However, if you’re referring to some kind of gridding of your data (like gmtbinstat), it probably depends on what method you used. A small code excerpt would help.

What @mvences wants is land polygons in one piece. That is very inefficient for high-resolution data and hence the tiling. If you desperately need to color individual countries then see coast -E for selection a different polygon data set.

1 Like

Alternatively, pick the right color to start with and don’t mess with Illustrator.

Thank you @pwessel and @PlanetGus for your quick replies. And sorry that perhaps my wording was not ideal – I am a biologist with little experience with geographical applications. Unfortunately, the suggestion of “don’t mess with Illustrator” is not an option, because having each land polygon in one piece (as a single graphical object) is essential for our downstream applications (it is not just about color – I just used the orange vs. yellow color to illustrate the issue). We will try whether selecting a different polygon data set with -E can be a solution. If anyone has an idea how to adjust the “tiling” intervals in high-resolution vectorized (PDF) export, I would be very grateful. Note that I will be doing fieldwork in the next 3 weeks, but will report back here in early December – hopefully with a post with a good solution.

I think you are missing the point(s): (1) The GSHHG data used for plotting landmasses is already tiled and there is no undoing the tiling. The tiling interval differs for the different resolutions but they are all tiled for efficiency. (2) There is the alternate data set DCW which you can access via -E where each country is a separate polygon. (3) You are of course welcome to have whatever work flow you want, including using Illustrator to change color of things. It just sounds like a very manual, laborious, and subjective undertaking to me hence the other suggestions such as scripting what you want to achieve so it can be automated.

All what @pwessel said.
Have a look at some showcases and the documentation’s gallery to get a better idea of gmt’s capabilities.

It seems that everything you want to do manually can be scripted.

Maybe have a look at Inset — PyGMT? If you just want to color Madagascar yellow, you could try something like

import pygmt

fig = pygmt.Figure()
fig.coast(
    region="g",
    projection="G47/-20/10c",
    land="orange",
    water="white",
    dcw="MG+gyellow",
)
fig.show()

gives

Key bit is the dcw/-E parameter in fig.coast. You want to set the country code (MG for Madagascar) to a fill color (+g) of ‘yellow’.

For what you want to do, I would use a different data source for plotting the country polygons, probably either Natural Earth, which would allow you to select a basic level of detail in advance, or possibly GADM if you needed to plot lower-level administrative boundaries. In these datasets, individual countries or administrative regions are represented as individual polygons, not split into tiles as GMT does it with its internal version of GSHHS.