使用Matplotlib3D线框创建海面图

时间:2017-03-21 10:21:27

标签: python matplotlib plot

我想创建一个类似于https://www.shutterstock.com/de/image-vector/vector-abstract-3d-wave-wireframe-surrounding-445020520的图表 我使用不同背景的线框演示(最好的情况是蓝色渐变):

from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from matplotlib import cm

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d', axisbg='blue')

# Grab some test data, e.g.gcreate noisy sea surface data
X, Y, Z = axes3d.get_test_data(0.05)

# Plot a basic white wireframe for the surface
ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10, color='white')

plt.show()

你会采取什么措施使这更像一个例子?

Cheers Bene

1 个答案:

答案 0 :(得分:0)

这是一个(众多)选项中的一个。在线框背景中使用曲面图可以为图形添加一些阴影,使其看起来更像图片。

enter image description here

import numpy as np
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d', facecolor='#1a5a98')
plt.subplots_adjust(0,0,1,1)
fig.patch.set_color('#1a5a98')

#Generate some data
x = np.linspace(0,500,501)/(9*np.pi)
X,Y = np.meshgrid(x,x)
f = lambda x,y: np.sin(x+y**0.2)*np.cos(y-x**0.4)
Z = f(X,Y)

# plot surface, for nice shading
ax.plot_surface(X, Y, Z, rstride=10, cstride=10)
# plot wireframe for white lines on top
ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10, color='white', linewidth=0.5)
#set axis off
ax.axis("off")
ax.set_xlim(6.42,11.17)
ax.set_ylim(6.42,11.17)
ax.set_zlim(-6,6)
ax.view_init(elev=25, azim=-88)
plt.show()