代码:
import matplotlib.pyplot as plt
num_list = [1,3,6,9,5,3] # Y坐标
name_list = ['HDY','Nic','Jay','Kobe','hdy','Deng']
plt.bar(range(len(num_list)),num_list,label='Handsome',tick_label=name_list)
plt.legend()
plt.show()
代码:
import numpy as np
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d
x = np.random.randint(0,40,10)
y = np.random.randint(0,40,10)
z = 80 * abs(np.sin(x+y))
ax = plt.subplot(projection='3d') # 三维图形
for xx, yy, zz in zip(x,y,z):
color = np.random.random(3) # 随机颜色元祖
ax.bar3d(
xx, # 每个柱的x坐标
yy, # 每个柱的y坐标
0, # 每个柱的起始坐标
dx=1, # x方向的宽度
dy=1, # y方向的厚度
dz=zz, # z方向的高度
color=color) #每个柱的颜色
plt.show()