Skip to content

Instantly share code, notes, and snippets.

@dsibi
Created June 2, 2020 12:50
Show Gist options
  • Save dsibi/88838f847d0a68d52a05fb216a50b7bb to your computer and use it in GitHub Desktop.
Save dsibi/88838f847d0a68d52a05fb216a50b7bb to your computer and use it in GitHub Desktop.
Meteors
#In the code below I tried to use customdata to make hovertemplate, but in this case on visualization it shows only data from the first row everywhere. I believe there should be function, but don't know how to implement it.
import plotly.express as px
import plotly.graph_objs as go
import pandas as pd
rows=[['501-600','15','122.58333','45.36667','slategray'],
['till 500','4','12.5','27.5','teal'],
['more 1001','41','-115.53333','38.08','whitesmoke'],
]
colmns=['bins','data','longitude','latitude','color']
df=pd.DataFrame(data=rows, columns=colmns)
df = df.astype({"data": int})
# df['colors'] = pd.cut(df['bins'], ['501-600', 'till 500', 'more 1001', 1950, 2100],
# labels=['till 1810', '1811-1880', '1881-1950', 'more than 1950'])
# fig=px.scatter_geo(df,lon='longitude', lat='latitude',
# color='bins',
# opacity=0.5,
# size='data',
# projection="natural earth")
#
# new_customdata = df.loc[:,('bins', 'data')]
# fig.update_traces(go.Scattergeo(
# customdata=new_customdata,
# hovertemplate="<b>%{customdata[0]} </b><br><br>" + \
# "blablabla: %{customdata[1]: .3f}<extra></extra>"))
fig = go.Figure(data=go.Scattergeo(
lon = df['longitude'],
lat = df['latitude'],
mode = 'markers',
marker_size=df['data'],
marker=dict(
# size=df_sub['pop'] / scale,
color=df['color'],
line_color='rgb(40,40,40)',
line_width=0.5,
sizemode='area'
),
customdata = df,
hovertemplate="<b>%{customdata[0]} </b><br><br>blablabla: %{customdata[1]: .3f}<extra></extra>"
))
fig.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment