import plotly.plotly as py
import plotly.graph_objs as go
import pandas as pd
import time
stream_id = "kqo6saq4it"
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_us_cities.csv')
data = go.Scattergeo(
mode='markers',
lon=df['lon'],
lat=df['lat'],
marker=dict(
size=[],
sizeref=3e4,
color='#d3d3d3'
),
stream=dict(token=stream_id)
)
layout = go.Layout(
title='2014 US city population',
geo=dict(
scope='usa',
showlakes=True
)
)
fig = dict(data=[data], layout=layout)
py.plot(fig, filename='usa-pop-stream', auto_open=False)
'https://plot.ly/~etpinard/7339'
s = py.Stream(stream_id)
s.open()
pop = df['pop']
N = len(pop)
i = 0
time.sleep(5)
while i<N:
s.write(dict(type='scattergeo', marker=dict(size=pop[i])))
i += 1
time.sleep(0.08) # (!) plot a point every 80 ms, for smoother plotting
s.close()