1

I am new to python and have just plotted my first map using matplotlib. I now want to plot a filled polygon or patch on this map using a set of coordinates I have. I have tried with pygame but it doesn't work. Do you have any suggestions?

Thanks in advance

# plot polygon using a set of coordinates        
pygame.draw.polygon(map,brown,[[67.8942,9.8188],[68.0048,10.345],[68.7539,11.5195]],3)
pygame.display.flip()
  • If you want to just draw the poygons using matplotlib, have a look at this question: https://stackoverflow.com/questions/26935701/ploting-filled-polygons-in-python – Vincent Sep 06 '17 at 08:48
  • 2
    The solution will depend on *how* you created the map. There are two toolkits for matplotlib (Basemap and Cartopy). Using those it is straight forward to plot any other matplotlib plot or patch on top. If you have a problem with that, you need to provide a [mcve] of the issue. – ImportanceOfBeingErnest Sep 06 '17 at 08:49
  • Thanks for your reply. I have used basemap to create the map. How can I add the patch on it is the problem. – Néstor Santana Sep 06 '17 at 09:01
  • @Vincent I checked the code but I'm not sure where to add the coordinates to make the polygon – Néstor Santana Sep 06 '17 at 09:06

1 Answers1

0

If you want to do Maps the package for you is folium. Check out this post on how to draw lines https://deparkes.co.uk/2016/06/03/plot-lines-in-folium/ - this will also allow you to draw polygons from coordinates. Also folium has a polygon plotting functionality. Package documentation is here http://folium.readthedocs.io/en/latest/

  • 1
    How is this related to plotting a filled polygon with Matplotlib? – Bart Sep 06 '17 at 10:52
  • It will plot polygons using the `Folium` package. As shown [here](https://geopandas.org/en/stable/gallery/polygon_plotting_with_folium.html). – not2qubit Aug 23 '22 at 15:46