Ví dụ mã dưới đây cung cấp một cách để mở rộng từng trục so với các trục khác. Tuy nhiên, để làm như vậy, bạn cần sửa đổi chức năng Axes3D.Get_Proj. Dưới đây là một ví dụ dựa trên ví dụ được cung cấp bởi matplot lib: http://matplotlib.org/1.4.0/mpl_toolkits/mplot3d/tutorial.html#line-plots (Có một phiên bản ngắn hơn ở cuối câu trả lời này) from mpl_toolkits.mplot3d.axes3d import Axes3D
from mpl_toolkits.mplot3d import proj3d
import matplotlib as mpl
import numpy as np
import matplotlib.pyplot as plt
#Make sure these are floating point values:
scale_x = 1.0
scale_y = 2.0
scale_z = 3.0
#Axes are scaled down to fit in scene
max_scale=max(scale_x, scale_y, scale_z)
scale_x=scale_x/max_scale
scale_y=scale_y/max_scale
scale_z=scale_z/max_scale
#Create scaling matrix
scale = np.array([[scale_x,0,0,0],
[0,scale_y,0,0],
[0,0,scale_z,0],
[0,0,0,1]])
print scale
def get_proj_scale(self):
"""
Create the projection matrix from the current viewing position.
elev stores the elevation angle in the z plane
azim stores the azimuth angle in the x,y plane
dist is the distance of the eye viewing point from the object
point.
"""
relev, razim = np.pi * self.elev/180, np.pi * self.azim/180
xmin, xmax = self.get_xlim3d()
ymin, ymax = self.get_ylim3d()
zmin, zmax = self.get_zlim3d()
# transform to uniform world coordinates 0-1.0,0-1.0,0-1.0
worldM = proj3d.world_transformation(
xmin, xmax,
ymin, ymax,
zmin, zmax)
# look into the middle of the new coordinates
R = np.array([0.5, 0.5, 0.5])
xp = R[0] + np.cos(razim) * np.cos(relev) * self.dist
yp = R[1] + np.sin(razim) * np.cos(relev) * self.dist
zp = R[2] + np.sin(relev) * self.dist
E = np.array((xp, yp, zp))
self.eye = E
self.vvec = R - E
self.vvec = self.vvec / proj3d.mod(self.vvec)
if abs(relev) > np.pi/2:
# upside down
V = np.array((0, 0, -1))
else:
V = np.array((0, 0, 1))
zfront, zback = -self.dist, self.dist
viewM = proj3d.view_transformation(E, R, V)
perspM = proj3d.persp_transformation(zfront, zback)
M0 = np.dot(viewM, worldM)
M = np.dot(perspM, M0)
return np.dot(M, scale);
Axes3D.get_proj=get_proj_scale
"""
You need to include all the code above.
From here on you should be able to plot as usual.
"""
mpl.rcParams['legend.fontsize'] = 10
fig = plt.figure(figsize=(5,5))
ax = fig.gca(projection='3d')
theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
z = np.linspace(-2, 2, 100)
r = z**2 + 1
x = r * np.sin(theta)
y = r * np.cos(theta)
ax.plot(x, y, z, label='parametric curve')
ax.legend()
plt.show()
Sản lượng tiêu chuẩn: Được chia tỷ lệ bởi (1, 2, 3): Được chia tỷ lệ bởi (1, 1, 3): Lý do tôi đặc biệt thích phương pháp này, hoán đổi z và x, tỷ lệ theo (3, 1, 1): Dưới đây là phiên bản ngắn hơn của mã. from mpl_toolkits.mplot3d.axes3d import Axes3D
from mpl_toolkits.mplot3d import proj3d
import matplotlib as mpl
import numpy as np
import matplotlib.pyplot as plt
mpl.rcParams['legend.fontsize'] = 10
fig = plt.figure(figsize=(5,5))
ax = fig.gca(projection='3d')
theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
z = np.linspace(-2, 2, 100)
r = z**2 + 1
x = r * np.sin(theta)
y = r * np.cos(theta)
"""
Scaling is done from here...
"""
x_scale=1
y_scale=1
z_scale=2
scale=np.diag([x_scale, y_scale, z_scale, 1.0])
scale=scale*(1.0/scale.max())
scale[3,3]=1.0
def short_proj():
return np.dot(Axes3D.get_proj(ax), scale)
ax.get_proj=short_proj
"""
to here
"""
ax.plot(z, y, x, label='parametric curve')
ax.legend()
plt.show()
Làm thế nào để bạn làm cho một cốt truyện 3D lớn hơn trong Python?
Nếu chúng ta muốn các lô của chúng ta lớn hơn hoặc nhỏ hơn kích thước mặc định, chúng ta có thể dễ dàng đặt kích thước của sơ đồ khi khởi tạo hình - sử dụng tham số hình của phương thức PLT.Figure hoặc chúng ta có thể cập nhật kích thước của một Vẽ bằng cách gọi phương thức set_size_inches trên đối tượng hình.using the figsize parameter of the plt. figure method, or we can update the size of an existing plot by calling the set_size_inches method on the figure object.
Làm thế nào để bạn phóng to một âm mưu trong Python?
Hình () có hai tham số- chiều rộng và chiều cao (tính bằng inch).Theo mặc định, các giá trị cho chiều rộng và chiều cao lần lượt là 6,4 và 4,8.Trong đó, x và y có chiều rộng và chiều cao tương ứng tính bằng inch. takes two parameters- width and height (in inches). By default the values for width and height are 6.4 and 4.8 respectively. Where, x and y are width and height respectively in inches.
Làm cách nào để làm cho một con số lớn hơn trong matplotlib?
Làm thế nào để thay đổi kích thước của các số liệu trong matplotlib.. Sử dụng matplotlib.pyplot.nhân vật(). Sử dụng set_size_inches (). bằng cách sửa đổi RCPARAM ['Hình.Hình '].
Làm thế nào để bạn phóng to 3D trong Python?
Matplotlib với Python.. Đặt kích thước hình và điều chỉnh phần đệm giữa và xung quanh các ô phụ .. Tạo một hình mới hoặc kích hoạt một hình hiện tại bằng phương thức Hình () .. Nhận đối tượng trục 3D bằng phương pháp AXES3D (Hình) .. Sơ đồ các điểm dữ liệu x, y và z bằng phương thức scatter () .. Để hiển thị hình, sử dụng phương thức show () .. |