3

Thank you in advance for all your answers.

I am trying to plot a dataframe over an interactive map (OpenStreetMap), and what I get is what is in the picture, but I would like the map outlines to be on top of my data and not the data to be like a blob over the map. My code is:

import plotly.express as px
import numpy as np
from plotly.offline import plot

fig = px.scatter_mapbox(df, lat="lat", lon="lon",
                        color="hot days", zoom=4,
                        color_continuous_scale=px.colors.cyclical.Twilight,
                        mapbox_style='open-street-map')

plot(fig, auto_open=True)

And the result I get is this:

OpenStreetMap

Freddy Mcloughlan
  • 4,129
  • 1
  • 13
  • 29
userpython
  • 33
  • 5

1 Answers1

2

The issue is likely the structure of your DataFrame. It appears that "no data" areas are getting mapped to zero or something similar, and the DF including a record for every point on the map - including the null / zero data bits you're not interested in plotting. Try filtering out the records with zero data. Something like

df = df[df['hot days']>0]

Check one or two of the points in the ocean or other no-data areas to confirm they're at 0, and set the threshold accordingly. If they're null instead, try

df = df[df['hot days'].notna()]
Sarah Messer
  • 3,592
  • 1
  • 26
  • 43
  • Hi! Thank you very much for your suggestion it did indeed work and eliminated the points where there is no date. Can you tell me if it is possible to group the colorbar by categories of: 0-2; 2-4; 6-8? – userpython May 26 '22 at 12:55
  • 1
    @userpython You can create a custom scale with the instructions here: https://plotly.com/python/colorscales/ Scroll to the "Constructing a Discrete or Discontinuous Color Scale" section. – Sarah Messer May 26 '22 at 13:19