程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[Python data visualization] visual processing of background data of superstar Learning Assistant

編輯:Python

Hello everyone , I meet you again , I'm your friend, Quan Jun .

Author:AXYZdong Automation Engineering Male A little bit of thinking , Have a little idea , A little bit rational ! [email protected],CSDN First episode , For more, please go to AXYZdong The blog of

Environmental Science :Python 3.7 The library used :matplotlib and csv

List of articles

  • One 、 Preparation
  • Two 、 get data
  • 3、 ... and 、 Visualization processing
  • Four 、 Running results
    • One 、 Broken line diagram
    • Two 、 Bar chart
  • 5、 ... and 、 Data description
  • 6、 ... and 、 After an assistant stops maintenance
    • 1、 Visualization processing
    • 2、 effect
  • summary

One 、 Preparation

install matplotlib library , At the command prompt, enter

pip install matplotlib

The installation may be a little slow , Wait patiently .

About matplotlib How to use the library , You can refer to :Matplotlib.pyplot Common methods

Two 、 obtain data

Script site :https://greasyfork.org/zh-CN/scripts

Download statistics from superstar assistant .csv file , And keep it with python Files in the same directory .

remind : After getting the data , Delete the English in the first line , Otherwise datetime.strptime() An error occurs when the function converts data

3、 ... and 、 Visualization processing

# =============================================
# --*-- coding: utf-8 --*--
# @Time : 2020-04-28
# @Author : AXYZdong
# @CSDN : https://blog.csdn.net/qq_43328313
# @FileName: demo_1.py
# @Software: Python3.7
# =============================================
import matplotlib.pyplot as plt # Import library
from datetime import datetime # The import module datetime Medium datetime class
import csv
date=[] # Create a list of
installs=[]
update_checks=[]
with open('stats.csv', 'r') as f: # extract stats.csv And save the data in the corresponding list
reader = csv.reader(f)
dates,installs = [],[]
for row in reader:
current_date = datetime.strptime(row[0],"%Y-%m-%d") # Data containing date information row[0] To datetime object
dates.append(current_date)
install = int(row[1])
installs.append(install)
update_checks.append(row[2])
plt.plot(dates,installs,color= 'red') # Use bar charts , The color is set to red
plt.title('the picture about xuexitong help installs', fontsize = 16) # Set picture name
plt.xticks(rotation=300) #x Axis label rotation
plt.ylabel("", fontsize = 16)
plt.ylabel("Number", fontsize = 16)
plt.show() 

Four 、 Running results

One 、 Broken line diagram

Two 、 Bar chart

Just change one code

plt.bar(date,installs,color= 'red') 

5、 ... and 、 Data description

The statistical data is 2018-06-19 ~ 2020-04-13 Number of installations .

so :2020-03~2020-04 During this period of time, the data burst , What is the specific reason , Do you know ( Manual funny )

6、 ... and 、 After an assistant stops maintenance

Another big man began to take over , Another script

1、 Visualization processing

# =============================================
# --*-- coding: utf-8 --*--
# @Time : 2020-04-28
# @Author : AXYZdong
# @CSDN : https://blog.csdn.net/qq_43328313
# @FileName: demo_2.py
# @Software: Python3.7
# =============================================
import matplotlib.pyplot as plt # Import library
from datetime import datetime # The import module datetime Medium datetime class
import csv
date=[] # Create a list of
installs=[]
update_checks=[]
with open('stats1.csv', 'r') as f: # extract stats1.csv And save the data in the corresponding list
reader = csv.reader(f)
dates,installs = [],[]
for row in reader:
current_date = datetime.strptime(row[0],"%Y-%m-%d") # Data containing date information row[0] To datetime object
dates.append(current_date)
install = int(row[1])
installs.append(install)
update_checks.append(row[2])
plt.plot(dates,installs,color= 'blue') # Use bar charts , The color is set to blue
plt.title('the picture about xuexitong help installs', fontsize = 16) # Set picture name
plt.xticks(rotation=300) #x Axis label rotation
plt.ylabel("", fontsize = 16)
plt.ylabel("Number", fontsize = 16)
plt.show() 

2、 effect

summary

In order to achieve the desired results , It's been a long time At first it was x The problem of shaft label , The picture is always dark , I thought it was the problem of too much data , I didn't think about it After uploading to the blog , It is found that the coordinate value is wrong , The result is different from what I expected . Start looking for all kinds of information , In the end 《Python Programming From introduction to practice 》 We found a solution . Xiaobai's me Study Python, Encountered various problems , Slowly solve them one by one , To achieve the desired results .

You are welcome to criticize and correct

Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/151755.html Link to the original text :https://javaforall.cn


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved