乱人伦 国语对白海角社区,五月激情丁香婷婷综合中文字幕,欧美伊人婷婷久久五月综合,亚洲精品无amm毛片,亚洲男人第一无码AV网站,国产日韩欧美丝袜一区二区,亚洲一区精品在线观看

利用Python的matplotlib库绘制动态图形-太阳成tyc欢迎您

利用Python的matplotlib库绘制动态图形

2026-01-16 18:39:57投稿人:大眾彩票官方平臺(tái)大發(fā)(臺(tái)州)有限公司圍觀7154163 評(píng)論

利用Python的matplotlib庫(kù)繪制動(dòng)態(tài)圖形

一、python 繪制動(dòng)畫圖

python繪制動(dòng)態(tài)圖形是數(shù)據(jù)可視化更直觀 、更好看的一種方式 ,matplotlib工具包是常用的繪圖工具,也可以用來(lái)繪制動(dòng)態(tài)圖形 。本文介紹四種繪制動(dòng)態(tài)圖形的方法,包括生成圖形的代碼和動(dòng)態(tài)圖形演示示例。

用matplotlib工具包創(chuàng)建動(dòng)畫圖有兩種方法:

  • 使用 pause() 函數(shù)
  • 使用 FuncAnimation() 函數(shù)

動(dòng)畫柱狀圖 ,使用FuncAnimation() 函數(shù)

代碼如下:

from matplotlib import pyplot as pltfrom matplotlib.animation import FuncAnimation, writersimport numpy as np  fig = plt.figure(figsize = (7,5))axes = fig.add_subplot(1,1,1)axes.set_ylim(0, 300)palette = ['blue', 'red', 'green',            'darkorange', 'maroon', 'black']  y1, y2, y3, y4, y5, y6 = [], [], [], [], [], []  def animation_function(i):    y1 = i    y2 = 5 * i    y3 = 3 * i    y4 = 2 * i    y5 = 6 * i    y6 = 3 * i      plt.xlabel("Country")    plt.ylabel("GDP of Country")          plt.bar(["India", "China", "Germany",              "USA", "Canada", "UK"],            [y1, y2, y3, y4, y5, y6],            color = palette)  plt.title("Bar Chart Animation")  animation = FuncAnimation(fig, animation_function,                           interval = 50)plt.show()

如下圖:


橫向柱狀跑圖 (Horizontal Bar Chart Race),使用FuncAnimation() 函數(shù)

以下代碼是繪制世界1500年-2018年主要城市人口變化橫向柱狀跑圖