Pygmt : how to fill polygons with cmap color

Viewed 278

Good morning,

I am using pygmt on python 3.6 with spyder. I am trying to fill several polygons in a range of colors defined by a colorpalet. I used makecpt to define the colorpalet. The variable I want to represent is Mog.

My code is :

pygmt.makecpt(cmap="bilbao",  series=[-5, 50, 5])

for i , long in enumerate(longitude_polyT):     
      fig.plot(x=longitude_polyT[i], y=latitude_polyT[i], frame="a", pen="black", color=Mog[i], cmap=True)

But it doesn't fill my polygons.

Does anybody have an idea about it?

Thanks a lot!

1 Answers

Here is my best guess at what you want:

import pygmt

fig = pygmt.Figure()
a = fig.basemap(region=[0, 6, 0, 2], projection="X12c/4c", frame=True, )

pol = ["n0.9c", "c0.9c", "d0.9c"]
Mog = [
    pygmt.makecpt(cmap="bilbao", series=[-5, 50, 5]),
    pygmt.makecpt(cmap="bilbao", series=[-5, 15, 5]),
    pygmt.makecpt(cmap="bilbao", series=[-8000, 4000])
]
longitude_polyT = [1, 3, 5]
latitude_polyT = [1, 1, 1]

for i, long in enumerate(longitude_polyT):
    fig.plot(x=long, y=latitude_polyT[i], style=pol[i], frame=a,
             pen="black",
             color=Mog[i], cmap=True)
    
fig.show()

enter image description here

Couldn't get it to show different colours :(

Related