1 import matplotlib.pyplot as plt 
 2 import numpy as np
 3 np.random.seed(0) 
 4 x = np.arange(5)
 5 y = np.random.randint(-5,5,5)
 6 plt.subplot(1,2,1)
 7 plt.bar(x,y,color='blue')
 8 #在0位置水平方向添加蓝色的线条
 9 plt.axhline(0,color='blue',linewidth=2)
10 
11 plt.subplot(1,2,2)
12 #barh 将y和x进行对换,竖着方向为x轴
13 plt.barh(x,y,color='red')
14 #在0位置垂直方向添加红色线条
15 plt.axvline(0,color='red',linewidth=2)
16 
17 plt.show()

bar函数与barh函数

 

 

 

相关文章:

  • 2021-10-10
  • 2021-08-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-13
  • 2021-05-13
  • 2021-11-24
  • 2021-12-04
  • 2021-10-31
  • 2021-08-14
  • 2021-12-10
相关资源
相似解决方案