python与其他语言发展趋势动态图

import requests
import re
import os
import csv
url = 'https://www.tiobe.com/tiobe-index/'
f = open('programming.csv', 'w', newline='')
writer = csv.DictWriter(f, ['Programming','Percent','Date'])
writer.writeheader()
response = requests.get(url, )
html = response.text
result = ''.join(re.findall(r'series: (.*?)\}\);', html, re.DOTALL))
result = re.findall(r'({.*?})', result, re.DOTALL)
for item in result:
 name =''.join(re.findall(r"{name : '(.*?)'", item, re.DOTALL))
 data = re.findall(r"\[Date.UTC(.*?)\]", item, re.DOTALL)
 print(name)
 for i in data:
  i = i.replace(' ', '')
  i = re.sub(r'[()]', '', i)
  value = i.split(',')[-1]
  time_list = i.split(',')[:3]
  time = ""
  for index, j in enumerate(time_list):
   if index !=0:
    if len(j) == 1:
     j = '0' + j
   if index == 0:
    time += j
   else:
    time += '-' + j
  temp = {
   'Programming': name,
   'Percent': value,
   'Date': time
  }
  writer.writerow(temp)
f.close()

import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from IPython.display import HTML

df = pd.read_csv('programming.csv')

colors=dict(zip(['C','Python','Java','C++','C#','Visual Basic','JavaScript','Assembly language','PHP','SQL'],
               ['#adb0ff','#ffb3ff','#90d595','#e48381','#aafbff','#f7bb5f','#eafb50','#23ffab','#abff12','#afbb90']))
current_date='2021-04-02'
fig,ax=plt.subplots(figsize=(15,8))
def draw_barchart(date):
    dff=(df[df['Date'].eq(date)].sort_values(by='Percent',ascending=True).head(10))
    ax.clear()
    ax.barh(dff['Programming'],dff['Percent'],color=[colors[x] for x in dff['Programming']])
    ax.text(1,0.4,date,transform=ax.transAxes,size=46,ha='right')
    
#draw_barchart(current_date)

animator=animation.FuncAnimation(fig,draw_barchart,frames=sorted(list(set(df['Date'].values))))
#animator.save('temp.gif')
#animator.to_html5_video('temp.mp4')
HTML(animator.to_jshtml())


在这里插入图片描述

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页