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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM