Plotting Continuous Data on Scattermapbox

I am having trouble plotting my data on a continuous scale instead of a discrete scale.

my data looks something like this

[Lat, Lon, Datapoints]
[ 12 , 24, 190]
[81, 61, 0]
[ 15, 123, 71]

when I use the color argument, my program ends up displaying only each point on datapoints individually instead of on a scale. Is there any way to fix this, here is my example code


with open('little_tokyo.geojson') as f:
    js = json.load(f)
polygon = shape(js['features'][0]['geometry'])


plot = pd.read_csv('out.csv')
plot= plot[plot['LOCATION START DATE'].notna()]
plot['LOCATION START DATE'] = pd.to_datetime(plot['LOCATION START DATE'])

for all_values in range(len(plot['LOCATION START DATE'])):
    plot.at[all_values, 'LOCATION START DATE'] = all_values



fig = px.scatter_mapbox(plot, lat= plot['LAT'], lon=plot['LON'], color=plot['LOCATION START DATE'],
                        mapbox_style='carto-positron', )

fig.show()

Hi

Have you try the color_continuous_scale and range_color arguments
https://plotly.github.io/plotly.py-docs/generated/plotly.express.scatter_mapbox.html

It doesn’t seem to do anything for me at least.

I modified my code to look like this


fig = px.scatter_mapbox(plot, lat= plot['LAT'], lon=plot['LON'], color=plot['LOCATION START DATE'],
                        mapbox_style='carto-positron', color_continuous_scale=px.colors.sequential.algae, range_color=[0, 600] )

the graph currently looks like this

Figured out the problem.

The Data in the Location Start Date Column was considered an object and not an integer.

1 Like