I'm developing a dashboard application using dash/plotly in Python.
I need to build a map with more than 1000 traces. Because of performance issues, I'm trying to use one single Scattergeo object, but, ordinarily, it does not provide a way to plot each "trace" with a different color.
I would like that each trace contains a different color. For markers
, each one can have a single color, but using lines
is not possible.
The picture below illustrates what I said above.
Is there any workaround that I could use to solve this plotly issue?
I send a reproducible code below.
Thank you in advance.
Reproducible code:
##################################################
# plotly
##################################################
# Source: https://plotly.com/python/lines-on-maps/
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Scattergeo(
lat = [
40.7127, 51.5072, None,
30.7127, 41.5072, None,
20.7127, 31.5072
],
lon = [
-74.0059, 0.1275, None,
-64.0059, -10.1275, None,
-54.0059, -20.1275
],
mode = 'lines',
line = dict(
width=4,
color = 'blue',
# I would like something like this:
# color = [
# 'red',
# None,
# 'yellow',
# None,
# 'green'
# ],
),
))
fig.add_trace(go.Scattergeo(
lat = [
40.7127,
30.7127,
20.7127
],
lon = [
-74.0059,
-64.0059,
-54.0059,
],
mode = 'markers',
marker = dict(
size = 10,
color = ['red', 'yellow', 'green'],
line = dict(
width = 3,
color = 'rgba(68, 68, 68, 0)'
),
)
))
fig.update_layout(
title_text = 'Traces',
showlegend = False,
geo = dict(
resolution = 50,
showland = True,
showlakes = True,
landcolor = 'rgb(204, 204, 204)',
countrycolor = 'rgb(204, 204, 204)',
lakecolor = 'rgb(255, 255, 255)',
projection_type = "equirectangular",
coastlinewidth = 2,
lataxis = dict(
range = [0, 70],
showgrid = True,
dtick = 10
),
lonaxis = dict(
range = [-100, 20],
showgrid = True,
dtick = 20
),
)
)
##################################################
# dash
##################################################
import dash
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash()
app.layout = html.Div([
dcc.Graph(figure=fig)
])
app.run_server(debug=True, use_reloader=True)