[英]Reverse Z Axis on matplotlib 3D Plot
How would one reverse the order on the z axis of a 3D plot (ie negative is up, and positive is down)? 如何逆转3D图的z轴上的顺序(即负向上,正向向下)? The following code produces a cone with the base pointing downward; 下面的代码生成一个底部朝下的圆锥体; is there a command (like ax.reverse_zlim3d(True)
or something?) that can be used to change the tick order? 是否有一个命令(如ax.reverse_zlim3d(True)
或其他东西?)可用于更改刻度顺序?
The following code plots a cone with the base pointing downward. 下面的代码绘制了一个底部指向下方的圆锥体。 I would like to reverse the z-axis order so that it plots with the base pointing up, like an ice cream cone, with -1 at the top of the graph instead of the bottom. 我想颠倒z轴的顺序,以便它的底部朝上,如冰淇淋圆锥,在图形的顶部而不是底部为-1。
from matplotlib import pyplot as p
from mpl_toolkits.mplot3d import Axes3D # @UnusedImport
import numpy as np
from math import pi, cos, sin
z = np.arange(0, 1, 0.02)
theta = np.arange(0, 2 * pi + pi / 50, pi / 50)
fig = p.figure()
axes1 = fig.add_subplot(111, projection='3d')
for zval in z:
x = zval * np.array([cos(q) for q in theta])
y = zval * np.array([sin(q) for q in theta])
axes1.plot(x, y, -zval, 'b-')
axes1.set_xlabel("x label")
axes1.set_ylabel("y label")
axes1.set_zlabel("z label")
p.show()
Use the invert_zaxis
method of the Axes3D
: 使用invert_zaxis
的方法Axes3D
:
from matplotlib import pyplot as p
from mpl_toolkits.mplot3d import Axes3D # @UnusedImport
import numpy as np
from math import pi, cos, sin
z = np.arange(0, 1, 0.02)
theta = np.arange(0, 2 * pi + pi / 50, pi / 50)
fig = p.figure()
axes1 = fig.add_subplot(111, projection='3d')
for zval in z:
x = zval * np.array([cos(q) for q in theta])
y = zval * np.array([sin(q) for q in theta])
axes1.plot(x, y, -zval, 'b-')
axes1.set_xlabel("x label")
axes1.set_ylabel("y label")
axes1.set_zlabel("z label")
axes1.invert_zaxis()
p.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.