I recently came to realize that I do not know how to create a 3D Earth in a Matplotlib plot. After a great deal of googling around, I found and rejecting the following common options:
Faced with the lack of available options for adding a 3D Earth to a Matplotlib plot, I decided to roll my own.
My approach was relatively simple. I created a meshgrid of latitude and longitude coordinates. From there I created functions which would accept latitude and/or longitude, then produce an x-coordinate, y-coordinate, z-coordinate, or an RGB tuple for the facecolors
parameter of Matplotlib's plot_surface
method.
Colors were created by sampling an equirectangular projection of Earth created from the beautiful "Blue Marble" data set.
Blue Marble. MODIS image captured by NASA’s Terra satellite. Credit: NASA Goddard Space Flight Center Image by Reto Stöckli (land surface, shallow water, clouds). Enhancements by Robert Simmon (ocean color, compositing, 3D globes, animation). Data and technical support: MODIS Land Group; MODIS Science Data Support Team; MODIS Atmosphere Group; MODIS Ocean Group Additional data: USGS EROS Data Center (topography); USGS Terrestrial Remote Sensing Flagstaff Field Center (Antarctica); Defense Meteorological Satellite Program (city lights). link
I'll admit to spending a total of about 12 hours in my evenings refining this project. The final result...
Humiliation. Disaster. Defeat.
People very rarely put their failures on display. They prefer to only show their successes, so they can cultivate the impression that they are competent, skillfull, and knowledgeable. I see presentations, tutorials, blog posts, and documentation every day and I have to remind myself that behind the successes are many failures and dead ends.
My own failure on this project was a bummer, but these kinds of failures no longer upset me. In years past, I've definitely shared choice words with my computer, but as I get older I find my emotions much more level. I've come to realize that good days and bad days come and go. This was definitely a bad day, but I've learned some limitations of Matplotlib and I'll move on a wiser man for my efforts. In the future I will continue this work anew by experimenting with pyvista or possibly VTK. I'm certainly richer for the experience.
In writing this blog, my goal has been to share knowledge. Today's knowledge is not some algorithm or programming trick, but a slightly more honest view into the life of a more typical professional.
So today I present to you: Failure. It is a thing that every professional will experience many times.
I can't help but laugh at the sound of my computer rendering this.😂