|
10鱼币
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.axes3d import Axes3D
import numpy as np
fig = plt.figure()
axes3d = Axes3D(fig)
zs = [1, 5, 10, 15, 20]
for z in zs:
x = np.arange(0, 10)
y = np.random.randint(0, 30, size=10)
axes3d.bar(x, y, zs=z, zdir='x', color=['r', 'green', 'yellow', 'c'])
plt.show()
代码如上但是显示出来的是一片空白
本帖最后由 chinajz 于 2023-1-24 07:49 编辑
修改了一下,看是否符合你的想法:
- import numpy as np
- import matplotlib.pyplot as plt
- from mpl_toolkits.mplot3d import Axes3D
- fig = plt.figure()
- # 把画布分为1行1列,从左往右从上往下第1块区域
- # 表示“1×1网格,第一子图” 调用Axes3d
- axes3d = fig.add_subplot(111, projection='3d')
- # 设置Z轴坐标值,让每一个直方图间隔距离为5
- zs = [0, 5, 10, 15, 20]
- for z in zs:
- # 在0-10中取出值(取头不取尾)
- x = np.arange(0, 10)
- # 随机在0-30取出10个值
- y = np.random.randint(0, 30, size=10)
- # zdir将哪个方向用作z('x','y'或'z'),指定颜色
- axes3d.bar(x, y, zs=z, zdir='x', color=['red', 'green', 'yellow', 'c'])
- # print(x,y,zs)
- plt.show()
复制代码
|
|