# 畫折線圖
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
file=r'C:\Users\zm.com\Desktop\wwlln_year\20050112.txt'
# read file
def read_data(file_path):
colume_name=['datee','number']
data=pd.read_csv(file_path,header=None,names=colume_name)
return data
#線性圖
def line_plot(x,y,figure_no):
plt.figure(figure_no)
plt.plot(x,y,color='k',linestyle='-',marker='.')
#plt.xlim([160101,160131])
#plt.ylim([0,2400])
#plt.xticks([i for i in range(160101,160132)])
#plt.yticks([i*200 for i in range(0,13)])
plt.xlabel('Date')
plt.ylabel('The Number of Lightning')
#plt.title('The number of lightning strikes on a daily basis in January 2016')
# 調用函數
dataset=read_data(file)
figure_no=1
x=dataset['datee']
y=dataset['number']
line_plot(x,y,figure_no)
#x=[1,2,3,4]
#y=[1.2,2.4,3.6,4.8]
plt.show()
參考鏈接:
https://blog.csdn.net/eefresher/article/details/90022648
https://blog.csdn.net/Dian1pei2xiao3/article/details/80540084