Reputation: 11
I collected some connection data using the Ookla speedtest app and was looking into display it using plotly.express.scatter_mapbox. While the latitude and longitude data I collected had values with decimals points to about 10 places, when they are plotted they are rounded to 5 decimals and are shifted from where I collected them. Is there a solution to retain the precision of location from my collected data when I use the mapbox?
import pandas as pd
import plotly.express as px
data = pd.read_csv("Vis_temp2.csv")
fig = px.scatter_mapbox(data, lat = "lat", lon = "lon", hover_name = "Date", hover_data = ["download", "download bit", "upload", "upload bit", "Delay"], color = "upload", color_continuous_scale=px.colors.sequential.Rainbow, zoom = 7, height = 500)
fig.update_layout(mapbox_style = "open-street-map")
fig.update_layout(margin = {"r":0,"t":0,"l":0,"b":0})
fig.show()
Upvotes: 1
Views: 956
Reputation: 31226
import pandas as pd
import plotly.express as px
import io
data = pd.read_csv(
io.StringIO(
"""lat,lon,download,download bit,upload,upload bit,Date,ConnType,Delay
42.35017867,-71.10618252,52.37847,86617716.0,60.93106,83969867.0,15-feb-2020,Nr,31
42.35026867,-71.10618252,55.82914,55768734.0,49.94178,59047300.0,15-feb-2020,Nr,36
42.35025867,-71.10618252,74.25154,106000000.0,49.21369,75510325.0,15-feb-2020,Nr,26
42.35046867,-71.10618252,71.77018,77557366.0,64.37738,87413430.0,15-feb-2020,Nr,33
42.35045867,-71.10618252,38.07556,25111332.0,62.24909,63243310.0,15-feb-2020,Nr,28
42.35066867,-71.10618252,72.42865,95201216.0,39.63742,59216794.0,15-feb-2020,Nr,37
42.35016867,-71.10618252,17.95829,22567240.0,52.62537,62168470.0,15-feb-2020,Nr,38
42.35016867,-71.10618252,59.16352,60454576.0,56.31616,61478092.0,15-feb-2020,Nr,28
42.35016867,-71.10618252,51.92858,85851695.0,59.35478,49435750.0,15-feb-2020,Nr,34
42.35016867,-71.10618252,43.97223,71892749.0,44.91126,53637272.0,15-feb-2020,Nr,25
42.35016867,-71.10618252,35.33854,57786126.0,40.21487,57388188.0,15-feb-2020,Nr,30
42.35016867,-71.10618252,45.81104,70747898.0,33.40181,15939326.0,15-feb-2020,Nr,29
42.35016867,-71.10618252,17.92186,21767595.0,3.989344,5601570.0,15-feb-2020,Nr,38
42.35016867,-71.10618252,9.593128,13705626.0,8.222248,13352820.0,15-feb-2020,Nr,38
42.35016867,-71.10618252,7.780232,10658830.0,6.506208,10715328.0,15-feb-2020,Nr,31
42.35016867,-71.10618252,50.20906,46350104.0,6.698232,6668142.0,15-feb-2020,Nr,38
42.35016867,-71.10618252,47.83078,48497332.0,6.589096,11035024.0,15-feb-2020,Nr,37
42.35016867,-71.10618252,16.1776,22692638.0,2.281648,3625518.0,15-feb-2020,Nr,32
42.35016867,-71.10618252,73.1493,80903188.0,3.627792,6178952.0,15-feb-2020,Nr,37"""
)
)
fig = px.scatter_mapbox(
data,
lat="lat",
lon="lon",
hover_name="Date",
hover_data={
"lat":":.10f",
"lon":":.10f",
"download": True,
"download bit": True,
"upload": True,
"upload bit": True,
"Delay": True,
},
color="upload",
color_continuous_scale=px.colors.sequential.Rainbow,
zoom=7,
height=500,
)
fig.update_layout(mapbox_style="open-street-map", mapbox_zoom=16)
fig.update_layout(margin={"r": 0, "t": 0, "l": 0, "b": 0})
fig.update_traces(marker_size=20) # make it visible !
Upvotes: 2