{"componentChunkName":"component---src-templates-blog-post-js","path":"/en/blog/plotting-geographical-data","result":{"data":{"post":{"id":"-5babeaa4-1f7a-572d-a7be-bcbbd7bed810","publishedAt":"2020-11-01T17:00:00.000Z","categories":[{"_id":"53ed5f7e-f671-4432-ba1f-b1bbebaced2e","title":{"en":"Data Science","vi":"Data Science"},"slug":{"current":"data-science"}}],"mainImage":{"crop":null,"hotspot":null,"asset":{"_id":"image-771674f9dd90460e84d6f50349c091756b67ef34-600x400-png","url":"https://cdn.sanity.io/images/vrx9irrf/production/771674f9dd90460e84d6f50349c091756b67ef34-600x400.png"}},"title":"Plotting Geographical Data with Geopandas & Geoplot","singleLang":"en","slug":{"current":"plotting-geographical-data"},"excerpt":"Making beautiful maps with Geopandas and Geoplot","_rawBody":[{"_key":"e34e54b6ef94","_type":"block","children":[{"_key":"b859c9738613","_type":"span","marks":[],"text":""}],"markDefs":[],"style":"normal"},{"_key":"c72bb3a4de5d","_type":"image","asset":{"_id":"image-771674f9dd90460e84d6f50349c091756b67ef34-600x400-png","_type":"sanity.imageAsset","_rev":"DmK61VtPyEhMsfOjcmTux7","_createdAt":"2022-03-10T03:46:25Z","_updatedAt":"2022-03-10T03:46:25Z","assetId":"771674f9dd90460e84d6f50349c091756b67ef34","extension":"png","metadata":{"_type":"sanity.imageMetadata","dimensions":{"_type":"sanity.imageDimensions","aspectRatio":1.5,"height":400,"width":600},"hasAlpha":true,"isOpaque":true,"lqip":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAANCAYAAACpUE5eAAAACXBIWXMAAAsSAAALEgHS3X78AAADiElEQVQ4yz2S60+TBxSH+/csWcw2srFlyUCzOBzJBqgQZCTbUBYV5uLAyS0CibiIUqkOAiKMUcChBdY6QLkUaEFuUgptoW+vQFtoaTugWGgrz96xbB+enJNzkie/nBzJdHcLxrobOJpKCIw1EV3u41AY4tCq5tAzRXRVg3+oFUdXDdaZp1jEmeCfxBIYwxbQYPWLBCYweyeZtYwimakswpD1Oc7cU+w8ukps6A5v1FJiYzLezD4kMlGPr/YKlu9SEKp+xD70GLswgmVDg7ClweweweocxCb0odN1I5m++C1Lie+y+kUcoapzxNq+J9Z+hZhcrPIfOGi6jL/gS2xJ72FOTcR5qwD3YBtO8zjC8jDmF804FbWsj7ZhmFMh0WSls/DxMdZS3idUnk60/jzR+19zcPsc4Yqz7JWkEcxPZj3tI1Y+jUM4n4a38QYeVTOmB7dYuvQV1tI87M8V6JaNSPozMpmKP8ZqyofslmcSERPtS78hdD2V3YIUdssy2C5Kx5WZwGL8WxhOfoCvOAvvzVyW0j/jVUoSBpmUBZ2JMYsXyR+lVahPJLJ84h0C105z8CifsDSH3cLUI1m4MZ89EfelZIwJbyMkxeHPSxY5heVMAgvFhcxM6FA79+g1+ZH0KCd4kV/Iy0/icWYf5/WdbCI12YTLz/C6MpNwQx77HdfYrs3FV5JOoPgs29dP48s9if2ieK42OaPmIEpHjE69KFToNnjeO4amtALzTxfYlV0mIkoOanIIlaazW5zBXnUO+y1XiXSXcfB7EXs1F9iqyMHWLGN62ki/PYLCEkWuE4VPDEH6zTtMvLIhaMWfm1Syo+kkpKxju6aAYEEmweJsdlrLCWlb2J6UE+yV4etpwKxfYHwtjNIJT4Qobf8JnzmiqD2H6L1hnN5N3J4VtmzzBDV/4m+9h+fXWhzaYSzWFZYdDuzmJVzGKUyrLtTu2P/C33SBf4UqMfLA2iEaTwz91h4rPjdOnw2vW2DDMIuwuMS08y9xH0G7EWV+M4TFtY7Rtcm4ax+V85AuIULr/D8J5130GLZ4uujjqJ+zoZrRMzSj5eXcmIiWgZkFHk8JR3TPCqjmBUYWV9CarAya1lHoN2mdXqduZBlJ17ieDrWOBpWG2/JnlNV3UCRtpFwqpbr2Z+7er6ZS9svRrKymnop7ddysb+FBexdyZR/tfcM8VI5wt3OAiiYFfwOeiCbcji+gYAAAAABJRU5ErkJggg==","palette":{"_type":"sanity.imagePalette","darkMuted":{"_type":"sanity.imagePaletteSwatch","background":"#222d2e","foreground":"#fff","population":2.38,"title":"#fff"},"darkVibrant":{"_type":"sanity.imagePaletteSwatch","background":"#b10405","foreground":"#fff","population":2.94,"title":"#fff"},"dominant":{"_type":"sanity.imagePaletteSwatch","background":"#faba83","foreground":"#000","population":8.83,"title":"#fff"},"lightMuted":{"_type":"sanity.imagePaletteSwatch","background":"#cca0a7","foreground":"#000","population":0.08,"title":"#fff"},"lightVibrant":{"_type":"sanity.imagePaletteSwatch","background":"#faba83","foreground":"#000","population":8.83,"title":"#fff"},"muted":{"_type":"sanity.imagePaletteSwatch","background":"#ac795c","foreground":"#fff","population":0.01,"title":"#fff"},"vibrant":{"_type":"sanity.imagePaletteSwatch","background":"#d13120","foreground":"#fff","population":7.9,"title":"#fff"}}},"mimeType":"image/png","originalFilename":"image.png","path":"images/vrx9irrf/production/771674f9dd90460e84d6f50349c091756b67ef34-600x400.png","sha1hash":"771674f9dd90460e84d6f50349c091756b67ef34","size":148160,"uploadId":"fm9UbJxb4TymoyE3QvN9MsTSh0zRj1in","url":"https://cdn.sanity.io/images/vrx9irrf/production/771674f9dd90460e84d6f50349c091756b67ef34-600x400.png","id":"image-771674f9dd90460e84d6f50349c091756b67ef34-600x400-png","children":[],"internal":{"type":"SanityImageAsset","contentDigest":"2cea6c5d1b7d7a4b631005ee6b945857","counter":917,"owner":"gatsby-source-sanity"},"parent":null}},{"_key":"1d59aec28a28","_type":"block","children":[{"_key":"624838bc0cfb","_type":"span","marks":[],"text":"Background"}],"markDefs":[],"style":"h1"},{"_key":"264971190a5c","_type":"block","children":[{"_key":"ffc9341e620c0","_type":"span","marks":[],"text":"Travelling back to February 2019, I had been working as a researcher for a media company. My job involved lots of data and spreadsheets to store and analyze it. But for such a fast-growing industry with millions of rows of new data flowing in every day, Microsoft Excel was hardly sufficient to get the job done. It could easily take a whole morning just to update a few spreadsheets as the performance of Excel quickly deteriorates when working with large data. I was looking out to learn some new tools for my works and I found a Data Analysis with Python course at "},{"_key":"ffc9341e620c1","_type":"span","marks":["7fe352dfb5c4"],"text":"CoderSchool"},{"_key":"ffc9341e620c2","_type":"span","marks":[],"text":". To someone with a business background like me, coding felt like rocket science and it was not something that I thought I would be interested in. Nevertheless, being frustrated with Excel constantly crashing, I gave it a try anyway and OMG, it was mind-blowing. I have been coding since then and now I am teaching at the same school where I learnt my first line of code."}],"markDefs":[{"_key":"7fe352dfb5c4","_type":"link","href":"https://www.coderschool.vn/en/"}],"style":"normal"},{"_key":"66e4265332b8","_type":"block","children":[{"_key":"c6a6b180c27d0","_type":"span","marks":[],"text":"One of the topics that I have been encountering very frequently in my jobs was working with geographical data. Before I knew Python, it was a very challenging task to plot data on a map. One of our options was Tableau and its Map function (Source: "},{"_key":"c6a6b180c27d1","_type":"span","marks":["e1b82390e738"],"text":"Tableau"},{"_key":"c6a6b180c27d2","_type":"span","marks":[],"text":"). One limitation of Tableau, however, is that it can only plot data by Provinces in Vietnam, while many of the projects required data to be illustrated by Districts."}],"markDefs":[{"_key":"e1b82390e738","_type":"link","href":"https://help.tableau.com/current/pro/desktop/en-us/maps_howto_simple.htm"}],"style":"normal"},{"_key":"49831a56f6bc","_type":"block","children":[{"_key":"d3290206eaeb","_type":"span","marks":[],"text":""}],"markDefs":[],"style":"normal"},{"_key":"9eb23d0b1faf","_type":"image","asset":{"_id":"image-321d0f6ab9b74acc72a0a21cf3c053b22646a743-542x475-png","_type":"sanity.imageAsset","_rev":"DsHc46whJxIpNrcPyMBIGm","_createdAt":"2022-03-10T03:46:25Z","_updatedAt":"2022-03-10T03:46:26Z","assetId":"321d0f6ab9b74acc72a0a21cf3c053b22646a743","extension":"png","metadata":{"_type":"sanity.imageMetadata","dimensions":{"_type":"sanity.imageDimensions","aspectRatio":1.1410526315789473,"height":475,"width":542},"hasAlpha":true,"isOpaque":true,"lqip":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAASCAYAAABb0P4QAAAACXBIWXMAAAsSAAALEgHS3X78AAADh0lEQVQ4y02U21PbVhDG9Y93+tCHdqaZtjwnTSmQOJAMOCVpaho8KU2AlGAbWzdfJFmWrbt8lYG3r9/KNpOHnWPr7P7Ot3t2j7JYLHB3e4v7+3sslznG4zGmkynccYIDp4Hv1FN82/obj4x/sN27Qsmp48htoZF4mOar2Nu1LZdLKAmDs9kc4zlhXDMBTqcIphk++j28tOvYt2uoDHTcxB56WQg7i+CNU/j0jSYTTOdziDAxxRiG0IYR9FEMO0wRJimyLENK51Eaw4kD2LRhGvFbVmQQpikM38dHx8Gl68KJolUMvytWEKMXpLCiDF5C5zhGRAfZFKcszZDwdxQn8MIQndEI1/0+Kp0OXuo6jk0TLc9DyBiJU0TJeDrDfJFjNl8gSZJiQ1aBxlxtqmlQySfLQqXdRtkwsK9peK6qBVAlMKKfxChpmlBFitmMUNZCIHKaLxZHGHKtE/aWgaLoBSHP13ZA6Gm3C4sHSlyRcio1Y1pyEQJNshR24OPGc1H3+sV61uvila49gMRKtNdUKun76xIVwAlTnvCmBDabzxBQsYCqdgcntPdWG2/bOtWsIKWvoGUq/sKLGX4N9JIILd9DPRiwHWJeTIwvAwd/EfSnZeJN18ChqbFmrRWs1cIz2l6T/7m+M9vQ1jUsgJo/xJGp4netgQ+uDTsK0WCaJ/YKeLwGHugq60dYs4ldMcJ2Wyr2VQ3ntv2gUhmNJ6iPfJwPPOhBiCHbpj3y8KlvFdA/eFipdo092gu1SZVUJwoJE+CBpuPCdjDaAPN8iRk7fM5VWkd6byT9RuVF6qzd40oVW29OsP35P6bZLFLeXQNfEXglF0MhBTAhQDo/yibIOIYyCbIRsZaDMIDK08vVc/y0XcLWfglPP5xip1bDDmsoJin/27PoG66AThDAHPrQXB8WxzBOswdo0eSckFpTx5Mnj/HD99/g52e/4dfLS6pkTan+0NBwZnXhBKteVEJJkRA3SllY3pSM23oukyKNDD27j/LRIbZ++RGPdnbw9OIzymylimWg6rRx5dmQbpFeVhZ5jsJYP5kU6ckHdesRDKMYutlBpXqGvXfvcdy4wcXAxrXvoBG66KYBxvkcd3d3UOQN21jO902AG1jIusRUma1VO4MhbswuDHcAJ/Th8hXy+YwVML6n8qbylnNsTBRK4Aa2AW6mYFXTuJj1gLWXffGXKZO3UOL/B34NC1qmTp4YAAAAAElFTkSuQmCC","palette":{"_type":"sanity.imagePalette","darkMuted":{"_type":"sanity.imagePaletteSwatch","background":"#2c4358","foreground":"#fff","population":0.14,"title":"#fff"},"darkVibrant":{"_type":"sanity.imagePaletteSwatch","background":"#a8713b","foreground":"#fff","population":0.54,"title":"#fff"},"dominant":{"_type":"sanity.imagePaletteSwatch","background":"#a2d2d2","foreground":"#000","population":16.89,"title":"#fff"},"lightMuted":{"_type":"sanity.imagePaletteSwatch","background":"#a2d2d2","foreground":"#000","population":16.89,"title":"#fff"},"lightVibrant":{"_type":"sanity.imagePaletteSwatch","background":"#97d7f5","foreground":"#000","population":0.04,"title":"#fff"},"muted":{"_type":"sanity.imagePaletteSwatch","background":"#4d929d","foreground":"#fff","population":2.23,"title":"#fff"},"vibrant":{"_type":"sanity.imagePaletteSwatch","background":"#0ea97b","foreground":"#fff","population":0.69,"title":"#fff"}}},"mimeType":"image/png","originalFilename":"image.png","path":"images/vrx9irrf/production/321d0f6ab9b74acc72a0a21cf3c053b22646a743-542x475.png","sha1hash":"321d0f6ab9b74acc72a0a21cf3c053b22646a743","size":185284,"uploadId":"fMm5Prjx0SruqbizMYCwaGyUI0H13k6u","url":"https://cdn.sanity.io/images/vrx9irrf/production/321d0f6ab9b74acc72a0a21cf3c053b22646a743-542x475.png","id":"image-321d0f6ab9b74acc72a0a21cf3c053b22646a743-542x475-png","children":[],"internal":{"type":"SanityImageAsset","contentDigest":"7b246f54cfc35b947723c8925f7a4599","counter":1226,"owner":"gatsby-source-sanity"},"parent":null}},{"_key":"fb174cd6a7a6","_type":"block","children":[{"_key":"bbbe532b656f","_type":"span","marks":[],"text":"In that regard, Python provides much more flexibility and also more customization options when plotting on a map."}],"markDefs":[],"style":"normal"},{"_key":"d69fbc1f3faf","_type":"block","children":[{"_key":"7006db0d4a2f0","_type":"span","marks":["strong"],"text":"Geopandas & Geoplot"}],"markDefs":[],"style":"h1"},{"_key":"91e60a7c3fa2","_type":"block","children":[{"_key":"4702556509ae0","_type":"span","marks":["761f8a68f9e6","strong"],"text":"Geopandas"},{"_key":"4702556509ae1","_type":"span","marks":[],"text":" and "},{"_key":"4702556509ae2","_type":"span","marks":["494c8f0f0d7e","strong"],"text":"Geoplot"},{"_key":"4702556509ae3","_type":"span","marks":[],"text":" are two Python libraries that allow us to handle and visualize geographical data. "},{"_key":"4702556509ae4","_type":"span","marks":["strong"],"text":"Geopandas"},{"_key":"4702556509ae5","_type":"span","marks":[],"text":" is based on "},{"_key":"4702556509ae6","_type":"span","marks":["strong"],"text":"pandas"},{"_key":"4702556509ae7","_type":"span","marks":[],"text":" and extends its features to allow manipulating geometric data type. "},{"_key":"4702556509ae8","_type":"span","marks":["strong"],"text":"Geoplot"},{"_key":"4702556509ae9","_type":"span","marks":[],"text":", similarly, is built on top of "},{"_key":"4702556509ae10","_type":"span","marks":["strong"],"text":"matplotlib"},{"_key":"4702556509ae11","_type":"span","marks":[],"text":" for cartographic plots. If you are unfamiliar with "},{"_key":"4702556509ae12","_type":"span","marks":["strong"],"text":"pandas"},{"_key":"4702556509ae13","_type":"span","marks":[],"text":" and "},{"_key":"4702556509ae14","_type":"span","marks":["strong"],"text":"matplotlib"},{"_key":"4702556509ae15","_type":"span","marks":[],"text":", I suggest these two articles to get you started:"}],"markDefs":[{"_key":"761f8a68f9e6","_type":"link","href":"https://geopandas.org/"},{"_key":"494c8f0f0d7e","_type":"link","href":"https://residentmario.github.io/geoplot/index.html"}],"style":"normal"},{"_key":"dd227a945650","_type":"block","children":[{"_key":"aa0d4ec469f3","_type":"span","marks":["54f197a3a9de"],"text":"A Quick Introduction to the “Pandas” Python Library"},{"_key":"a7fb4441c159","_type":"span","marks":[],"text":"​ "}],"markDefs":[{"_key":"54f197a3a9de","_type":"link","href":"https://towardsdatascience.com/a-quick-introduction-to-the-pandas-python-library-f1b678f34673"}],"style":"h4"},{"_key":"f7dc137ebcc6","_type":"block","children":[{"_key":"3e999668db350","_type":"span","marks":["9b9c829e1710"],"text":"Data Visualization using Matplotlib"},{"_key":"58340506d1b6","_type":"span","marks":[],"text":"​ "}],"markDefs":[{"_key":"9b9c829e1710","_type":"link","href":"https://towardsdatascience.com/data-visualization-using-matplotlib-16f1aae5ce70"}],"style":"h4"},{"_key":"b089ea206715","_type":"block","children":[{"_key":"1ccd056c9410","_type":"span","marks":[],"text":"In this example, I will be running the code in a Colab Notebook environment. First, we will need to install "},{"_key":"32b5b285c2d6","_type":"span","marks":["strong"],"text":"Geopandas"},{"_key":"15c97e49200a","_type":"span","marks":[],"text":" and "},{"_key":"65c40f9df657","_type":"span","marks":["strong"],"text":"Geoplot:"}],"markDefs":[],"style":"normal"},{"_key":"39ee27a969fd","_type":"code","code":"!pip install git+git://github.com/geopandas/geopandas.git\r\n!apt install proj-bin libproj-dev libgeos-dev\r\n!pip install git+git://github.com/ResidentMario/geoplot.git\r\n","language":"python"},{"_key":"4d3195297150","_type":"block","children":[{"_key":"9a815f322333","_type":"span","marks":[],"text":"Import the necessary libraries:"}],"markDefs":[],"style":"normal"},{"_key":"0dce5f05c2c9","_type":"code","code":"import pandas as pd\r\nimport matplotlib.pyplot as plt\r\nimport geopandas as gpd\r\nimport geoplot as gplt\r\n\r\nimport warnings\r\nwarnings.filterwarnings('ignore')","language":"python"},{"_key":"807aee6482db","_type":"block","children":[{"_key":"b56caa670f16","_type":"span","marks":[],"text":"​Geometric data of countries around the world are widely available on the Internet. They come in many different formats, most of which are supported by "},{"_key":"68eb7899f1c7","_type":"span","marks":["strong"],"text":"geopandas"},{"_key":"8e3ff5b2ec6d","_type":"span","marks":[],"text":". Geometric data of provinces in Vietnam is available on "},{"_key":"bfee37d16773","_type":"span","marks":["3f88a48821fb"],"text":"HCMGIS OpenData"},{"_key":"625bbbfc596f","_type":"span","marks":[],"text":". In this example, I will use the JSON format. "},{"_key":"046327871bc8","_type":"span","marks":["strong"],"text":"Geopandas"},{"_key":"9b43a25a3665","_type":"span","marks":[],"text":" has the function "},{"_key":"b48e0def4c9f","_type":"span","marks":["em"],"text":"read_file"},{"_key":"fd356f62a2a5","_type":"span","marks":[],"text":" to read geometric data from a source. This returns a Geopandas DataFrame containing many columns, but we will only need to care about the Name (District), Province and geometry column."}],"markDefs":[{"_key":"3f88a48821fb","_type":"link","href":"http://opendata.hcmgis.vn/"}],"style":"normal"},{"_key":"9c9087063373","_type":"code","code":"GEO_URL = 'http://opendata.hcmgis.vn/geoserver/wfs?srsName=EPSG%3A4326&typename=geonode%3Avietnam_districts&outputFormat=json&version=1.0.0&service=WFS&request=GetFeature'\r\ngeo = gpd.read_file(GEO_URL)\r\n\r\n# We only need to care about the Name, Province and geometry column\r\ngeo = geo[['Name', 'Province', 'geometry']]\r\ngeo.sample(10)","language":"python"},{"_key":"863e6a7b94a8","_type":"image","asset":{"_id":"image-3756f383120c7aa7bbe71aaf349a463534821ef7-767x368-png","_type":"sanity.imageAsset","_rev":"DmK61VtPyEhMsfOjcmTvHf","_createdAt":"2022-03-10T03:46:27Z","_updatedAt":"2022-03-10T03:46:27Z","assetId":"3756f383120c7aa7bbe71aaf349a463534821ef7","extension":"png","metadata":{"_type":"sanity.imageMetadata","dimensions":{"_type":"sanity.imageDimensions","aspectRatio":2.0842391304347827,"height":368,"width":767},"hasAlpha":true,"isOpaque":true,"lqip":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAYAAAAywQxIAAAACXBIWXMAAAsSAAALEgHS3X78AAAA00lEQVQoz5WRSQ7DMAwD/f9PBtn3PTmzGAMs0rRA24Mg05HGohLO89RxHNr3XdM0qWkajeOoeZ5V17XKstQwDNq27WMsyxJ78jyPObRtq6qqYmOWZUrTNJ6LolCSJDG4p4Hg7LB2HZzQ970MBULuuu45HdoP8t0QMtp31OAwYI2DwWQ0NtHA/Q1LPEQzGe2ghrUF9mUARTRyB4hCQ68wT452UMNOX4AGfAJ+m/AJBGbbtoy2zX8svwFpJrzTu+WfJsQqcQX4h3in9+nYoYHXHa7rqgerM57/lnC3MAAAAABJRU5ErkJggg==","palette":{"_type":"sanity.imagePalette","darkMuted":{"_type":"sanity.imagePaletteSwatch","background":"#4c4c4c","foreground":"#fff","population":0,"title":"#fff"},"darkVibrant":{"_type":"sanity.imagePaletteSwatch","background":"#424242","foreground":"#fff","population":0,"title":"#fff"},"dominant":{"_type":"sanity.imagePaletteSwatch","background":"#bcbcbc","foreground":"#000","population":2.01,"title":"#fff"},"lightMuted":{"_type":"sanity.imagePaletteSwatch","background":"#bcbcbc","foreground":"#000","population":2.01,"title":"#fff"},"lightVibrant":{"_type":"sanity.imagePaletteSwatch","background":"#bcbcbc","foreground":"#000","population":0,"title":"#fff"},"muted":{"_type":"sanity.imagePaletteSwatch","background":"#767676","foreground":"#fff","population":1.64,"title":"#fff"},"vibrant":{"_type":"sanity.imagePaletteSwatch","background":"#7f7f7f","foreground":"#fff","population":0,"title":"#fff"}}},"mimeType":"image/png","originalFilename":"image.png","path":"images/vrx9irrf/production/3756f383120c7aa7bbe71aaf349a463534821ef7-767x368.png","sha1hash":"3756f383120c7aa7bbe71aaf349a463534821ef7","size":74873,"uploadId":"ANdVVKFFs0qWy1S6jRC1ecpVd4a2zai4","url":"https://cdn.sanity.io/images/vrx9irrf/production/3756f383120c7aa7bbe71aaf349a463534821ef7-767x368.png","id":"image-3756f383120c7aa7bbe71aaf349a463534821ef7-767x368-png","children":[],"internal":{"type":"SanityImageAsset","contentDigest":"9e5ebfd81dbeac7f53b871d73a365211","counter":1229,"owner":"gatsby-source-sanity"},"parent":null}},{"_key":"e23805ac0007","_type":"block","children":[{"_key":"41781dcab0d0","_type":"span","marks":[],"text":"Notice the data in the geometry column: they are in "},{"_key":"2329d58d165c","_type":"span","marks":["strong"],"text":"MULTIPOLYGON"},{"_key":"66ec2183d24c","_type":"span","marks":[],"text":" format, which represents the shape and the location of the district on the world map."}],"markDefs":[],"style":"normal"},{"_key":"98a6a365c8ab","_type":"block","children":[{"_key":"06eb7154df820","_type":"span","marks":[],"text":"We will also need some data to plot on the map. I have prepared some sample data in the form of a .csv file. It contains the numerical data of some districts in Vietnam and the province they belong to. We can read the file with "},{"_key":"06eb7154df821","_type":"span","marks":["strong"],"text":"pandas."}],"markDefs":[],"style":"normal"},{"_key":"cb7a8191d3fb","_type":"code","code":"DATA_URL = 'https://raw.githubusercontent.com/minhanhng-cd/generate-geo-map/master/data.csv'\r\ndata = pd.read_csv(DATA_URL)\r\ndata.sample(10)","language":"python"},{"_key":"a1c5f91638eb","_type":"image","asset":{"_id":"image-2a26d05da508aac681ae7ec267867904b77d5260-436x377-png","_type":"sanity.imageAsset","_rev":"DsHc46whJxIpNrcPyMBIQ4","_createdAt":"2022-03-10T03:46:27Z","_updatedAt":"2022-03-10T03:46:27Z","assetId":"2a26d05da508aac681ae7ec267867904b77d5260","extension":"png","metadata":{"_type":"sanity.imageMetadata","dimensions":{"_type":"sanity.imageDimensions","aspectRatio":1.156498673740053,"height":377,"width":436},"hasAlpha":true,"isOpaque":true,"lqip":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAARCAYAAADdRIy+AAAACXBIWXMAAAsSAAALEgHS3X78AAABfklEQVQ4y22Ui66CQAxE+f/vFF8oKgooIfTmbHJM4WoyWelj2mkXqmVZ4hfmeY77/R6HwyEej0d55jdNU9xut2I/Ho9xvV6jaZo4nU7xer2iGscxhmEIzoy+7+NyucRut4u2bePz+RSQBAF2cD6fCyDvui4q2Un2PyBgv98XQAgRneHDVtd1AXn4yS2EsBNEME6IkCPwI51g5OEH5GSfRUuH4Pl8lllBahESTQLE/SIkd0WIAyNzw0Ew3SGNExuAiLkhVR9dQ8pZJDs7CK3kkElwHAC7RG4ZO0Scqw6RSyXJsjTsjiOT6aMRzhWhVZQq7IIkZOVR4EMRxfARUyQD5ofBhWyXImHu3A7/SQY84MiS8wzzsrbjoNiXMFdyk/niQuCFz6MQectF8vYemmwXdEwhErTbhN3/lMz7DHKihBQCjkMy5wvRd8s6eZAwv8duWULtecurDgmiQ7bs14Rq3jmvFHaLbS+29xCOL+H7/V59CyFRssWw+T7bfZZM3B9VggN0oU9OAQAAAABJRU5ErkJggg==","palette":{"_type":"sanity.imagePalette","darkMuted":{"_type":"sanity.imagePaletteSwatch","background":"#505050","foreground":"#fff","population":2.41,"title":"#fff"},"darkVibrant":{"_type":"sanity.imagePaletteSwatch","background":"#424242","foreground":"#fff","population":0,"title":"#fff"},"dominant":{"_type":"sanity.imagePaletteSwatch","background":"#505050","foreground":"#fff","population":2.41,"title":"#fff"},"lightMuted":{"_type":"sanity.imagePaletteSwatch","background":"#bcbcbc","foreground":"#000","population":0.69,"title":"#fff"},"lightVibrant":{"_type":"sanity.imagePaletteSwatch","background":"#bcbcbc","foreground":"#000","population":0,"title":"#fff"},"muted":{"_type":"sanity.imagePaletteSwatch","background":"#7c7c7c","foreground":"#fff","population":0.79,"title":"#fff"},"vibrant":{"_type":"sanity.imagePaletteSwatch","background":"#7f7f7f","foreground":"#fff","population":0,"title":"#fff"}}},"mimeType":"image/png","originalFilename":"image.png","path":"images/vrx9irrf/production/2a26d05da508aac681ae7ec267867904b77d5260-436x377.png","sha1hash":"2a26d05da508aac681ae7ec267867904b77d5260","size":41229,"uploadId":"tGDRn16nOUvZkbQPjikpGPXlAbkPO7Wn","url":"https://cdn.sanity.io/images/vrx9irrf/production/2a26d05da508aac681ae7ec267867904b77d5260-436x377.png","id":"image-2a26d05da508aac681ae7ec267867904b77d5260-436x377-png","children":[],"internal":{"type":"SanityImageAsset","contentDigest":"d9aeaf3649363be7101a576635975812","counter":1227,"owner":"gatsby-source-sanity"},"parent":null}},{"_key":"3c60f3004e84","_type":"block","children":[{"_key":"5646eaf3787a","_type":"span","marks":[],"text":"In order to illustrate our example data on the map, we will need to combine it geopandaswith the geometric data. This can be achieved with the method "},{"_key":"57b8f098ef6d","_type":"span","marks":["em"],"text":"merge."}],"markDefs":[],"style":"normal"},{"_key":"7190daf7be6d","_type":"code","code":"geodata = geo.merge(data, how='inner', left_on=['Name','Province'], right_on=['Name','Province'])\r\ngeodata.sample(10)","language":"python"},{"_key":"5d28797504c4","_type":"image","asset":{"_id":"image-570cbb93e0b58fa0ab8bf784b32f2223a81ee17d-876x367-png","_type":"sanity.imageAsset","_rev":"DmK61VtPyEhMsfOjcmTvG5","_createdAt":"2022-03-10T03:46:27Z","_updatedAt":"2022-03-10T03:46:27Z","assetId":"570cbb93e0b58fa0ab8bf784b32f2223a81ee17d","extension":"png","metadata":{"_type":"sanity.imageMetadata","dimensions":{"_type":"sanity.imageDimensions","aspectRatio":2.3869209809264307,"height":367,"width":876},"hasAlpha":true,"isOpaque":true,"lqip":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAICAYAAAD5nd/tAAAACXBIWXMAAAsSAAALEgHS3X78AAAAyElEQVQoz42Q2w6EIAxE+f//RFG8K8a3mtNkCNlssvswltbh0Dbc923P8xhx2zab59mu6/J8XVdLKbmoH8fh/9B5ni7O+Pq+d1/Y991KKW7OOVeg8mEYbJomW5bFI7VxHKuU69FAVwCIuswDvC4gRoBcpBPUdV3tCuHDE/jQJbEF8kgLRJwFFIyaIqMHANodP8g1Mh21QI2mDr8CMbYdaofUyD9H/gnESDctkP1pp//uEPkOGVFAiuwNGHVd4KwdAkIxxgqVD88LdZ1aGkeqUjEAAAAASUVORK5CYII=","palette":{"_type":"sanity.imagePalette","darkMuted":{"_type":"sanity.imagePaletteSwatch","background":"#4c4c4c","foreground":"#fff","population":0,"title":"#fff"},"darkVibrant":{"_type":"sanity.imagePaletteSwatch","background":"#424242","foreground":"#fff","population":0,"title":"#fff"},"dominant":{"_type":"sanity.imagePaletteSwatch","background":"#bcbcbc","foreground":"#000","population":2.26,"title":"#fff"},"lightMuted":{"_type":"sanity.imagePaletteSwatch","background":"#bcbcbc","foreground":"#000","population":2.26,"title":"#fff"},"lightVibrant":{"_type":"sanity.imagePaletteSwatch","background":"#bcbcbc","foreground":"#000","population":0,"title":"#fff"},"muted":{"_type":"sanity.imagePaletteSwatch","background":"#767676","foreground":"#fff","population":0.81,"title":"#fff"},"vibrant":{"_type":"sanity.imagePaletteSwatch","background":"#7f7f7f","foreground":"#fff","population":0,"title":"#fff"}}},"mimeType":"image/png","originalFilename":"image.png","path":"images/vrx9irrf/production/570cbb93e0b58fa0ab8bf784b32f2223a81ee17d-876x367.png","sha1hash":"570cbb93e0b58fa0ab8bf784b32f2223a81ee17d","size":78406,"uploadId":"ZjDB4jNEieDnVq2DKxz3Xpi54KaAB60i","url":"https://cdn.sanity.io/images/vrx9irrf/production/570cbb93e0b58fa0ab8bf784b32f2223a81ee17d-876x367.png","id":"image-570cbb93e0b58fa0ab8bf784b32f2223a81ee17d-876x367-png","children":[],"internal":{"type":"SanityImageAsset","contentDigest":"ec8cc895225710afe3ef3af4a8cff213","counter":1228,"owner":"gatsby-source-sanity"},"parent":null}},{"_key":"adfdf070c327","_type":"block","children":[{"_key":"de9f43169342","_type":"span","marks":[],"text":"We can now make a map with "},{"_key":"59aea2431735","_type":"span","marks":["strong"],"text":"geoplot"},{"_key":"58ea719afaaf","_type":"span","marks":[],"text":". In this example, I am making a Choropleth map, where the value of our variable Data (hue) is represented by the color of the polygons. "},{"_key":"60a42e0b573d","_type":"span","marks":["strong"],"text":"Geoplot"},{"_key":"bf5ea39e6f1a","_type":"span","marks":[],"text":" has more options for map types, check out their "},{"_key":"8dbb138104b3","_type":"span","marks":["05a74de6de62"],"text":"Documentation"},{"_key":"2b105eca0caf","_type":"span","marks":[],"text":"."}],"markDefs":[{"_key":"05a74de6de62","_type":"link","href":"https://residentmario.github.io/geoplot/plot_references/plot_reference.html"}],"style":"normal"},{"_key":"638aeca25e9a","_type":"code","code":"gplt.choropleth(geodata, hue = geodata['Data'])","language":"python"},{"_key":"ad60fd491183","_type":"image","asset":{"_id":"image-880ed233b2ff2edee2e8d6077f0ae088a2bf8485-333x340-png","_type":"sanity.imageAsset","_rev":"DsHc46whJxIpNrcPyMBISO","_createdAt":"2022-03-10T03:46:27Z","_updatedAt":"2022-03-10T03:46:28Z","assetId":"880ed233b2ff2edee2e8d6077f0ae088a2bf8485","extension":"png","metadata":{"_type":"sanity.imageMetadata","dimensions":{"_type":"sanity.imageDimensions","aspectRatio":0.9794117647058823,"height":340,"width":333},"hasAlpha":true,"isOpaque":false,"lqip":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAsSAAALEgHS3X78AAADxElEQVQ4y5VUS4/bVBQ+99qOY09iXz/itx0/YseTZOwkNPNq2lGFNNLQp0AIVASoI1oJJBYVdANCAjYIodl0wYoVOzZIrKgQApYsEHtWSOxQf0S4tjvTaphK7ZVO7onvPZ+/c/ydA0CXffUFFL9csP3tUDDy0NDSKJBDXwaui6rz5d05PNdyrm/KyeXZbnJhdMufZ5/aRXJkrIdv9hLXNQ2CQbPhjTsBcHzn2QDNg4XRvzS7He0UD7zp8G8j7//bG7gPzNh6VTVVFQDBX6vXocV3nw2Q7JaCu5he6C/KI3sj+5ME9kPZ1n5THe1QNlSzuvPP6pOaIcYUHjdxGJ8B9sP9O/RXBDsZif7muR2zGH0tB87PgiLdFeS1VDJUvrr39revAGbYGoxuJ4ttnWY3XcKV95KmlrsXXass39cH8RFxzD0Avg41PPnsUnlnUCTpHLKyBGGvAGO25K1xUTjj/C2vHF7rzwdWtGjuiRJfsUOVHaeKqAYY7ow3ycEStq6XtW/kJRcuinF8bvhaWPoHdtJzWE7CqCodAzwFrAwfA6LTJK2tg4Z+uQ/Bskl941ImJNPwvJ+H98zIv6nYllHFMyxqU3ZtClTDtIUG9P+1SLbq3R2nkOTj2g8naT8cZ5/38/gbZ+BfZDsc02IRZlsMbkAk0Bc+2C+m4B6sg3d51IC16RcmA7/2eUmBYh7V/mSZm5Pt7LN8OvglyKJbbWKL9UuzyVPlp28GT3TLTlPD1eojAP8lyJdpONrOvhqUwz/sePBhW/ZIda7YMfC6CFjkwNkfwvDd8+hwdf8xkAhdyoyAsYiBhQ7o/R6nZF5oTeJ3gmn2U1AMfzfT5PaaYtZtYgQDwG0WoRbDdCK1pRSO2E11nhE4dJKys79R+2uSyhPXGBHf+ECLnB/tcfKrP8u+cMf9uayItUA6pgyYZzjE4jVO4gmvr9msxPfo/0biPAgQXm2mSUfXFMU3bxK3971s69/piXfozdPcn3oCQ885pYtoMEMZCohFEmKQijhsUzAdMGoAOQrpbee1L1m6pIb2FcUzPpYM5ZqoSxq3t44eqRjTYI6ya9OdNjWS6NPuI6Oqh8cCMofNV1YcjdNCy1YDK+4aWtVv6MtoCq2qPhix1NrUBBpagdEpRNPDlCdzSo1Eb8YS0SRQegRJPRUB24VO0AMSUU1XfUIDqZzpdAC2Lj0teZ3g8aJXOJ3OSwaa0WG6ysnZPWo9TwEjtZu7DD4GpQFVv9Xp1axo+s0z9gmSqq82DE0CCgUmDgG+W08tmN0on2v6/wcuOnAM6GhsbQAAAABJRU5ErkJggg==","palette":{"_type":"sanity.imagePalette","darkMuted":{"_type":"sanity.imagePaletteSwatch","background":"#505c2f","foreground":"#fff","population":0.06,"title":"#fff"},"darkVibrant":{"_type":"sanity.imagePaletteSwatch","background":"#15497a","foreground":"#fff","population":0.01,"title":"#fff"},"dominant":{"_type":"sanity.imagePaletteSwatch","background":"#505c2f","foreground":"#fff","population":0.06,"title":"#fff"},"lightMuted":{"_type":"sanity.imagePaletteSwatch","background":"#bbd2b0","foreground":"#000","population":0.02,"title":"#fff"},"lightVibrant":{"_type":"sanity.imagePaletteSwatch","background":"#e9e564","foreground":"#000","population":0.04,"title":"#000"},"muted":{"_type":"sanity.imagePaletteSwatch","background":"#589da7","foreground":"#fff","population":0.01,"title":"#fff"},"vibrant":{"_type":"sanity.imagePaletteSwatch","background":"#9c6404","foreground":"#fff","population":0,"title":"#fff"}}},"mimeType":"image/png","originalFilename":"image.png","path":"images/vrx9irrf/production/880ed233b2ff2edee2e8d6077f0ae088a2bf8485-333x340.png","sha1hash":"880ed233b2ff2edee2e8d6077f0ae088a2bf8485","size":29784,"uploadId":"ddSLEXzh0g2oQ9glWQORKilEnQuMUqWK","url":"https://cdn.sanity.io/images/vrx9irrf/production/880ed233b2ff2edee2e8d6077f0ae088a2bf8485-333x340.png","id":"image-880ed233b2ff2edee2e8d6077f0ae088a2bf8485-333x340-png","children":[],"internal":{"type":"SanityImageAsset","contentDigest":"a1e1cc0eb12970b479d23f54f31401a0","counter":1230,"owner":"gatsby-source-sanity"},"parent":null}},{"_key":"f87753d30ecb","_type":"block","children":[{"_key":"812ffbef2706","_type":"span","marks":[],"text":"Improving the Plot"}],"markDefs":[],"style":"h1"},{"_key":"0fd653e15996","_type":"block","children":[{"_key":"e1234e70dca90","_type":"span","marks":[],"text":"It is probably not a good idea to plot all districts in Vietnam together as there are so many of them. Instead, we can break down the country by region. For example, I can select only four provinces to plot by applying a filter to the DataFrame."}],"markDefs":[],"style":"normal"},{"_key":"fc6e60579c93","_type":"block","children":[{"_key":"10f36ae030f60","_type":"span","marks":[],"text":"Change the "},{"_key":"10f36ae030f61","_type":"span","marks":["em"],"text":"figsize"},{"_key":"10f36ae030f62","_type":"span","marks":[],"text":" argument to configure the size of the map and "},{"_key":"10f36ae030f63","_type":"span","marks":["em"],"text":"cmap"},{"_key":"10f36ae030f64","_type":"span","marks":[],"text":" for the color palette used for polygons."}],"markDefs":[],"style":"normal"},{"_key":"542e78fc15e7","_type":"code","code":"plotdata = geodata[geodata['Province'].isin(['Binh Duong Province','Tay Ninh Province','Long An Province','Ho Chi Minh City'])]\r\nPALETTE = 'OrRd'\r\n\r\ngplt.choropleth(plotdata, hue = plotdata['Data'], cmap = PALETTE, figsize = (15,10))\r\n","language":"python"},{"_key":"94ee65ce913d","_type":"block","children":[{"_key":"228d2d998dbb","_type":"span","marks":[],"text":""}],"markDefs":[],"style":"normal"},{"_key":"d7bfc0cce26e","_type":"image","asset":{"_id":"image-b7924d8fc7469ac90b298aa124296c4a32a3b51e-945x881-png","_type":"sanity.imageAsset","_rev":"DsHc46whJxIpNrcPyMBIXc","_createdAt":"2022-03-10T03:46:28Z","_updatedAt":"2022-03-10T03:46:28Z","assetId":"b7924d8fc7469ac90b298aa124296c4a32a3b51e","extension":"png","metadata":{"_type":"sanity.imageMetadata","dimensions":{"_type":"sanity.imageDimensions","aspectRatio":1.072644721906924,"height":881,"width":945},"hasAlpha":true,"isOpaque":false,"lqip":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAASCAYAAABb0P4QAAAACXBIWXMAAAsSAAALEgHS3X78AAAFFklEQVQ4y32UeVCTRxiHN3cwjAwhcogGpB7Vaq1FpzjgVXGggpzGYBUDEUQjRZEjUoOEKUEiGCBUOliKmiqi1KCioEQ5I7EBxURbiw5i0CCGQEIOQpB8X5Pg1X/6m9l535ndfea9dgGwqtOLZDOglewC4GBfu397DhE0k0moOz6uyP3gv9L9GAF69gaC/1UL+SNUtMAd2TaHSJIu8Qzo/e6rIFVK8AotK9Jj+HC4oyqXinrVwAXnvpgH+HgMKEIiQeE7xnsLrng6A5mP63sgQew9a1knmRR3f+mcc/0RK1s1aSHVelZkzlhWeMxo5hYfRVIgynYWFqTY77AxaFDwaXT1nkTwyHvWNHCui9tdL1KShOzS/GCJ58iLqFVvdRlbDOPZUUp9dlSjhr0taqgojmA7W+k1C3kcgUD88o6z/VOgzG+R3W/+zG1m18r58Q9WzZfL/RZCCoofNJYeChvZFNhQmtinr81mDzfxFp4iuxN5SIRnKQHvKJu4ar/LfQ+sne0MFPnxdl+WHo15VUAPU+bGSgdSI6BBRjA0mhoK6TixlnFhrn6i50ybql2Qdnm9f3wZCpXMA2B9EQBEa/2QvxHwABx5B1UJc+z22dkMjOE2N9gkKmgzXMx6q+HS4JG0cEhbsBsaF/GgyWd12pHuelnLHlp3lRvpYcVMh4pTJKe1pTNwuA81rMOhgTxoelzg3kqEsZ33ubm9iGOqz3miK0s0jx6OhjSFDEjX9DM09me1ZbBRMNXNOjAlCl9jadka8FBMD9rVmhBsrys49klzwhxnII7i0ajnAqaDoZ69XH8m5cjYCVqHNi9OrfmVbVHWlMIPsvdD4p0RcHdStKWvaI9ZdS7z8cgfrH2quqNOdkiqbWxwaGw1BuVegkT45gEQwAJgtnirL1abT/HW8Pbs1Z46ck99mjv5iHUQFn65GKohzoQ7Niw3KXmJsnERhz/ezA3U3sybjjBuOmXXy1g0tQqNFJxAgFouAR/fQA/xHq47RlTl79s8WpDcMsRKeCunbIIbF5Gh6z4esCTId/w5M/qGuoIRrr502GWoNhvZYQNuti4hDk28hkPvuoRBSSqxaJVgmc+tvytYPxmf3KRrTuekD2dslb5ODJpSUNfAvdH+0OPdIdAT5o7JAQ5NouJs/34oI8TRxtLmUQG4ZW1INR6DujEDu+gqFs2uc3OSi2M2qN9cK1Gan4pkxtYKqSJ355tHO9ZC/fRv4WFmFPT6WAKkOLHPoCxJahouio8eZIbZgfpcihVofY82NXk4o69iUIvbV8zL7M+iSAxCjtEsrpwytfJ1fcVJo7cj/QzS7QGWl8xI6EVKGPyMsVmnLKBd017J2aHvKF4wcqeQMNSQjwACLAp0zHcHMAwDAQCov2JWe2kKYxNMVcl1pguZYtN1ds1A5UG+iLqm9m7sxhdP07dN9YT6WbrWLTW+5NCem9qLmya6yo/qOkqWK0VcpD26s04OQL5pmd03CA8gDGU01/Eymr+hnB5sPH/w68Ezh7zu0QPX9ubSihXFKfd7qIFdd1cvblCWMu6ZJWXKye5yobGT76+wRWgbaptqPJxBIwFnf4/NDCp4XfEDcrAkAS1nbETY9vuYYXh1TdZK1QXWrn8yYijSkG/WqS9mx5ulJ8snpCcPGTr5Xh8GujN0hT1lm5TWz3OSF/thD1ZeBhPNx4GsKg30/Z6KeXU+1WGgKhnbX52JNEj4LkZJ2RJ9J3/uaBvP3ox/AcnpUdY6/pffAAAAAElFTkSuQmCC","palette":{"_type":"sanity.imagePalette","darkMuted":{"_type":"sanity.imagePaletteSwatch","background":"#5c3c3c","foreground":"#fff","population":0,"title":"#fff"},"darkVibrant":{"_type":"sanity.imagePaletteSwatch","background":"#970705","foreground":"#fff","population":4.9,"title":"#fff"},"dominant":{"_type":"sanity.imagePaletteSwatch","background":"#970705","foreground":"#fff","population":4.9,"title":"#fff"},"lightMuted":{"_type":"sanity.imagePaletteSwatch","background":"#d6b6a7","foreground":"#000","population":0.09,"title":"#fff"},"lightVibrant":{"_type":"sanity.imagePaletteSwatch","background":"#f6c47a","foreground":"#000","population":0.04,"title":"#000"},"muted":{"_type":"sanity.imagePaletteSwatch","background":"#a1755b","foreground":"#fff","population":0.51,"title":"#fff"},"vibrant":{"_type":"sanity.imagePaletteSwatch","background":"#df1816","foreground":"#fff","population":0.14,"title":"#fff"}}},"mimeType":"image/png","originalFilename":"image.png","path":"images/vrx9irrf/production/b7924d8fc7469ac90b298aa124296c4a32a3b51e-945x881.png","sha1hash":"b7924d8fc7469ac90b298aa124296c4a32a3b51e","size":170433,"uploadId":"YXezNxzYSsS3ecRJrQADkDJ5s2R1e9sx","url":"https://cdn.sanity.io/images/vrx9irrf/production/b7924d8fc7469ac90b298aa124296c4a32a3b51e-945x881.png","id":"image-b7924d8fc7469ac90b298aa124296c4a32a3b51e-945x881-png","children":[],"internal":{"type":"SanityImageAsset","contentDigest":"f0a003e2d0a6f05b80930e41359b8db6","counter":926,"owner":"gatsby-source-sanity"},"parent":null}},{"_key":"15a7176141f8","_type":"block","children":[{"_key":"0f68f0bddb68","_type":"span","marks":[],"text":"What we often want to do is to add some labels to the plot (i.e. name of the districts and the values of the variable). Since "},{"_key":"9e7bf1fd8c46","_type":"span","marks":["strong"],"text":"geoplot"},{"_key":"134c5aedd46e","_type":"span","marks":[],"text":" is built on top of "},{"_key":"2124685f2ebe","_type":"span","marks":["strong"],"text":"matplotlib"},{"_key":"158ec98599ee","_type":"span","marks":[],"text":", we can do this using the "},{"_key":"b2d5f915d608","_type":"span","marks":["em"],"text":"plt.text"},{"_key":"317d94adc152","_type":"span","marks":[],"text":". However, it requires the position of the label on the plot. The method "},{"_key":"2da151de0eff","_type":"span","marks":["em"],"text":"centroid"},{"_key":"9c0ede409a0b","_type":"span","marks":[],"text":" returns a x-y coordinate of the point in the center the polygon, which is just what we need!"}],"markDefs":[],"style":"normal"},{"_key":"6e9fc32fd194","_type":"code","code":"geodata['coords'] = geodata['geometry'].apply(lambda x: x.centroid.coords[:])\r\ngeodata['coords'] = [coords[0] for coords in geodata['coords']]\r\n\r\ngeodata.sample(10)","language":"python"},{"_key":"a1db7254991e","_type":"block","children":[{"_key":"62e2ca351dc6","_type":"span","marks":[],"text":""}],"markDefs":[],"style":"normal"},{"_key":"40b5b60ba2a5","_type":"image","asset":{"_id":"image-866d4c8ae9a109cfd1f32bb112e128c5523076af-945x312-png","_type":"sanity.imageAsset","_rev":"ofM7EIDfnwHVEh3rYRktBI","_createdAt":"2022-03-10T03:46:27Z","_updatedAt":"2022-03-10T03:46:28Z","assetId":"866d4c8ae9a109cfd1f32bb112e128c5523076af","extension":"png","metadata":{"_type":"sanity.imageMetadata","dimensions":{"_type":"sanity.imageDimensions","aspectRatio":3.0288461538461537,"height":312,"width":945},"hasAlpha":true,"isOpaque":true,"lqip":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAHCAYAAAAIy204AAAACXBIWXMAAAsSAAALEgHS3X78AAAAuklEQVQoz3WQSQ7FMAhDc/9jdkindB62fD0kV/lVu7AgEBtDmOfZUkrWdZ31fW9t21pVVRZj9Dc9YRgGr4NpmhzUxIcXJNI0jQsQ67r2CJFPT0DGCLEsyz/cgjTHcXRRuUX0KcYw/u377u6KonCoH2jK9rIsvgY1rcOwHAzC3bZtzmGoQD9Q5BNkOczznCCSbkqum+KcGHCig7+JfwnSfxW8rsvO87TjOByswn2Uc4Yc67refXLVOQPxB72eC7EwPCvUAAAAAElFTkSuQmCC","palette":{"_type":"sanity.imagePalette","darkMuted":{"_type":"sanity.imagePaletteSwatch","background":"#4c4c4c","foreground":"#fff","population":0,"title":"#fff"},"darkVibrant":{"_type":"sanity.imagePaletteSwatch","background":"#424242","foreground":"#fff","population":0,"title":"#fff"},"dominant":{"_type":"sanity.imagePaletteSwatch","background":"#bcbcbc","foreground":"#000","population":3.07,"title":"#fff"},"lightMuted":{"_type":"sanity.imagePaletteSwatch","background":"#bcbcbc","foreground":"#000","population":3.07,"title":"#fff"},"lightVibrant":{"_type":"sanity.imagePaletteSwatch","background":"#bcbcbc","foreground":"#000","population":0,"title":"#fff"},"muted":{"_type":"sanity.imagePaletteSwatch","background":"#818181","foreground":"#fff","population":0.87,"title":"#fff"},"vibrant":{"_type":"sanity.imagePaletteSwatch","background":"#7f7f7f","foreground":"#fff","population":0,"title":"#fff"}}},"mimeType":"image/png","originalFilename":"image.png","path":"images/vrx9irrf/production/866d4c8ae9a109cfd1f32bb112e128c5523076af-945x312.png","sha1hash":"866d4c8ae9a109cfd1f32bb112e128c5523076af","size":116314,"uploadId":"DWJyjJG48IKLNuERxoMKKgS65numDsOb","url":"https://cdn.sanity.io/images/vrx9irrf/production/866d4c8ae9a109cfd1f32bb112e128c5523076af-945x312.png","id":"image-866d4c8ae9a109cfd1f32bb112e128c5523076af-945x312-png","children":[],"internal":{"type":"SanityImageAsset","contentDigest":"6cb2a5621b57f7c547fb4089b4f6a70e","counter":1231,"owner":"gatsby-source-sanity"},"parent":null}},{"_key":"b929c7e6aaa0","_type":"block","children":[{"_key":"9c03ef30d1a8","_type":"span","marks":[],"text":"Now we can add some labels to the plot with "},{"_key":"9a4ae4e2a8b5","_type":"span","marks":["strong"],"text":"matplotlib"},{"_key":"438bf909d570","_type":"span","marks":[],"text":"."}],"markDefs":[],"style":"normal"},{"_key":"19b98c4ea242","_type":"block","children":[{"_key":"23b83aceba83","_type":"span","marks":[],"text":""}],"markDefs":[],"style":"normal"},{"_key":"dce09a647387","_type":"code","code":"plotdata = geodata[geodata['Province'].isin(['Binh Duong Province','Tay Ninh Province','Long An Province','Ho Chi Minh City'])]\r\nPALETTE = 'OrRd'\r\n\r\ngplt.choropleth(plotdata, hue = plotdata['Data'], cmap = PALETTE, figsize = (60,30))\r\n\r\nfor _, row in plotdata.iterrows():\r\n\r\n  hue = round(row['Data'],2)\r\n  \r\n  plt.text(s=row['Name'], x = row['coords'][0], y = row['coords'][1],\r\n           horizontalalignment='center', fontdict = {'weight': 'bold', 'size': 8})\r\n\r\n  plt.text(s='Data: ' + f'{hue:,}', x=row['coords'][0],y = row['coords'][1] - 0.01 ,\r\n          horizontalalignment='center', fontdict = {'size': 8})\r\n","language":"python"},{"_key":"4d009be40a69","_type":"block","children":[{"_key":"bf0d9720d1eb","_type":"span","marks":[],"text":""}],"markDefs":[],"style":"normal"},{"_key":"b5f30effb905","_type":"image","asset":{"_id":"image-9be649b74d8629c289f16057b668afdf67087388-945x881-png","_type":"sanity.imageAsset","_rev":"DsHc46whJxIpNrcPyMBIcG","_createdAt":"2022-03-10T03:46:29Z","_updatedAt":"2022-03-10T03:46:29Z","assetId":"9be649b74d8629c289f16057b668afdf67087388","extension":"png","metadata":{"_type":"sanity.imageMetadata","dimensions":{"_type":"sanity.imageDimensions","aspectRatio":1.072644721906924,"height":881,"width":945},"hasAlpha":true,"isOpaque":false,"lqip":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAASCAYAAABb0P4QAAAACXBIWXMAAAsSAAALEgHS3X78AAAFHUlEQVQ4y32UeVBTVxSHb1aCMFqSiCCyWZfiUkvVSotSaFUUlTWAFZIaQBFLkV2GEIlCAUMQEistLiAOoDQ2UREECmIEIcYNgstYFcUQGiBhSV4AlbzX5IkO/adn5s75zdxzvznn3HMvAEZrd6SaHGiypwAk3BPVdXZWoNmBimteaI2lg/+aNt0fSKO8wP9aiwN12lNA02IbrGQBmSpbZrf+6dYvvAfjtriOZgTYqtP8LAcPh+L66o6CiuXOQEAiAB4WC/KnGR88uGTMpmuhNaolDhSLVqe5K9scKLvvLV9Q0eO/5sZI0rYqLcs/czTNd+dw6o6FvdEbcaZY5FwceuYwAQ/yZmZXY0cG3U5zUX3DnjKvzZEafcuecv2ui53mVeDad2Mp2yFdRoBSmxF4bYQTEqji7bYwxZ5ymIvlYjCY36Y5P8wEdrktfV/yp/Nmy9YsYt5bu0je5bYE7g12g8eStiNQZjAC8fe80AnZHPVfhUtOOtqSj2ExdnwLkqV88gp69ugHoHC+FejNYaJankIjKHIjfBWccFlvvB/cF+MNqw9sg8ey6Qa9iKObuF8mGZCUJwk93Zl8HC62AABPHgBkY/+wJy1IALCmoYOiTNT3VKQStI15W3T1OZLR8wffDebQEVWCL6zJiYChhgJ48qlodOj2pa6mKPrd0/OonSWzzUtOUud48GeRzD72UGyGB3Lv1ahGXpRhdBLeZ+M38n+BLh96ouFHvlGlBMBDR2Pg0Ybj8Ii00qCoPTslY8VNNfpuMDQHuXfeZG5mtER6o30FWTMux8fSHMMm4XEvylPNoRrOKm3ZzywNl946dIShVpccMryuLETuZuyHb4b5I7f3Bhmecfe86S9PejhQnR6jErHnoJBE09iY4YlVBJxNERazOhsD1rMBmN8espaoyaY5qXl79g3/ni4dOJP3tjM9DhGudIGryLORFs/PJ17xIru09VkCXVPuxpFrWe8zZLwv2fpPIj60FI89x8MAYe4sM+ZVpo/TkDiXPJCzz0edF9vSz4p810nbiFxdag+LnW2Qlu9dxx8n+tUqT0T7Df2RRlEJ2dhTJuA64xKZ4cmXzfCMCwRcRwkRP1i2wrlBXpyepX1YG6EpZSerkoNkyqjNUz0h65FHAV/D0vBN8K3YwLdyVmhHb2bwLmWyj6WJNcChAXCeiAPVJAKuxpy4VETEcy5az5FLQj3VSvExpf7Jta6x5mLZy8ywAfkuD/g50wvpS/KDH2eEw1I2HerO/rFRkUsPUh7cgQLV7CAAao03jH4GtlZ4MQHnInF1Tu1Jo3WMXszS6yUlU7rmQu2zgr3Djf5uUMdOd0NPsh/8JGYrcj9yk/bZkbArGhE7TNdauFjdnG+hqsvBgGoiHkgW2QAEQUAlALjHO79xHM6nR0GnfxLrK5PbxmsyL/SeOiCoD9kglIR5vXqUQJu64/OVod1juf5lNqNHLylonJCdOKRtLVr1TxMXi2Z34RNz8GDTClRD4niMTsCwhgQMd6g4You+Mv7L/rOJjm27v/OQs8OK/ubuvyejed256eZSpyiKkY7f4isnZSdEULvAva8hD4MONQq1tQL1xqeTa9SyhHCgOXMAq+JH4R9Ee2FM+90JPiRFefKa1+UHGd0JwcHSbeu+HarOYE7c/rXYuBKNQMePA92+3RUt2WT9LH+g4+76uIf0XQST17mgszQJPD8XT1BUJJgrSmOJr6tSsFCHgKLvOL5M1y6wH5YUEkzx/wKDqEzyaLckiQAAAABJRU5ErkJggg==","palette":{"_type":"sanity.imagePalette","darkMuted":{"_type":"sanity.imagePaletteSwatch","background":"#5a3734","foreground":"#fff","population":0.02,"title":"#fff"},"darkVibrant":{"_type":"sanity.imagePaletteSwatch","background":"#930605","foreground":"#fff","population":4.3,"title":"#fff"},"dominant":{"_type":"sanity.imagePaletteSwatch","background":"#930605","foreground":"#fff","population":4.3,"title":"#fff"},"lightMuted":{"_type":"sanity.imagePaletteSwatch","background":"#ceb6a7","foreground":"#000","population":0.16,"title":"#fff"},"lightVibrant":{"_type":"sanity.imagePaletteSwatch","background":"#f5c47c","foreground":"#000","population":0.02,"title":"#000"},"muted":{"_type":"sanity.imagePaletteSwatch","background":"#9d6f4f","foreground":"#fff","population":0.58,"title":"#fff"},"vibrant":{"_type":"sanity.imagePaletteSwatch","background":"#d71915","foreground":"#fff","population":0.38,"title":"#fff"}}},"mimeType":"image/png","originalFilename":"image.png","path":"images/vrx9irrf/production/9be649b74d8629c289f16057b668afdf67087388-945x881.png","sha1hash":"9be649b74d8629c289f16057b668afdf67087388","size":216369,"uploadId":"iYCRDgzMzqEvNRLc9oQdKIoMuYty37o8","url":"https://cdn.sanity.io/images/vrx9irrf/production/9be649b74d8629c289f16057b668afdf67087388-945x881.png","id":"image-9be649b74d8629c289f16057b668afdf67087388-945x881-png","children":[],"internal":{"type":"SanityImageAsset","contentDigest":"52687e81f796a114c464e4d6f3104126","counter":927,"owner":"gatsby-source-sanity"},"parent":null}},{"_key":"e3cb0231b0d8","_type":"block","children":[{"_key":"7d305b29fc17","_type":"span","marks":[],"text":"Notice those messy text cluster on the lower right corner? It is because the districts in Ho Chi Minh City are too small and their labels are too closed to each other. One solution is to exclude the labels of Ho Chi Minh City’s districts from the map."}],"markDefs":[],"style":"normal"},{"_key":"ec2a376242ec","_type":"block","children":[{"_key":"0d1144b5c115","_type":"span","marks":[],"text":""}],"markDefs":[],"style":"normal"},{"_key":"9c8adac3e5c4","_type":"code","code":"plotdata = geodata[geodata['Province'].isin(['Binh Duong Province','Tay Ninh Province','Long An Province','Ho Chi Minh City'])]\r\nPALETTE = 'OrRd'\r\nEXCLUDE_PROVINCE = ['Ho Chi Minh City']\r\n\r\ngplt.choropleth(plotdata, hue = plotdata['Data'], cmap = PALETTE, figsize = (60,30))\r\n\r\nfor _, row in plotdata.iterrows():\r\n\r\n  if row['Province'] not in EXCLUDE_PROVINCE:\r\n\r\n    hue = round(row['Data'],2)\r\n    plt.text(s=row['Name'], x = row['coords'][0], y = row['coords'][1],\r\n            horizontalalignment='center', fontdict = {'weight': 'bold', 'size': 8})\r\n\r\n    plt.text(s='Data: ' + f'{hue:,}', x=row['coords'][0],y = row['coords'][1] - 0.01 ,\r\n            horizontalalignment='center', fontdict = {'size': 8})\r\n","language":"python"},{"_key":"a36a22ad5d91","_type":"block","children":[{"_key":"ac61cc1f239b","_type":"span","marks":[],"text":""}],"markDefs":[],"style":"normal"},{"_key":"1c1c2372de66","_type":"image","asset":{"_id":"image-0dd59b4bd7974ada23325ac828e63e9c38094926-945x881-png","_type":"sanity.imageAsset","_rev":"DmK61VtPyEhMsfOjcmTvNC","_createdAt":"2022-03-10T03:46:29Z","_updatedAt":"2022-03-10T03:46:30Z","assetId":"0dd59b4bd7974ada23325ac828e63e9c38094926","extension":"png","metadata":{"_type":"sanity.imageMetadata","dimensions":{"_type":"sanity.imageDimensions","aspectRatio":1.072644721906924,"height":881,"width":945},"hasAlpha":true,"isOpaque":false,"lqip":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAASCAYAAABb0P4QAAAACXBIWXMAAAsSAAALEgHS3X78AAAFH0lEQVQ4y32UeVBTVxTGb1aCMFqSCCKySF2KS63byBQX6KhYUAw7BYkEUIRaBFkHiMQGWYOYOGJxAXFAoWCiUhARhAAlGKVCsFo3MIbQAAmE5EVByXtNnujoPz0zd843c8/9zXfOve8BYIgue6oxgWZbCkD2uaK6wcYCtNhRcS2OlthQ8GVo0migO9IN/G+02lFnMwU0L12AFS4iU8UrbDY//fE799HYXWvVGd7WytS95qPHA3FDDXmgYuViwCMRAAeLBQWzjI8ZXDe46XO0RLXQjmLW4TB/dacdJaxn5aKKAdqGtokEzyuadFqmOtUraDx5j6M0ajvOWItcjkXPHCfgQe7n7upsyKDfYT6q22wpVp321Kg/bSl3HzjZqF75bHw/mbQb0mZ4yzUZPrcmWAE+Ck6YmbH2vN18bD4Ggzk7y/npc2Cf8/IPLX9tNVe8YQmjZ+MSSZ/zMljq7wxPJuxGoEx/BOIeeKmtYbKUd4qWnbO3Jp/EYmy4ZiRzydRN9GzeR2DNQgsgzWagWpLkR5DlhHvJWPvE0ri98FC0O6w84glPZoXqdXyW9u1fZcIRYXlCjasLg4vDHS4EwJUDANkwP+w5MxIA6bPQUX4mmgcqkgmaptxd2sZsofpqyvvR7FBEEe8Fq7LDYeh2ITz1lK8eu3e9rzky9MEFK2pvyVzTknPUeVu5c0gmn2YoMMEDift6VCMvyzBaIeebN20FJ6Abx56ouBHTiiRveCwvGlbfPg1PdFfqZfWXZsTpsTNNXlv0Lb4uve2MnfTWCHd0roD92eV4mJtimCQ87mV5silUx1qjKfslXZUf2jH2K12pLDmmf11ZhPRkxMDtITTk3kFf/fP8A9PD5QmPRqrTohV85jwUctT4bEzwxCsE3IJTWMz6LAzYzARgYVfARqIqy89ByTlwaPy3tO6Ri7nvetNikWurneAr5LlIq+u3b18VRPRpGtk8bXPO9olb7A8O6R9atrxGxAeW4rGXORhQkzPHhPEHw8NhTJBDHsk+5KHMPdw6nB7xvtdvO9Kw3Ba+6WiNdOxY9+Zponf9v2cP7VX+nkpR1DKx1UbgJsPim+DJN0zw9CoCTlRCxI+WrVp8W1KcxtY8qg9XlTITFYm+YnnkzpnBwM3IP74ucH+EJ/x3cvC7QTZdpMgKClYkeZgbWePsAACuEnGgmkTA1ZkSl/OJeFat5TyJMNBVKReclOue3OqbbCkWD2aGjEiCt8Ivwt2QkRQfeDgnEpYWRkPyoqimMU6Y73CKFwrUsvwBqDfcMPozsLbACwg4J+HaxckDqX4idS1bpxOWzGhbijTPCw+ON9GcIVGQi16aRIMHY/cgz2I8NEO5+2+qr2eGaDuKlqpaCswUDdkYUE3EA+GSBQBBEFAJAO5x0Pf24wWhkdCFnwW6ysTON3WZVdLzR3iNAVtq2kPcXj2O95u577lJ371tpe71if0Db9uLmqbuFx/TdJxaI7+Th0XdVX1lCh7uWIVqSBCH0fLolhCP7gIVh+/SVcatG7501L4z7IetEmbIqWf5MT1iP7f77c5ODUPcmO5p0Wn5uwfFfF0Xz0VqdCiYbbnK2gI0Gj6dHIMWx+8DqotHsApuJP5hlBvGuN8f70GSlSdueF2eQu+P9/fv9ty0TVnNZEyLzxRPic8chbp49p8edNfutWjLxhhOpwFtfvCnPWSoFkzdzQe9pQngxeU4gqwi3lRWepgou5qMhUQ8ik50eoW2i2c7LjxJMNb/B3N6Tq4on1NLAAAAAElFTkSuQmCC","palette":{"_type":"sanity.imagePalette","darkMuted":{"_type":"sanity.imagePaletteSwatch","background":"#593634","foreground":"#fff","population":0.01,"title":"#fff"},"darkVibrant":{"_type":"sanity.imagePaletteSwatch","background":"#930605","foreground":"#fff","population":4.33,"title":"#fff"},"dominant":{"_type":"sanity.imagePaletteSwatch","background":"#930605","foreground":"#fff","population":4.33,"title":"#fff"},"lightMuted":{"_type":"sanity.imagePaletteSwatch","background":"#ceb6a7","foreground":"#000","population":0.14,"title":"#fff"},"lightVibrant":{"_type":"sanity.imagePaletteSwatch","background":"#f5c47c","foreground":"#000","population":0.02,"title":"#000"},"muted":{"_type":"sanity.imagePaletteSwatch","background":"#a26f4f","foreground":"#fff","population":0.56,"title":"#fff"},"vibrant":{"_type":"sanity.imagePaletteSwatch","background":"#d71915","foreground":"#fff","population":0.38,"title":"#fff"}}},"mimeType":"image/png","originalFilename":"image.png","path":"images/vrx9irrf/production/0dd59b4bd7974ada23325ac828e63e9c38094926-945x881.png","sha1hash":"0dd59b4bd7974ada23325ac828e63e9c38094926","size":203563,"uploadId":"07R9dVPOpjeet8jgu2QfvBf9mkNp2rGf","url":"https://cdn.sanity.io/images/vrx9irrf/production/0dd59b4bd7974ada23325ac828e63e9c38094926-945x881.png","id":"image-0dd59b4bd7974ada23325ac828e63e9c38094926-945x881-png","children":[],"internal":{"type":"SanityImageAsset","contentDigest":"ce8cb0b75f5f24ac010d60784c6d40b4","counter":1233,"owner":"gatsby-source-sanity"},"parent":null}},{"_key":"01021e73430e","_type":"block","children":[{"_key":"fef85f83f587","_type":"span","marks":[],"text":"Another very helpful feature of "},{"_key":"bfa49728e5b6","_type":"span","marks":["strong"],"text":"geopandas"},{"_key":"2202cbb20b4a","_type":"span","marks":[],"text":" is to combine multiple polygons together into larger chunks. This is particularly useful when, for example, you want to visualize the data by Provinces instead of Districts. "},{"_key":"aeaf2676bce0","_type":"span","marks":["strong"],"text":"geopandas"},{"_key":"9bb401f8953e","_type":"span","marks":[],"text":" has the dissolve() function to aggregate Districts data rows into the respective Provinces."}],"markDefs":[],"style":"normal"},{"_key":"cd3cc456361b","_type":"block","children":[{"_key":"a2b562820a7c","_type":"span","marks":[],"text":""}],"markDefs":[],"style":"normal"},{"_key":"0ebcb37f9389","_type":"code","code":"plotdata_province = plotdata.dissolve(by='Province', aggfunc='sum')","language":"python"},{"_key":"dcf0ab0ee621","_type":"block","children":[{"_key":"85283d9f4387","_type":"span","marks":[],"text":""}],"markDefs":[],"style":"normal"},{"_key":"985bc9ac1b81","_type":"image","asset":{"_id":"image-ef78c74d5be1d51d8c4389bfa0ae9ead34f34046-634x203-png","_type":"sanity.imageAsset","_rev":"DsHc46whJxIpNrcPyMBIfA","_createdAt":"2022-03-10T03:46:29Z","_updatedAt":"2022-03-10T03:46:29Z","assetId":"ef78c74d5be1d51d8c4389bfa0ae9ead34f34046","extension":"png","metadata":{"_type":"sanity.imageMetadata","dimensions":{"_type":"sanity.imageDimensions","aspectRatio":3.123152709359606,"height":203,"width":634},"hasAlpha":true,"isOpaque":true,"lqip":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAGCAYAAADDl76dAAAACXBIWXMAAAsSAAALEgHS3X78AAAAsUlEQVQY032R1w7EIAwE+f/PJIoghZBenvY0SI5yOekeBhuXNcVd16XzPLUsi2KMqutaOecSI/eP4zgKVot1NDdNU4S896qqSl3XaRgGpZTU9/0Ne3jmsNM0aZ5njeMoxxJCKGKATwPFnPgJg6Ft2y+fQ6FDn0OZYhPEp8AEGWC8B8CP4Lqu95WBAktydTsN1vYG++eVEXY8JgEECJDgofd9Lx8FxLAMt5ixbVv5DMD/AII8xl2ow/1zAAAAAElFTkSuQmCC","palette":{"_type":"sanity.imagePalette","darkMuted":{"_type":"sanity.imagePaletteSwatch","background":"#545454","foreground":"#fff","population":1.02,"title":"#fff"},"darkVibrant":{"_type":"sanity.imagePaletteSwatch","background":"#424242","foreground":"#fff","population":0,"title":"#fff"},"dominant":{"_type":"sanity.imagePaletteSwatch","background":"#bcbcbc","foreground":"#000","population":1.17,"title":"#fff"},"lightMuted":{"_type":"sanity.imagePaletteSwatch","background":"#bcbcbc","foreground":"#000","population":1.17,"title":"#fff"},"lightVibrant":{"_type":"sanity.imagePaletteSwatch","background":"#bcbcbc","foreground":"#000","population":0,"title":"#fff"},"muted":{"_type":"sanity.imagePaletteSwatch","background":"#7c7c7c","foreground":"#fff","population":0.63,"title":"#fff"},"vibrant":{"_type":"sanity.imagePaletteSwatch","background":"#7f7f7f","foreground":"#fff","population":0,"title":"#fff"}}},"mimeType":"image/png","originalFilename":"image.png","path":"images/vrx9irrf/production/ef78c74d5be1d51d8c4389bfa0ae9ead34f34046-634x203.png","sha1hash":"ef78c74d5be1d51d8c4389bfa0ae9ead34f34046","size":29007,"uploadId":"QJBzGvHmRY7CToV5AvJ88Sqvcq0BQB3g","url":"https://cdn.sanity.io/images/vrx9irrf/production/ef78c74d5be1d51d8c4389bfa0ae9ead34f34046-634x203.png","id":"image-ef78c74d5be1d51d8c4389bfa0ae9ead34f34046-634x203-png","children":[],"internal":{"type":"SanityImageAsset","contentDigest":"a8af09c25d3a132e0ab87a1cfca34b7f","counter":1232,"owner":"gatsby-source-sanity"},"parent":null}},{"_key":"6647207e33d6","_type":"block","children":[{"_key":"28da4848bc0c","_type":"span","marks":[],"text":"The Provinces are now in the index of the DataFrame, so the code to draw the labels will need small modification."}],"markDefs":[],"style":"normal"},{"_key":"deb43e5d5359","_type":"block","children":[{"_key":"6eb7416e2c00","_type":"span","marks":[],"text":""}],"markDefs":[],"style":"normal"},{"_key":"db89566c66ca","_type":"code","code":"# We will need to generate the coordinates again\r\nplotdata_province['coords'] = plotdata_province['geometry'].apply(lambda x: x.representative_point().coords[:])\r\nplotdata_province['coords'] = [coords[0] for coords in plotdata_province['coords']]\r\n\r\nPALETTE = 'OrRd'\r\n\r\ngplt.choropleth(plotdata_province, hue = plotdata_province['Data'], cmap = PALETTE, figsize = (60,30))\r\n\r\nfor idx, row in plotdata_province.iterrows():\r\n\r\n    hue = round(row['Data'],2)\r\n    plt.text(s=idx, x = row['coords'][0], y = row['coords'][1], # The Province names are now in the index\r\n            horizontalalignment='center', fontdict = {'weight': 'bold', 'size': 8})\r\n\r\n    plt.text(s='Data: ' + f'{hue:,}', x=row['coords'][0],y = row['coords'][1] - 0.01 ,\r\n            horizontalalignment='center', fontdict = {'size': 8})","language":"python"},{"_key":"fe2ded6b1115","_type":"block","children":[{"_key":"f42424884b5e","_type":"span","marks":[],"text":""}],"markDefs":[],"style":"normal"},{"_key":"50dbfd50cb22","_type":"image","asset":{"_id":"image-6e2a429902cc98c25053a02c6d91d1c608e9fc1d-945x881-png","_type":"sanity.imageAsset","_rev":"DmK61VtPyEhMsfOjcmTvV6","_createdAt":"2022-03-10T03:46:30Z","_updatedAt":"2022-03-10T03:46:31Z","assetId":"6e2a429902cc98c25053a02c6d91d1c608e9fc1d","extension":"png","metadata":{"_type":"sanity.imageMetadata","dimensions":{"_type":"sanity.imageDimensions","aspectRatio":1.072644721906924,"height":881,"width":945},"hasAlpha":true,"isOpaque":false,"lqip":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAASCAYAAABb0P4QAAAACXBIWXMAAAsSAAALEgHS3X78AAAEfklEQVQ4y32Ue0xbVRzHT9vBQB5LmDDfm0ac8xF0ooljmWg2RDOg0HY8lhAx8xkziSzCgJUWClExc2yJ2XwmCxLUZItL0LBkTNSMQnmUDugLWih9v3t7++Le3uPv3mrdX97km3Puuef3Od/zPfdehOBKhOxsg0JuM8IYc32fzYj8jlWBx6rn/zT8Lbrz2iKcaGXhFvrfK+gypaEO8zKf9FrujgdtB2GxV+NB+7NR/+a9pHcjN+RaE9gN0yhs0yCPaRakQp41FVf7b4tM2jmEkwTXJ9zrOVD8NIDeoEjXME26fgeNUGFnTyLkaIgGrI94bEYBOxdjiqtZmR5Hdt0djjcMangYTTl0mXeBs3cANsFEPT4QBSKTEbcNoL/F/Jt1vk1tDjvXqlPyXcZpHg6tcbWXzin+A0JRKju7MR+ALeBKA2MMKxzzYibixhRhXYt7V2WEVfOY16Qq8K/P3Q9t7ueKDq4W7lNA3aISRXwWrm8zLWUAsAaAM+CKSYt0JOmgOUx59ZNx10pbzLncAvqAtGvKAxvzBT7zHB8HVyHIM0IOFHYYudauU7HASgBOAogCYRZIEzaGDpiYZMAYpH36RcqnnwW4OuFeuQQHdMhrmt2ezjAkF6HYaD/XX4vFeRD845BXP4C0sNUEu206bGcSbgMTty8xlEdLA5RO+g1JAKujzuVmAHK5Inz2eBpslDXx7IomQVCnzI4HrCUU4eiiSfefTMzrpYLWpEN1ExuuXma86gm85dEmAZgA8BJE8F7QsrCDgyycrECuM8LMkLzuHrJX9BzZJz4Y6hHe59FMZpK+zT0xy+13qfV5Jame2FoYUuArjbWMcrAHB5b+iP2z9fMx1/JhYlOdcnjjrXLkkQqLwr2i+phCfDmmkPwM0BZfT+0eh7y+IPR91+vRH+Q3iW86qKUPxXj0+b3M8CsHsPJsb9Q0/uOYYWykRjc2shMzTj4H/KW5DHmltQXgrhlgU/F+iRvacYD2wSJvhhWSU9GBhpn4QD3taa/CN448xVx4oBBfLH1ma/hoxdTFF0ubWhHKZVlD+4ohw08bkLO7RkD0ivZGFWIZADUgL8gG4MVIn1gFzl1bA8cYQirEt2r2M0NF+VietT2iyM+73pufJ+rMyuKAfTl3wY+hX5L6DqXCbeBoH0A/BtgUjEegpeGeALA/MXAsEpHXJfUnyplrB4rx1w8XEoM7sq9189BxeK2LT/N4OacQ4iFz+1EEhYjsE8HWhazT3eDqBECugv4C4CjoPJttXCFZJ6S1tLW1MjkjfiHy3aO7TDIB/3oXQtJOHippQyiVo7btNQSQ1IvdVc0j5KIiyLAMcq0E1/vZRWDsEMz5AsBzIJXp/cO/AnBaxufZuhG6AtCyVtYhnCYHut1aiSArhAcbkRu+HgDzLaerts2frOBxP4LO6iyYWxqS1TXDYhL92y+/dK4wr0XKQ18C8CMA7k6/0LbOau7HqjjyJArK6hD+pD79DH/WyB2co6uGjSfD0lGVDfDMr0oe4kN2OzsRegL0YDtCGez8vwHckv368SK9MQAAAABJRU5ErkJggg==","palette":{"_type":"sanity.imagePalette","darkMuted":{"_type":"sanity.imagePaletteSwatch","background":"#443c3c","foreground":"#fff","population":0.01,"title":"#fff"},"darkVibrant":{"_type":"sanity.imagePaletteSwatch","background":"#770404","foreground":"#fff","population":3.8,"title":"#fff"},"dominant":{"_type":"sanity.imagePaletteSwatch","background":"#770404","foreground":"#fff","population":3.8,"title":"#fff"},"lightMuted":{"_type":"sanity.imagePaletteSwatch","background":"#c8bca4","foreground":"#000","population":0.01,"title":"#fff"},"lightVibrant":{"_type":"sanity.imagePaletteSwatch","background":"#fca45c","foreground":"#000","population":0,"title":"#fff"},"muted":{"_type":"sanity.imagePaletteSwatch","background":"#a8785d","foreground":"#fff","population":0.04,"title":"#fff"},"vibrant":{"_type":"sanity.imagePaletteSwatch","background":"#ed7634","foreground":"#fff","population":0.01,"title":"#fff"}}},"mimeType":"image/png","originalFilename":"image.png","path":"images/vrx9irrf/production/6e2a429902cc98c25053a02c6d91d1c608e9fc1d-945x881.png","sha1hash":"6e2a429902cc98c25053a02c6d91d1c608e9fc1d","size":98868,"uploadId":"yXR6ltRzsavbjXxm7ul86OtDbXeUqJVX","url":"https://cdn.sanity.io/images/vrx9irrf/production/6e2a429902cc98c25053a02c6d91d1c608e9fc1d-945x881.png","id":"image-6e2a429902cc98c25053a02c6d91d1c608e9fc1d-945x881-png","children":[],"internal":{"type":"SanityImageAsset","contentDigest":"69bafbed0b52c7c215feafff0153d446","counter":1234,"owner":"gatsby-source-sanity"},"parent":null}},{"_key":"dce58004c132","_type":"block","children":[{"_key":"0477442e29dd","_type":"span","marks":[],"text":"Conclusion"}],"markDefs":[],"style":"h1"},{"_key":"2d5bfac4af0c","_type":"block","children":[{"_key":"10e5f607364e0","_type":"span","marks":["strong"],"text":"Geopandas"},{"_key":"10e5f607364e1","_type":"span","marks":[],"text":" and "},{"_key":"10e5f607364e2","_type":"span","marks":["strong"],"text":"Geoplot"},{"_key":"10e5f607364e3","_type":"span","marks":[],"text":" are two very useful Python libraries to visualize geographical data. They require more efforts but also allow much more control over the plot."}],"markDefs":[],"style":"normal"}],"authors":[{"_key":null,"profilePhoto":{"crop":null,"hotspot":null,"asset":{"_id":"image-55fa73787cabef146930d382d551ee4bd90904a9-676x422-jpg"}},"name":"Minh-Anh Nguyen","jobTitle":"Machine Learning Instructor "}]}},"pageContext":{"pageId":"-5babeaa4-1f7a-572d-a7be-bcbbd7bed810","previousPagePath":"blog/10-full-stack-web-developer-skills","previousItem":{"node":{"id":"-627c7d22-9a0b-505c-a9fe-3bc1b2c19a68","title":"Top 10 Skills You Need to Become a Full Stack Web Developer","publishedAt":"2020-11-04T17:00:00.000Z","slug":{"current":"10-full-stack-web-developer-skills"}}},"previousPageId":"-627c7d22-9a0b-505c-a9fe-3bc1b2c19a68","nextPagePath":"blog/bailey-nguyen-ftw-2019","nextItem":{"node":{"id":"-44b6e38f-38c4-592b-80eb-11921cb6252a","title":"Great coders are today's rock stars. That's it.","publishedAt":"2020-11-01T17:00:00.000Z","slug":{"current":"bailey-nguyen-ftw-2019"}}},"nextPageId":"-44b6e38f-38c4-592b-80eb-11921cb6252a","language":"en","intl":{"language":"en","languages":["en","vi"],"messages":{"title":"CoderSchool","apply_now":"Apply Now","about_us":"About Us","course_detail_curriculum_title":"What You'll Learn","course_detail_curriculum_subtitle":"Over twelve weeks, you'll learn a lot. You'll be coding every day, all day. Here we've broken down some of the main concepts you'll be learning. For more information, apply today, and we'll send you a detailed syllabus of all that you'll learn.","course_detail_class_starts":"Next Class Starts ","course_detail_testimonials_title":"CoderSchool helped thousands of graduates change their lives","course_detail_testimonials_subtitle":" ","course_detail_payments_title":"Payment Options","course_detail_payments_subtitle":"Results and Satisfaction are Guaranteed","empty_search":"There's no result which matches your search in this section. Please clear the search terms and try again.","talenthub_title":"TALENT HUB","talenthub_subtitle":"Welcome to CoderSchool Talent Hub where you can find and hire our talents fast and free of charge!","talenthub_portfolio_button":"Portfolio","talenthub_upcoming_events":"UPCOMING EVENTS","talenthub_more":"MORE ABOUT US AND OUR TALENTS","talenthub_send_email":"Send Email","job_page_description":"(At our hiring partners)","job_page_title":"CURRENT JOBS OPENING","events_at_coderschool":"New Events @ CoderSchool","more_info_events":"Register and More Details >>","courses":"Courses","hire_graduates":"Hire Graduates","facebook_and_coderschool":"Facebook & CoderSchool","hear_from_students":"Hear From Our Graduates","youtube_page":"See more stories on CoderSchool's YouTube Channel >>","blog_subtext":"Latest news about CoderSchool and technology","latest_news":"Latest News","categories":"Categories","address":"Sonatus Building 15 Le Thanh Ton, Ben Nghe Ward, District 1, HCMC","instructor":"Instructor","read_more":"Read More","from":"From"},"routed":true,"originalPath":"/blog/plotting-geographical-data","redirect":true,"defaultLanguage":"en"}}},"staticQueryHashes":["1803319088","3802271601","63159454","63159454"]}