Matplotlib 3D图的反转轴破坏刻度线

时间:2019-06-19 11:44:14

标签: python matplotlib plot

我将使用官方的Matplotlib 3.1.0 example code绘制3D散点图:

# This import registers the 3D projection, but is otherwise unused.
from mpl_toolkits.mplot3d import Axes3D  # noqa: F401 unused import

import matplotlib.pyplot as plt
import numpy as np

# Fixing random state for reproducibility
np.random.seed(19680801)


def randrange(n, vmin, vmax):
    '''
    Helper function to make an array of random numbers having shape (n, )
    with each number distributed Uniform(vmin, vmax).
    '''
    return (vmax - vmin)*np.random.rand(n) + vmin

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

n = 100

# For each set of style and range settings, plot n random points in the box
# defined by x in [23, 32], y in [0, 100], z in [zlow, zhigh].
for m, zlow, zhigh in [('o', -50, -25), ('^', -30, -5)]:
    xs = randrange(n, 23, 32)
    ys = randrange(n, 0, 100)
    zs = randrange(n, zlow, zhigh)
    ax.scatter(xs, ys, zs, marker=m)

ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')

plt.show()

它绘制以下图像:

enter image description here

现在,我想反转Y轴的绘制顺序。我尝试在填充绘图的for循环之后添加ax.invert_yaxis(),但没有执行任何操作。在ax = fig.add_subplot(111, projection='3d')之后添加线的确可以使绘图本身反转,但会弄乱沿y轴的刻度线:

enter image description here

我做错了吗,或者可能是个错误? (我知道我可以将数据传递给倒置的数组,但我觉得解决方案不太干净。)

0 个答案:

没有答案