微信扫一扫打赏支持

matplotlib库疑难问题---11、画动态直方图

matplotlib库疑难问题---11、画动态直方图

一、总结

一句话总结:

动态画直方图的原理非常简单:就是不断的清除画布的图像,生成新的图像,只要速度足够快,眼睛追不上,那么我们看到的就是动画
import numpy as np
import matplotlib.pyplot as plt
%matplotlib qt5

a=np.array([])
for i in range(110):
    for _ in range(100):
        add_num=np.sum(np.random.rand(90))
        a=np.append(a,add_num)
        pass
    # plt.clf() # Clear the current figure.
    plt.cla()   # Clear the current axes.
    plt.hist(a, bins=30, color='g', alpha=0.75)  # hist:绘制直方图
    plt.grid()
    plt.pause(0.1)
    plt.show()

 

 

二、画动态直方图

博客对应课程的视频位置:

 

动态画直方图的原理非常简单:就是不断的清除画布的图像,生成新的图像,只要速度足够快,眼睛追不上,那么我们看到的就是动画

In [4]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib qt5

a=np.array([])
for i in range(110):
    for _ in range(100):
        add_num=np.sum(np.random.rand(90))
        a=np.append(a,add_num)
        pass
    # plt.clf() # Clear the current figure.
    plt.cla()   # Clear the current axes.
    plt.hist(a, bins=30, color='g', alpha=0.75)  # hist:绘制直方图
    plt.grid()
    plt.pause(0.1)
    plt.show()
 
 

本系列博客对应课程位置:
1、解决中文乱码问题-范仁义-读书编程笔记
https://www.fanrenyi.com/video/43/371
2、将曲线平滑-范仁义-读书编程笔记
https://www.fanrenyi.com/video/43/372
3、matplotlib绘图核心原理-范仁义-读书编程笔记
https://www.fanrenyi.com/video/43/373
4、画动态图-范仁义-读书编程笔记
https://www.fanrenyi.com/video/43/374
5、保存动态图-范仁义-读书编程笔记
https://www.fanrenyi.com/video/43/375
6、显示图片-范仁义-读书编程笔记
https://www.fanrenyi.com/video/43/376

7、去掉刻度和边框-范仁义-读书编程笔记
https://www.fanrenyi.com/video/43/383

8、几个点画曲线-范仁义-读书编程笔记
https://www.fanrenyi.com/video/43/384

9、画箭头(综合实例)-1-范仁义-读书编程笔记
https://www.fanrenyi.com/video/43/391

9、画箭头(综合实例)-2-范仁义-读书编程笔记
https://www.fanrenyi.com/video/43/392

10、画直方图-范仁义-读书编程笔记
https://www.fanrenyi.com/video/43/393

11、画动态直方图-范仁义-读书编程笔记
https://www.fanrenyi.com/video/43/394

 
posted @ 2020-11-16 15:36  范仁义  阅读(258)  评论(0编辑  收藏  举报