我知道我们可以用matplotlib创建简单的三维球体,documentation中包含了这样一个球体的例子.

现在,我们还有一个warp方法作为matplotlib模块的一部分,它的用法示例是here.

将圆柱形图像扭曲到球体.有可能结合这些方法来创建一个三维旋转地球吗?除非我对这个问题的思考方式有点偏离,否则要做到这一点,你必须获取图像的像素数据,然后使用正弦和余弦表达式沿着第一个示例中创建的3D球体表面绘制每个像素.这些柱面 map 的一些例子可以在here页上找到

我知道可以通过mayablender来实现这一点,但我试图在matplotlib范围内实现这一点,因为我想创建这个图,然后能够使用一组数据将地理空间数据绘制到曲面上.

推荐答案

有趣的问题.我试图基本上遵循@Skeletor概述的思路,将图像映射为plot_surface:

import PIL
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D

# load bluemarble with PIL
bm = PIL.Image.open('bluemarble.jpg')
# it's big, so I'll rescale it, convert to array, and divide by 256 to get RGB values that matplotlib accept 
bm = np.array(bm.resize([d/5 for d in bm.size]))/256.

# coordinates of the image - don't know if this is entirely accurate, but probably close
lons = np.linspace(-180, 180, bm.shape[1]) * np.pi/180 
lats = np.linspace(-90, 90, bm.shape[0])[::-1] * np.pi/180 

# repeat code from one of the examples linked to in the question, except for specifying facecolors:
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

x = np.outer(np.cos(lons), np.cos(lats)).T
y = np.outer(np.sin(lons), np.cos(lats)).T
z = np.outer(np.ones(np.size(lons)), np.sin(lats)).T
ax.plot_surface(x, y, z, rstride=4, cstride=4, facecolors = bm)

plt.show()

结果:

Python-3.x相关问答推荐

在numpy. linalg的qr之后使用scipy. integrate中的solve_ivp时出现了一个奇怪的错误

在Python中从mySQL获取多行

将strid()映射到Pandas DataFrame中的字符串不会更改NaN条目,但仍然声称它们不同?

将字符串转换为python日期时间时出错

我想判断df_entry_log[AM_PM],并根据测试填充列

我不能使用拆分来分隔数据

Pandas 根据条件增加Dataframe列

根据第一个字典的值序列对第二个字典进行排序

基于Pandas列动态创建分箱,以使观测值数量或计数占总计数的1%.

类不继承时 super() 的用途

如何在不使用循环的情况下根据另一个数组的索引值将 numpy 数组中不同通道的值设置为零?

在python中将字符串写入文本文件

如何在 on_ready 事件中使用 change_presence? (discord.py)

使用带有多线程的 win32com

django.core.exceptions.ImproperlyConfigured

Generic[T] 基类 - 如何从实例中获取 T 的类型?

为什么 virtualenv 会有效地禁用 Python 3 制表符补全?

Python中的多行日志(log)记录

定义 True,如果没有定义,会导致语法错误

如何模拟 open(...).write() 而不会出现没有这样的文件或目录错误?