爬虫,四种统计图

导包

 
  1. import numpy as np

  2. import matplotlib.pyplot as plt

代码

网格线图

 
  1. ypoints = np.array([1,3,9,25,12,32,5,1])

  2.  
  3. 数据插入到图表

  4. marker:符号

  5. color:颜色,可简写为c

  6. linewidth:线条宽度

  7.  
  8. #plt.plot(ypoints,'o:g')

  9. #plt.plot(ypoints,marker='o',linestyle=':',color='g')

  10. plt.plot(ypoints,marker='o',ls=':',c='g',linewidth='1.5')

marker可以定义的符号如下:

80c4c3e2faba4684bf7d76299c9be2e4.png

散点图

 
  1. import numpy as np

  2. import matplotlib.pyplot as plt

  3.  
  4. x = np.array([1, 2, 3, 4, 5, 6, 7, 8])

  5. y = np.array([1, 4, 9, 16, 7, 11, 23, 18])

  6. sizes = np.array([20,50,100,200,500,1000,60,90])

  7. colors=np.array(["red","green","black","orange","purple","beige","cyan","magenta"])

  8. plt.subplot(1,2,1)

  9. plt.scatter(x, y, s=sizes,c=colors,cmap='afmhot_r') #viridis颜色条

  10. plt.title("scatter")

  11. plt.colorbar() #颜色条输出

  12.  
  13.  
  14. x2 = np.random.rand(50)

  15. y2 = np.random.rand(50)

  16. colors2 = np.random.rand(50)

  17. plt.subplot(1,2,2)

  18. plt.scatter(x2,y2,c=colors2,cmap='afmhot_r')

  19. plt.title("scatter2")

  20. plt.colorbar()

  21.  
  22. plt.show()

柱形图

 
  1. import matplotlib.pyplot as plt

  2. import numpy as np

  3.  
  4. #定义数据

  5.  
  6. x=np.array(['math','english','chinese','history','physic'])

  7. y=np.array([88,77,66,55,99])

  8. c=np.array(["#4CAF50","red","hotpink","#556B2F","pink"])

  9.  
  10.  
  11. plt.subplot(1,2,1)

  12.  
  13. #插入数据显示

  14.  
  15. plt.bar(x,y,color=c,width=0.5)

  16. plt.title('score')

  17. plt.xlabel('course')

  18. plt.ylabel('grade')

  19.  
  20.  
  21. plt.subplot(1,2,2)

  22.  
  23. #定义数据

  24.  
  25. x=np.array(['math','english','chinese','history','physic'])

  26. y=np.array([88,77,66,55,99])

  27. plt.bar(x,y,color='pink',width=0.5)

  28. plt.title('score')

  29. plt.xlabel('course')

  30. plt.ylabel('grade')

  31.  
  32. plt.show()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值