How to plot 3D Earth in Python? - python

I'm trying to plot a satellite orbit around the Earth. This is what I currrently have:
I made this plot using the Axes3D function in mpl_toolkits.mplot3d. Ideally what I would like to do, is to replace the simple sphere with an actual Earth with topology.
If you're not sure what I mean, take a look at a MATLAB implementation:
http://uk.mathworks.com/matlabcentral/fileexchange/13823-3d-earth-example
The Basemap package could be of help (especially the bluemarble() function), but unforunately I can't make it work on 3D objects. There is a similar question here, but the answer to that question results in a projection of a 3D sphere on a 2D plot. I want a 3D sphere on a 3D plot, so that I'm able to rotate around it.
Does anybody know of another package/implementation. Or is there a way to make Basemap work with 3D objects?
---EDIT---
Somebody asked the same question, but nobody has answered it yet

I have asked something similar some times ago
PyOpenGL sphere with texture
If I were you I would pick a OpenGL and use a texture of Earth on it just like this one
https://i.stack.imgur.com/ojwD8.jpg
In any case there is my second thread where I needed to make a Mars planet which is basically the same as you want except different texture:
Why my texture is not showing PyOpenGL

Related

Is it an orthogonal projection in the Nearside Perspective?

I'm currently working on world map visualizations. For now, I can use a home-made software for visualizations and point projections (Java), but I would like to upgrade the soft to be able to use a similar tool in Python.
Thus, I wanted to use cartopy with the module PROJ4, not to re-code everything, and use the wonderfull existing libraries.
It perfectly works for the PlateCarree projection, but when I want to use the Nearside Perspective, I observe a small difference between the two methods.
The two following pictures are extracted from the Java software (1) and the cartopy plot (2).
Cartopy (0.17) is used with matplotlib (3.0.2) and proj4 (4.9.1). In both pictures, we are observing at lon=lat=0° and at 400 km.
Here is the first image (Java):
Java visualization
Here is the second one (Cartopy):
Cartopy representation
As one can observe, lands are over-represented in the cartopy plot. Asuming that I want to get exactly the same projection as the one in my Java software (same representation as the "TrueView angles" in Telecom fields), I discovered in the cartopy crs module:
class NearsidePerspective(_Satellite):
"""
Perspective view looking directly down from above a point on the globe.
In this projection, the projected coordinates are x and y measured from
the origin of a plane tangent to the Earth directly below the perspective
point (e.g. a satellite).
"""
So I got this question: which projection is this about? Are the angles kept, which would means that I have an undetected problem? Or is it an orthogonal projection on the tangent plane? In this case, angles are not conserved, and I would need a solution to apply another projection (the correct one in my case). I might use the wrong one...
Thanks for your time,
Lou
I'm not sure if it's an orthogonal projection, but what CartoPy is using is directly from Proj4:
https://proj4.org/operations/projections/nsper.html
I think coordinates in this Nearside Perspective coordinates are Cartesian distances (distances from the origin on a plane), not angles. It sounds like angles are what's being used for your projection. Have you looked at using the Geostationary projection, but with a different satellite height?
https://scitools.org.uk/cartopy/docs/latest/crs/projections.html#geostationary
I can say that in this projection, the coordinates are angles (multiplied by the satellite height). Might be what you're looking for.

Plotting 3D Chessboard/Swiss Cheese Type Patterns in Python

My particular case is that I am trying to make a 3D space-time diagram of a 2D cellular automata. If anybody has any advice/clever ways of representing this visually that would be awesome, but to make the question more general I'll phrase it as...
What is the best way to plot a sort of 3D chessboard or Swiss Cheese type pattern where the white squares are transparent (or vice versa)?
I have looked around and have found ways to plot Imshow type plots on a 3D coordinate system, but it was kind of clunky, slow, and I couldn't get the transparency to work (didn't try masks, but it didn't seem like what I wanted, but I could be wrong).
I have also used a scatter plot where I have a point at (x,y,z) if cell (x,y) is in the active state at time z (also tried the other way around...). This actually managed to render and looked pretty cool, but for the wrong reasons since it was hard to see anything on and was hard to angle properly due to the amount of points on the scatter plots making it lag.
Thanks in advance for any advice.

surfaceplot with matplotlib over points xyz

I'm trying to plot a surface over several points it should look like a deformed sphere.
I used the scatter function and plotted the points, but the surface function is not working (the window is empty).
To plot the surface, I think i need a mesh function. I try ed to mash x,y,z but it was not working. How i can generate the code, to put a surface over my points?.
Thanks for helping me.
I have the points xyz stored in a list. They are describing a deformed sphere and i have to plot somthing like this
(source: iop.org)
This question is hard to answer without any sample code of what you're doing, you might want to edit it to include a working example.
I suppose you are using the mplot3d class, have you checked the examples that are provided online here, here, and here? These to me look like what you're trying to produce.

Aitoff projection, Python

I'm trying to plot my data with the Aitoff Projection using matplotlib
An example is here, but I would like to set xaxis limit and visualize only a portion of the sphere. For instance, what should I use to visualize only latitude between 0 and 90 degrees and longitudes between -90 and 90 degrees?
The Aitoff projection in matplotlib cannot have its limits changed - they are fixed to a global extent (I think it is because it simplifies axis creation).
Of the other tools available to you, neither Basemap nor Cartopy support the Aitoff projection.
Because its fairly easy to do, I just created an Aitoff projection definition in Cartopy, but things did not work smoothly as proj.4 has not got the inverse Aitoff definition.
I'm afraid that, for now, there doesn't appear to be a good solution to this. I'll continue to look at the possibility of doing this with Cartopy, and let you know if I find anything.
HTH

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

Categories