Hello,
I am new to Plotly and i am wondering if there is any way to plot data on a map object such as go.Scattergeo() with projection_type="natural earth". Not scatterpoints or choropleths but on the whole map maybe as a heatmap or contour.
import numpy as np
import pandas as pd
from scipy.interpolate import griddata
#
import json
import geojsoncontour
#
import plotly.graph_objs as go
import matplotlib.pyplot as plt
import matplotlib as mpl
#Read data
data = pd.read_csv('data.txt', header=0, delimiter='\t')
#Create meshgrid for x,y
xi = np.linspace(min(data['x']), max(data['x']), num=100)
yi = np.linspace(min(data['y']), max(data['y']), num=100)
x_grid, y_grid = np.meshgrid(xi,yi)
#Grid data
z_grid = griddata((data['x'],data['y']),data['z'],(x_grid,y_grid),method='cubic')
#Mpl contourf
cs=plt.contourf(x_grid,y_grid,z_grid,cmap=plt.cm.jet)
plt.colorbar(cs)
plt.show()
# Convert matplotlib contourf to geojson
geojson = geojsoncontour.contourf_to_geojson(contourf=cs)
my_geojson = json.loads(geojson)
#Filling array with Z and Id for each geojson spatial object. Z value from contour plot will be stored as title
arr_temp=np.ones([len(my_geojson["features"]),2])
for i in range(0, len(my_geojson["features"])):
my_geojson["features"][i]["id"]=i
arr_temp[i,0]=i
arr_temp[i,1]=my_geojson["features"][i]["properties"]["title"].split("-")[0]
df_contour=pd.DataFrame(arr_temp, columns=["Id","Z"])
fig = go.Figure(go.Choropleth ( locations=df_contour.Id,
z= df_contour.Z,
colorscale="jet",
geojson= my_geojson) )
fig.update_layout(geo = dict(projection = dict(type = 'natural earth')))
fig.show()