plotly / plotly.py

The interactive graphing library for Python :sparkles: This project now includes Plotly Express!
https://plotly.com/python/
MIT License
15.78k stars 2.52k forks source link

Figure factory: Plot a scalar field with geographical coordinates on map with projection #715

Open ghost opened 7 years ago

ghost commented 7 years ago

I have an array of global temperatures and associated longitude and latitude coordinates arrays. I would like to plot the temperatures as a heatmap on a map with custom projection and showing coastlines. A working code example using matplotlib is:

import matplotlib.pyplot as plt
import cartopy.crs as ccrs

f, ax = plt.subplots(subplot_kw={'projection': ccrs.Robinson()})
p = ax.pcolormesh(longitude, latitude, temperature, cmap='RdBu_r', transform=ccrs.PlateCarree())
ax.coastlines()
f.colorbar(p, orientation='horizontal')

The output figure from code block above is (data available here): map

At the moment I was only able to use plotly for a simple heatmap with the following code:

from plotly.offline import iplot
import plotly.graph_objs as go

layout = go.Layout(geo={'projection': {'type': 'robinson'}})
data = go.Heatmap(x=longitude, y=latitude, z=temperature)

fig = go.Figure(data=[data], layout=layout)
iplot(fig)

As next figure shows, main issues are:

Balinus commented 6 years ago

Would also love something similar!

empet commented 6 years ago

You can plot both heatmap and contour plots on maps. Take a look here: https://plot.ly/~Dreamshot/9147 or visit this user (Dreamshot) Plotly profile for more examples.

Balinus commented 6 years ago

Thanks! Will take a look :)

Balinus commented 6 years ago

Although it does not seem to support mapping per se. I mean, the data are on a lat-lon coordinates, but what if we want to change the projection? I don't see a proper support for maps right out of the box (or at least without creating a unique map for each use case).

JiaweiZhuang commented 6 years ago

This blog should help: How to Create 2D and 3D Interactive Weather Maps in Python and R

jonmmease commented 5 years ago

A geographic heatmap figure factory would be really nice!

zxdawn commented 2 years ago

How about the progress here? It seems geoviews supports this function, but that's sometimes slow. Similar question is on the forum.

pedroaugustosmribeiro commented 1 year ago

I also would like to plot any scallar (numpy array, xarray, etc) with a projeceted basemap in plotly just like is done on matplolib+cartopy integration

Balinus commented 1 year ago

I am currently using GeoMakie.jl (https://github.com/MakieOrg/GeoMakie.jl). Works really well!

pedroaugustosmribeiro commented 1 year ago

I am currently using GeoMakie.jl (https://github.com/MakieOrg/GeoMakie.jl). Works really well!

Nice, however it's in Julia. Is it possible to mix it inside a Python Plotly Dash app?

Balinus commented 1 year ago

I am currently using GeoMakie.jl (https://github.com/MakieOrg/GeoMakie.jl). Works really well!

Nice, however it's in Julia. Is it possible to mix it inside a Python Plotly Dash app?

Not sure. Using Python inside Julia is easy, the other way around is more difficult in my experience. This is actually the reason why I use Julia : this gives me access to Julia and 100% of Python's ecosystem.

g-voelker commented 1 year ago

Of course, there are other methods out there, for Python cartopy stays the library of choice when it comes to map-based plots. A speedy and interactive data visualization tool stays, however, a rare feat.

I support the request for the feature and think it would make a good unique selling point for plotly in the geosciences and adjacent communities.

g-voelker commented 1 year ago

A quick side remark: All scripts implementing the requested functionality (see above in the thread) depend on basemap which has reached EoL and names cartopy as a recommended replacement. Thus there is currently no example of an efficient geospatial data representation in plotly.

I will no further bump this thread, but I'd like to stress that I would really like the feature and hope that it isn't just me.