简体   繁体   中英

Make a custom axes values on 3d surface plot in Matplotlib

How can I change axes values that are displayed on chart in 3D surface plot in Matplotlib?

I have 16, 32, 64 and 128 values on X axis but matplotlib displays 10, 20, 30, 40, etc. What should I do to display it correctly (I mean exactly 16, 32, 64 and 128 values)?

在此处输入图片说明

Below is the code:

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")

我认为以下将做:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM