Lines on maps with PlotlyJS

I want to use PlotlyJS to create lines on maps as explained here. I build on the maps example from the PlotlyJS documentation to “translate” the JavaScript code into the Julia/PlotlyJS notation, but the resulting map does not show any lines, but does not produce any errors either. I’m using Julia 1.7.

using PlotlyJS, DataFrames, CSV

nm = tempname()
url = “https://raw.githubusercontent.com/plotly/datasets/c34aaa0b1b3cddad335173cb7bc0181897201ee6/2011_february_aa_flight_paths.csv
download(url, nm)
cord = CSV.read(nm,DataFrame)

data = scattergeo(;locationmode=“USA-states”,
lon = hcat(cord[!,:start_lon], cord[!,:end_lon]),
lat = hcat(cord[!,:start_lat], cord[!,:end_lat]),
mode = “lines”,
line_width = 5,
line_color = “red”,
opacityValue = 2
)

geo = attr(scope=“north america”,
projection_type=“azimuthal equal area”,
showland=true,
landcolor=“rgb(217, 217, 217)”,
subunitwidth=1,
countrywidth=1,
subunitcolor=“rgb(255,255,255)”,
countrycolor=“rgb(255,255,255)”)

layout = Layout(;title=“lines”, showlegend=false, geo=geo)
plot(data, layout)

Hi Leonard, Here is how I would translate that example:

using PlotlyJS, DataFrames, CSV

nm = tempname()
url = "https://raw.githubusercontent.com/plotly/datasets/c34aaa0b1b3cddad335173cb7bc0181897201ee6/2011_february_aa_flight_paths.csv"
download(url, nm)
cord = CSV.read(nm,DataFrame)

M = maximum(cord[:,:cnt])

trace_data = [ scattergeo(;locationmode="USA-states",
    lon = [cord[i,:start_lon], cord[i,:end_lon]],
    lat = [cord[i,:start_lat], cord[i,:end_lat]],
    mode = "lines",
    line_width = 2,
    line_color = "red",
    opacity = cord[i,:cnt]/M
) for i in 1:nrow(cord)];

geo = attr(scope="north america",
    projection_type="azimuthal equal area",
    showland=true,
    landcolor="rgb(243,243,243)",
    countrycolor="rgb(204,204,204)",
    subunitwidth=1,
    countrywidth=1,
)

layout = Layout(;title="Feb. 2011 American Airline flight paths", showlegend=false, geo=geo)
plot(trace_data, layout)
1 Like