Visualizing maps and bubbles

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.

Getting ready

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.

How to do it...

For the following recipe, we will proceed as follows:

  1. Import and query the data.
  2. Define the coordinates of each country.
  3. Create an entry for each country.
  4. Define the layout for the chart.
  5. 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=': ...

Get Python Data Visualization Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.