In this recipe, we will see how to visualize a map and place a bubble on each country, in this case some European countries. The size of each bubble will be proportional to the number of total reported crimes in that country.
Here we will again use the crim_gen.tsv
file, which comes with this book, assuming that this file is in the same directory as the code using it.
For the following recipe, we will proceed as follows:
Import and query the data.
Define the coordinates of each country.
Create an entry for each country.
Define the layout for the chart.
Invoke
plotly
.import plotly.plotly as py from plotly.graph_objs import * import pandas as pd crimes = pd.read_csv('crim_gen.tsv', sep=',|\t', na_values=': ') crimes = crimes[crimes.country.isin(['IT','ES','DE','FR','NO','FI'])] total_crimes = crimes.query('iccs == "TOTAL"')[['country', '2012 ']].sort(columns='2012 ').values coords = {'IT': (13.007813, 42.553080), 'ES': (-3.867188, 39.909736...