Python matplotlib绘制线型图

# 画折线图
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

猜你喜欢

转载自www.cnblogs.com/stelliformzm/p/12944440.html