设置球体坐标
Setting coordinates for sphere
我有一个生成球体的代码。我想更改球体生成的坐标
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
from matplotlib import cm
from matplotlib import animation
import pandas as pd
fig = plt.figure(facecolor='black')
ax = plt.axes(projection = "3d")
u = np.linspace(0, 2*np.pi, 100)
v = np.linspace(0, np.pi, 100)
r = 10
ax.set_xlim(0, 60)
ax.set_ylim(0, 60)
ax.set_zlim(0, 60)
x = r * np.outer(np.cos(u), np.sin(v))
y = r * np.outer(np.sin(u), np.sin(v))
z = r * np.outer(np.ones(np.size(u)), np.cos(v))
def init():
ax.plot_surface(x,y,z)
return fig,
def animate(i):
ax.view_init(elev = 20, azim = i*4)
ani = animation. FuncAnimation(fig, animate, init_func = init, frames = 90, interval = 299)
plt.show()
例如,我希望在坐标 (10,10,10) 中绘制球体
简单,只是 x, y, z
的一个偏移量,像这样:
x = r * np.outer(np.cos(u), np.sin(v)) + 10
y = r * np.outer(np.sin(u), np.sin(v)) + 10
z = r * np.outer(np.ones(np.size(u)), np.cos(v)) + 10
我有一个生成球体的代码。我想更改球体生成的坐标
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
from matplotlib import cm
from matplotlib import animation
import pandas as pd
fig = plt.figure(facecolor='black')
ax = plt.axes(projection = "3d")
u = np.linspace(0, 2*np.pi, 100)
v = np.linspace(0, np.pi, 100)
r = 10
ax.set_xlim(0, 60)
ax.set_ylim(0, 60)
ax.set_zlim(0, 60)
x = r * np.outer(np.cos(u), np.sin(v))
y = r * np.outer(np.sin(u), np.sin(v))
z = r * np.outer(np.ones(np.size(u)), np.cos(v))
def init():
ax.plot_surface(x,y,z)
return fig,
def animate(i):
ax.view_init(elev = 20, azim = i*4)
ani = animation. FuncAnimation(fig, animate, init_func = init, frames = 90, interval = 299)
plt.show()
例如,我希望在坐标 (10,10,10) 中绘制球体
简单,只是 x, y, z
的一个偏移量,像这样:
x = r * np.outer(np.cos(u), np.sin(v)) + 10
y = r * np.outer(np.sin(u), np.sin(v)) + 10
z = r * np.outer(np.ones(np.size(u)), np.cos(v)) + 10