Alternative to plotly scatter_geo for skymap instead of Earth - python

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.

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.

Simple 3D Graphics in Python

I am working in a project where 3D visualizations are important to see what is happening during the setup stage and perhaps for visual validation by making a short videos of what is happening.
The problem that I have is that 3D visualizations in Python are too sophisticated, and complicated to learn for what I need. I find that Mathematica is the perfect kind of software...but it is not portable and is very expensive.
Question
Is there any Python package similar to Mathematica?
Clarification
I don't want a "plotting" program, since plotting is not what I am looking for. I want to generate simple geometric shapes like spheres and cubes that can move around, this is more than enough. Give some coordinates, perhaps a rotation, and the program just shows the desired image(s) to export as a .png or make a quick video; as in Mathematica.
Packages like Pygame, Panda3D, Pyglet, etc., look too complicated and an overkill for what I need, as well as software like Blender, etc. Jupyter notebooks are similar, but they don't have the 3D graphics capabilities. I found a Python module named Fresnel, but it looks too sophisticated for what I need.
I have read several answers to this question here in Stack Overflow, but they seem outdated and not really what I am looking for.
Further Clarification
To draw spheres in Mathematica you do:
coordinates = Flatten[Table[Table[Table[ {i,j,k}, {k,1,10}], {j,1,10}], {i,1,10}],1]
spheres= Flatten[Table[Graphics3D[{Sphere[coordinates[[i]],0.5]}],{i,1,Length[coordinates]}]]
Show[{spheres}]
This is a simple quick and easy way of displaying a group of spheres. To use any program in Python to do the same, it seems like you must be an expert in 3D graphics to do this simple thing.
Programs that have capabilities of using Python scripts, like Blender, make it difficult to use the interface in a straight forward way (try doing the same in Blender, it will take a while just to learn the basics!).
I know several other user-friendly plotting libraries than matplotlib, but not a lot provide an interactive view. There is of course the well known vtk but it's not for end-user
plotly
For usage in a notebook, like jupyter and mathematica, you probably would go for plotly It's using a browser-based interface with plots very similar to mathematica
pymadcad
If you need a more offline version and what you are looking for is some view you can rotate/zoom/pan to look on your geometry by different sides, you can take a look at pymadcad
It even works with touchscreens.
It is not centered on 3D visualization, so it's a bit overkill to use it only for it, but for 3D curves, 3D surfaces, spheres and cubes as you said, it can do the job
simple plots with pymadcad:
from madcad import *
from madcad.rendering import Displayable
from madcad.displays import GridDisplay
# create a wire from custom points
s = 100
mycurve = Wire([ vec3(sin(t/s), cos(t/s), 0.1*t/s)
for t in range(int(s*6*pi)) ])
# create a sphere
mysphere = uvsphere(vec3(0), 0.5)
# display in a separated window
show([
mycurve, # displaying the curve
mysphere, # displaying the sphere
Displayable(GridDisplay, vec3(0)), # this is to have a 2D grid centered on origin
])
result:
(The window is dark because so is my system theme, but likely it will adapt to yours)

How to add wind vectors over a density heatmap?

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.

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

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