draw a population density map for the world in python matplotlib - matplotlib

I have a dictionary of countries (by their 2 letter country code), and the population density of each country.
I'd like to create a map with each country colored according to a color bar of density, with the country boundries drawn.
I've tried using the basemap package, like in this notebook
This piece of code works for the US countries. But I want to do it worldwide.

Related

Folium slider on a geopandas dataframe column values

I have a Folium map with shapefile of towns colored according to the number of people in the town.
I would like to add a slider that let me select only the town in a certain population range.
Is this doable?
Thanks in advance for any advice.
Giacomo
I looked online but I found only example with time values. Such as this: https://github.com/python-visualization/folium/blob/main/examples/TimeSliderChoropleth.ipynb

Coordinates of City Centers from OpenStreetMap via OSMnx?

Is it possible to query OpenStreetMap via the Python library OSMnx to retrieve the (lat,long) coordinates for a city? The documentation seems to suggest attribute data should be accessible but I've not yet seen a pathway to retrieving the coordinates of a city's center. Using the OSMnx geocoder for a city of interest led to a poor result.
You may want to try to work with centroids - It's clearly not the city center in a colloquial definition, but it gives you the the center of the city boundaries:
gdf = ox.geocode_to_gdf('London').centroid
>>> POINT (-0.10942 51.50050
London's city center would be in ... erm ... Woolwich, but you can try "City of London"
gdf = ox.geocode_to_gdf('city of London')
>>> POINT (-0.09244 51.51441)
which gives you a location between Bank and St Paul's in... erm... "Trump Street"
Not what you are looking for I guess for various reasons, but it is the "center".
https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoSeries.centroid.html

How to plot histogram where a country is a bin

I am attempting to plot a histogram where the y-axis should be the count and the x-axis (i.e. the bins) should be composed of all the countries, but I cannot seem to figure out the code.
I have tried following https://datasciencelab.wordpress.com/tag/pandas/ and How to create Histograms in Panda Python Using Specific Rows and Columns in Data Frame, but both of those are for bar graphs and not for histograms.
per_country = df.groupby(['COUNTRY'])[['TOTAL']].sum()
per_country = per_country.sort_values('TOTAL')
per_country.head()
medals_per_country['TOTAL'].plot(kind='hist') # if hist is changed to bar, then it works, but I need a histogram and not a bar graph
The result should be a histogram where the x-axis includes a label for each country and the y-axis is the total for each country. Right now the bins are just based on the 'TOTAL', whereas the y-axis is the number of countries with said 'TOTAL'.
Can someone please point me in the right direction? Thank you!

Vega / vega-lite multi-level / hierachy axes

i have seen view composition techniques like facets etc.
however i am struggling to create a plot that features multiple view cells / subplots for different combinations of dimensions/groups as seen in the image for the x axis. it should be possible to not only do this for year-month-day but also for something as "country, year" and then plotting e.g. some continuous x vs. y scatter as subplot within individual cell for specific country & year.
could you provide an example json for auch a plot, so that i can have multiple groups applied for both x & y axis?
please see following vega spec for what I've tried already. I would like to add a graph on top of it, the colored boxes should be the scales.
https://vega.github.io/editor/#/url/vega/N4KABGBEAkDODGALApgWwIaQFxUQFzwAdYsB6UgN2QHN0A6agSz0QFcAjOxge1IRQyUa6SgBY6AK1jcAdpAA04KAHdGAExbYwogAw7FESCkbV8WgMx6DUQujVrGM6lv0glkWCZnoANrC0A2koQwFDeqMhakGC29o7O8lAUvqyROK4QmVDsjmpawJCOhKx4UQBO6E6RiZCoji41GAAeWgCM+lCweMiEbQC+YH3WIWHoEeXcrDJ5Nck+qVoAZr6wyDU50-mFMsWlOJBIyPAA1uzcLQNDwWChkOFpSchleIzwvgpJKQ-LfmvZuVsiiUoocTmcLoMlABdRTuNToPCYHBBLKgLKGe5RPBlZDVa6GOapfzI-GZArqKIAQQ+kFsOJkezAMlYPh8sy+Liu6LJhTy+wAQjS6cgGVSaYSHq0udybryogBhIXoemMyDU9nzB46aXc8l8qAAESVKoV4o5OClw3ReqiAFFjSLVYqNQsLX1STDSZBsZVYItuGVUIFSSEQ5lvQBPQgPDw+l6LCMKMOGY7IRP7ClW7m05WOgDSaaiwtFYZ11uTUDwUZjdJeL1kSZl4cWjGQPn1kAljabNjsDicW081G8PiiMT78UgZezZUmmxwBSHI4mUzy0-RHkYAC8HgFF153vsqM9Xr4wAB+MDGUx4MA4VQaRBTxL74eHx4nt4+C9gB8sO9XsgJhmH0UKlh61zuhAnruAgvjIMSYAomSXqYvs8DcD4AbdlkkbRlEAb9u8WZQBUVSDoc4zoQiNABhGABMOhTpB0KwoYGBlMciHIaG2ZVvh+w4vApQkZAiyzkGC6QPCiJYjikTrpAIoYWoDxojKSkMk8+QVmJjCshR8Egph2E1C2bYdhSUEyuuhisIQMlqbp6ayku76dk8Lxfj+MmsKgdBNDoAHXvgAC0vn+RGTG2eGDGDgeo5Hp5p7fpeEUBa0wVATe4UIn5dARq0z66S0UluYlH5eWeaV5ZFQU4OlgVQDFhhNPR8VvhVHmftVEDpYVAGNUV1nciNmRjdZYHukAA
There are a number of faceting examples in the Vega-Lite gallery.

How to plot hexagon to represent scores on ArcMap?

I want to plot hexagon to represent each point's scores in different aspects and show it on the map. Each score will be saved in the data table. How to plot them? Or are there any symbol which can has same effect like hexagon?