在Matplotlib中的三维曲面图上创建自定义轴值

时间:2014-11-08 16:08:19

标签: python matplotlib mplot3d

如何在Matplotlib中更改3D曲面图中图表上显示的轴值?

我在X轴上有16个,32个,64个和128个值,但matplotlib显示10,20,30,40等。我该怎么做才能正确显示它(我的意思是16,32,64和128个值) ?

enter image description here

以下是代码:

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

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

plt.title("Just simple text of 3D plot")

X = [   
            [16, 16, 16, 16, 16, 16, 16],
            [32, 32, 32, 32, 32, 32, 32],
            [64, 64, 64, 64, 64, 64, 64],
            [128, 128, 128, 128, 128, 128, 128]
        ]
Y = [   
            [1, 2, 3, 4, 5, 6, 7],
            [1, 2, 3, 4, 5, 6, 7],
            [1, 2, 3, 4, 5, 6, 7],
            [1, 2, 3, 4, 5, 6, 7]
        ]

Z = [
    [550    ,700    ,650    ,550    ,300    ,100    ,5],
    [650    ,760    ,720    ,620    ,350    ,150    ,15],
    [720    ,800    ,780    ,700    ,500    ,250    ,50 ],
    [580    ,690    ,600    ,550    ,250    ,50     ,5  ]
]


ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm, linewidth=0, antialiased=False)

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

ax.view_init(elev=33, azim=155)
plt.savefig("3d_test.png")

1 个答案:

答案 0 :(得分:1)

我认为以下内容会:

ax.set_xticks([16,32,64,128])