Weather scattergeo forecasts map help

Hello,

I’ve recently started working with Python and I’m really excited to have found Plotly.

I’m working on a small project in which I’m collecting weather forecast data and I’d like to plot each days forecast on a map. To begin, my data sits in a csv file with the following columns:

AirportCode, Location2, Lat, Lon, validDate, AVG, ANOM
KNYC,New York City, xx.xxx, yy.yyy, 2018-08-01, 72, -2
KNYC,New York City, xx.xxx, yy.yyy, 2018-08-02, 74, 1
KNYC,New York City, xx.xxx, yy.yyy, 2018-08-03, 78, 3
…
KPDX, Portland, xx.xxx, yy.yyy, 2018-08-01, 85,2
KPDX, Portland, xx.xxx, yy.yyy, 2018-08-02, 92,-2
KPDX, Portland, xx.xxx, yy.yyy, 2018-08-03, 87, -1

where Lat = Latitude, Lon = longitude, validDate = the forecast date (10 days for each city), AVG = average forecasted temperature and ANOM = deviation from normal.

So far I have been able to produce maps using plotly.express and plotly.graph_objects. Both seem to get me 90% percent of the way but in different ways.

For example with plotly.express, using the following code I get a map with a slider/animation (yes!) using the AVG field however what I would really like to see is the deviation from normal (ANOM) but I get the error that the size property contains invalid elements (all the negative anomaly’s).

import plotly.express as px
import pandas as pd

df = pd.read_csv(r’/Users/myname/Downloads/Plotly/CITY_IMPORT_MAP.csv’)

fig = px.scatter_geo(df,
lat = ā€˜Lat’,
lon = ā€˜Lon’,
color = ā€˜ANOM’,
#color_continuous_scale = ā€˜rdbu’,
color_continuous_scale=px.colors.diverging.RdBu[::-1],
hover_name= ā€˜Location2’,
size = ā€˜ANOM’,
size_max = 10,
animation_frame = ā€˜validDate’,
title = ā€˜Temperature Anomaly’s’,
projection = ā€˜albers usa’)

fig.show()

When I use plotly.graph_objects I can get a map with all the cities plotted using the ANOM field (yes!) however I don’t know how to add a slider to animate/scroll through each of the forecast dates (validDate). My code for this looks like the following

import plotly.graph_objects as go
import pandas as pd

df = pd.read_csv(r’/Users/myname/Downloads/Plotly/CITY_IMPORT_MAP.csv’)

df[ā€˜text’] = df[ā€˜Location2’] + ’ ’ + df[ā€˜ANOM’].astype(str)

fig = go.Figure(data=go.Scattergeo(
locationmode = ā€˜USA-states’,
lon = df[ā€˜Lon’],
lat = df[ā€˜Lat’],
text = df[ā€˜text’],
mode = ā€˜markers’,
marker = dict(
size = 10,
opacity = 0.8,
reversescale = True,
autocolorscale = False,
symbol = ā€˜circle’,
line = dict(
width=1,
color=ā€˜rgba(102, 102, 102)’
),
colorscale = ā€˜RdBu’,
cmin = -13,
color = df[ā€˜ANOM’],
cmax = 13,
colorbar_title=ā€œTemp Anomā€
)))

fig.update_layout(
title = ā€˜L48 Temp Anom
(Hover for airport names)’,
geo = dict(
scope=ā€˜usa’,
projection_type=ā€˜albers usa’,
showland = True,
landcolor = ā€œrgb(250, 250, 250)ā€,
subunitcolor = ā€œrgb(217, 217, 217)ā€,
countrycolor = ā€œrgb(217, 217, 217)ā€,
countrywidth = 0.5,
subunitwidth = 0.5
),
)
fig.show()

Is there anyway to use anomaly’s using express or to animate my plot that uses graph_objects?

I don’t want to get ahead of myself but if I can one of these options to work then the next item to tackle is to either export to a gif or make my plot publicly accessible.

Thanks for reading!

bump…can anyone provide any help or direction please?