Skip to content

Figure.plot: parameter aspatial does not accept integers for filling polygons #2497

Closed
@michaelgrund

Description

@michaelgrund

Description of the problem

When using polygons (e.g. read in via geopandas), the aspatial parameter of Figure.plot does not accept integers for filling the corresponding polygons (the polygons remain empty). First they need to be converted to float.

Minimal Complete Verifiable Example

import pygmt
import geopandas as gpd

world = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres"))

world = world[world["continent"] == "Europe"]
world["pop_est"] = world.pop_est * 1e-6

fig = pygmt.Figure()

pygmt.makecpt(cmap = "lajolla", series = [0, 150, 50], continuous = True)

fig.basemap(region = [-12, 35, 35, 60], 
            projection = "M12c", 
            frame = True)

fig.plot(data = world, 
         pen = "1p,black", 
         close = True, 
         fill = "+z", 
         cmap = True, 
         aspatial = "Z=pop_est")

fig.colorbar(position = "JMR", frame = 'a10+lPopulation in millions')

###############################################################################
fig.shift_origin(yshift = "-11c")

# first round data, then convert to int
world["pop_est_round"] = round(world["pop_est"])
world["pop_est_int"] = world.pop_est_round.astype(int)

fig.basemap(region = [-12, 35, 35, 60], 
            projection = "M12c", 
            frame = True)

fig.plot(data = world, 
         pen = "1p,black", 
         close = True, 
         fill = "+z", 
         cmap = True, 
         aspatial = "Z=pop_est_int")

fig.colorbar(position = "JMR", frame = 'a10+lPopulation in millions')

fig.show()

grafik

Full error message

No response

System information

PyGMT information:
  version: v0.9.0
System information:
  python: 3.9.16 | packaged by conda-forge | (main, Feb  1 2023, 21:39:03)  [GCC 11.3.0]
  executable: /home/michael/anaconda3/envs/pygmt/bin/python
  machine: Linux-5.15.0-67-generic-x86_64-with-glibc2.31
Dependency information:
  numpy: 1.23.2
  pandas: 1.4.3
  xarray: 2022.6.0
  netCDF4: 1.6.3
  packaging: 21.3
  contextily: 1.3.0
  geopandas: 0.11.1
  ghostscript: 9.54.0
GMT library information:
  binary version: 6.4.0
  cores: 8
  grid layout: rows
  image layout: 
  library path: /home/michael/anaconda3/envs/pygmt/lib/libgmt.so
  padding: 2
  plugin dir: /home/michael/anaconda3/envs/pygmt/lib/gmt/plugins
  share dir: /home/michael/anaconda3/envs/pygmt/share/gmt
  version: 6.4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions