Git Product home page Git Product logo

mapz's Introduction


Generic badge Generic badge License: GPL v3 Size GitHub top language GitHub last commit


A repository for containing python code for creating various map plots



Examples

For example, to plot all the worlds harbors/ports:

from mapplot import MapPlot

mymap = MapPlot(style="cyberpunk")
mymap.show_ports()
 



Or to plot all the worlds airports:

from mapplot import MapPlot

mymap = MapPlot(style="cyberpunk")
mymap.show_airports()
 



Or to plot all the worlds urban areas on a dark theme and save the image as a png in the "saved_plots" folder:

from mapplot import MapPlot

mymap = MapPlot(place="Europe", style="dark")
mymap.show_urban_areas()
mymap.save("urban")
 



Plots with diagrams

To plot bar plots on each country (Here with some made up data for some South American countries):

from mapplot import MapPlot
import pandas as pd

mydict = {"BRA": {"Coffee": 3, "Cocoa":4, "Beef":2, "Rubber":1},
          "COL": {"Coffee": 2, "Cocoa":1, "Beef":1, "Rubber":3},
          "PER": {"Coffee": 5, "Cocoa":3, "Beef":2, "Rubber":1},
          "ARG": {"Coffee": 1, "Cocoa":4, "Beef":9, "Rubber":3},
          "VEN": {"Coffee": 1, "Cocoa":4, "Beef":9, "Rubber":3}
          }

df = pd.DataFrame.from_dict(mydict)
mymap = MapPlot(place="South America", style="light", title="South America Exports")
mymap.highlight_countries(country_codes=list(df.columns))    
mymap.add_bar_plots(dataframe=df, width=0.25)
mymap.save()

Plots with networks

To add a network plot to the map, call the "add_country_network()" method from the MapPlot class. The may be defined from various ways, for example from a list of tuples:

    mymap = MapPlot(place="Europe", style="cyberpunk")
    
    country_links = [("DEU", "FRA"), ("FRA", "ESP"), ("DEU", "DNK"),
                     ("DNK", "SWE"), ("DNK", "NOR"), ("DEU", "POL"),
                     ("NOR", "SWE"), ("POL", "LTU"), ("LTU", "LVA"),
                     ("LVA", "EST"), ("EST", "FIN"), ("SWE", "FIN"),
                     ("DEU", "CZE"), ("POL", "CZE"), ("DEU", "AUT"),
                     ("AUT", "CZE"), ("ESP", "PRT"), ("CZE", "SVK"),
                     ("HUN", "AUT"), ("GBR", "IRL"), ("FRA", "BEL"),
                     ("NLD", "BEL"), ("NLD", "DEU"), ("BEL", "DEU"),
                     ("LUX", "DEU"), ("CHE", "DEU"), ("CHE", "FRA"),
                     ("CHE", "AUT"), ("CHE", "ITA"), ("FRA", "ITA"),
                     ("AUT", "ITA"), ("AUT", "SVN"), ("HRV", "SVN"),
                     ("HRV", "SRB"), ("GRC", "ITA"), ("HUN", "ROU"),
                     ("HRV", "HUN"), ("BGR", "ROU"), ("SRB", "ROU"),
                     ("SRB", "BGR"), ("BGR", "GRC"), ("POL", "SVK"),
                     ("HUN", "SVK"), ("HUN", "SRB"), ("POL", "SWE"),
                     ("SWE", "LTU"), ("FRA", "GBR")]   
    
    mymap.add_country_network(link_values=country_links)

Combined Plots

Another example, could be combining a map plot with a networks plot, and also pie plots for each country. See for the following example with some made up data for finnish metal "exports":

from mapplot import MapPlot
import pandas as pd

mydict = {"DEU": {"Metal": 3, "Death Metal":4, "Black Metal":2, "Folk Metal":1},
          "POL": {"Metal": 2, "Death Metal":1, "Black Metal":1, "Folk Metal":3},
          "DNK": {"Metal": 5, "Death Metal":3, "Black Metal":2, "Folk Metal":1},
          "NOR": {"Metal": 1, "Death Metal":4, "Black Metal":9, "Folk Metal":3},
          "ISL": {"Metal": 1, "Death Metal":4, "Black Metal":4, "Folk Metal":8}
          }

df = pd.DataFrame.from_dict(mydict)
mymap = MapPlot(place="Europe", style="cyberpunk", title="Finnish Metal Music Export")
mymap.add_country_network(country="FIN", dataframe=df, directed=True)
mymap.add_pie_charts(dataframe=df)
mymap.save()
 

From which you should be able to produce the following plot:

You should be able to replacate this example with any data you like and for any countries you would like, as long as you follow the dataframe structure in the example.



Notes

Available regions that you can specify in the the "place" parameter when calling "MapPlot" are:

  • Africa
  • Asia
  • Eurasia
  • Europe
  • North America
  • South America
  • Middle East
  • Norway
  • Sweden
  • Denmark

I can add more if anyone requests them.

Available styles that you can specify under the "style" parameter when calling "MapPlot", in the time of writing are:

  • light
  • dark
  • cyberpunk

Some of the geometric country centroids that define the placement of country network nodes have been manually edited for aesthetic reasons (for example, the geometric centroid of Norway is inside Sweden, or the geometric centroid of Portugal is in the Atlantic Ocean) or to better represent the population density (For example, Swedens and Great Britain's node has been moved south). The centroids that have been edited are:

  • Norway
  • Sweden
  • Portugal
  • Great Britain
  • Finland
  • USA

Acknowledgements

Country shapefiles obtained from: https://public.opendatasoft.com/explore/dataset/world-administrative-boundaries/export/

Shapefiles for airports, ports and urban areas were obtained from: https://www.naturalearthdata.com/downloads/

mapz's People

Contributors

agroengaard avatar

Watchers

 avatar

mapz's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.