How to add wind vectors over a density heatmap? - python

I have this density heatmap generated using Python Plotly package:
Now I need to add wind vectors over the heatmap. I would like to use quiver plots if possible, but currently I want to know how to add any kind of plot to a mapbox.
I have only found this example but the source code in the Plotly Chart Studio doesn't load so I don't know how to do it, also I need it in 2D:

I am not 100% sure if it is helpful but there is a software called QGIS (it's free). It is much easier to work with geospatial data there. Also, try rasterio library. It may have some functions like that (library for geospatial analyze)

I once used the velocity capability of ipyleaflet https://ipyleaflet.readthedocs.io/en/latest/api_reference/velocity.html
It is not using plotly but could be a good replacement for this kind of map until you find a better solution.

Related

How to draw a heatmap with grids of different colors in a map?

Recently I have been reading a paper called Modeling Taxi Drivers’ Behaviour for the Next Destination Prediction. There is a figure(Fig.1) that I wonder how to draw. Based on what I know, it may be drawn by Python. Then what library of Python should I use to draw such a heatmap?
Thanks a lot in advance for your time and your expertise.
Best Regards
I have built something very similar for myself in the past. However, as you are just wondering how this would be drawn and not exactly asking how to do it with Python, I will share how I did it.
1. Building Grid:
The grids on the map are squares of X-size latitude and longitude. In short, those are latitude and longitude grids. I used an interactive map library named leaflet.js to build the world map with an overlay of latitude and longitude grids. This is the tutorial I followed from the leaflet: https://leafletjs.com/examples/choropleth/
Remember, you have to and can build your version of the grid to overlay on a world map using GeoJSON as discussed in the tutorial. At least, when I was building, there wasn't a publicly available version of the lat/long square grid.
2. Showing Colors (Heatmap):
Once you build the grid with GeoJSON, the leaflet can take the whole GeoJSON as it is and overlay it on any map of your choice. That means you can put the numbers(aka data) for each grid in the GeoJSON. This part is also shown in the same tutorial.
For my project, I used to create a complete GeoJSON formatted file with normalized data in Python and then visualize it in leaflet.js. Below is an example of what I have built using these tools.

Alternative to plotly scatter_geo for skymap instead of Earth

I'm wanting to create an animated and interactive skymap using plotly, and I like scatter_geo (https://plotly.com/python-api-reference/generated/plotly.express.scatter_geo) but it seems to only allow for the use with the Earth (hence "geo"). I like the functionality in general of scatter_geo, I just need to be able to map it to sky coordinates (because mapping to Earth's lat/long gets annoying with the Earth's rotation) and to be able to have an image of my choosing as the backdrop (I'm wanting to use the Planck image of the MW). Oh, and it needs to be able to do the Mollweide projection.
I'm basically trying to create something like this animation of Fast Radio Bursts (https://vimeo.com/146295242) but with different data and with more interactivity, and I think plotly has the features I need for that - if I can map my sources to the sky, that is!
Does anyone know either how to make scatter_geo do this, or an alternative I can use? I have not yet been able to find one. It doesn't need to be a plotly function, but I would prefer to stick with Python.
Cheers!
...not sure how you create the flashes, but for the rest have a look at EOmaps
It can do all the stuff that .scatter_geo does, it should be able to handle any projection that pyproj can handle and gives you a map in Mollweide projection if you want :-)
... and on top of that you can interact with the map and assign assign any callbacks you like.

Best way to create a 2D Contour Map with Python

I am trying to create a 2D Contour Map in Python that looks like this:
In this case, it is a map of chemical concentration for a number of points on the map. But for the sake of simplicity, we could just say it's elevation.
I am given the map, in this case 562 by 404px. I am given a number of X & Y coordinates with the given value at that point. I am not given enough points to smoothly connect the line, and sometimes very few data points to draw from. It's my understanding that Spline plots should be used to smoothly connect the points.
I see that there are a number of libraries out there for Python which assist in creation of the contour maps similar to this.
Matplotlib's Pyplot Contour looks promising.
Numpy also looks to have some potential
But to me, I don't see a clear winner. I'm not really sure where to start, being new to this programming graphical data such as this.
So my question really is, what's the best library to use? Simpler would be preferred. Any insight you could provide that would help get me started the proper way would be fantastic.
Thank you.
In the numpy example that you show, the author is actually using Matplotlib. While there are several plotting libraries, Matplotlib is the most popular for simple 2D plots like this. I'd probably use that unless there is a compelling reason not to.
A general strategy would be to try to find something that looks like what you want in the Matplotlib example gallery and then modify the source code. Another good source of high quality Matplotlib examples that I like is:
http://astroml.github.com/book_figures/
Numpy is actually a N-dimensional array object, not a plotting package.
You don't need every pixel with data. Simply mask your data array. Matplotlib will automatically plot the area that it can and leave other area blank.
I was having this same question. I found that matplotlib has interpolation which can be used to smoothly connect discrete X-Y points.
See the following docs for what helped me through:
Matplotlib's matplotlib.tri.LinearTriInterpolator docs.
Matplotlib's Contour Plot of Irregularly Spaced Data example
How I used the above resources loading x, y, z points in from a CSV to make a topomap end-to-end

plot shapefile in python

I have a couple shape files that I want to plot some scatterplot data on top of that.
Does anyone have a way to load a shape file then plot it?
I've followed a couple of tutorials, but have not been successful so far.
The shape file, I am trying to use is one of the roads in Pakistan.
Found Here
I downloaded the modules pyshp and shapelib but am open to others!
Helpful tutorial for shapefiles and using basemap to plot maps: http://www.packtpub.com/article/plotting-geographical-data-using-basemap
As much as i love D3, Matplotlib and R, this sounds like you just want create an overlay above a Google Maps chart.
This is easier than you might expect:
https://developers.google.com/maps/documentation/javascript/overlays
Check out Qgis for that purpose.
It has a python console that enables you to treat data in an efficient way.
It also reads and writes .shp-files.

Interactive plotting in Python?

Matlab and Mathematica both have features that allow the user to manipulate the contents of a plot using, say, a slider. For example, if you have a set of 3D data, it is easy to make a small program that lets you view 2D slices of a set of 3D data where the user can slide a slider to move through which slice is displayed. Is there anything in python that allows for this sort of capability without tons of effort? For example, is it possible to do such a thing in matplotlib, or something similar? I
Thanks.
My first thought would be Mayavi, which is great for data visualization, especially in 3D. It relies on VTK. It is included in the Enthought flavoured version of Python, together with Chaco for 2D plotting. To get an idea, look at Travis Vaught's nice screencast in Multidimensional Data Visualization in Python - Mixing Chaco and Mayavi.
It also possible to embed basic interactive functionalities (like slider) to Matplotlib, see matplotlib.widgets and the widget examples.
Finally, you can use rpy (or better, rpy2) and benefit from the R interface.
Have you looked at Vtk? http://www.vtk.org/ One of their demos does exactly what you're asking.
In principle, you can do it by help of MathGL. This is cross-platform GPL library for plotting.
For each mouse clicks you can find the x,y,z position in plot or clicked object and adjust (replot) some other information correspondingly. However you should handle mouse clicks by yourself (for example, using PyQt).
Another option is to use python within the SAGE computation interface/environment, which has the #interact command (see here for specific help on this command)

Categories