Setup¶

In [111]:
# pip install -e "git+https://github.com/redivis/redipy.git#egg=redivis-bigquery&subdirectory=bigquery"
# pip install python-dotenv
# conda install basemap
# conda install -c conda-forge basemap-data-hires
# import sys
# !{sys.executable} -m pip install plotly
In [112]:
%reload_ext dotenv
In [113]:
# IMPORTANT: we've stored our REDIVIS_API_TOKEN in our .env file. This is necessary in order to make Redivis API calls
%dotenv
In [114]:
from redivis import bigquery
import numpy as np
import matplotlib.pyplot as plt
import plotly.express as px
from mpl_toolkits.basemap import Basemap
In [115]:
client = bigquery.Client()

Fetch data from Redivis¶

In [116]:
# Fetch our data
QUERY = ('''
   SELECT * FROM `anjsant.visualization_data:15.unemployment_2008_visualization_output:11`
''')

df = client.query(QUERY).to_dataframe()  # API request

Make a choropleth map¶

In [117]:
# See https://plotly.com/python/choropleth-maps/
fig = px.choropleth(df,
                    locations='state',
                    locationmode="USA-states",
                    color='unemployment_rate',
                    color_continuous_scale=['pink','purple'],
                    scope="usa")
fig.show()