python繪制趨勢圖的示例
import matplotlib.pyplot as plt #plt用于顯示圖片import matplotlib.image as mping #mping用于讀取圖片import datetime as dtimport matplotlib.dates as mdatesfrom pylab import *def draw_trend_chart(dates,y): mpl.rcParams[’font.sans-serif’] = [’SimHei’] #指定默認(rèn)字體 mpl.rcParams[’axes.unicode_minus’] = False #解決保存圖像是負(fù)號’-’顯示為方塊的問題 x = [dt.datetime.strptime(d,’%Y/%m/%d’).date() for d in dates] #plt.figure(figsize=(8,8)) plt.figure() #plt.gca().xaxis.set_major_formatter(mdates.DateFormatter(’%m/%d/%Y’)) #plt.gca().xaxis.set_major_locator(mdates.DayLocator()) #plt.plot(x,y,'r--',linewidth=2) plt.plot(x,y,'r',linewidth=1) #plt.gcf().autofmt_xdate() #plt.xlabel('DATE') #x軸標(biāo)簽 plt.ylabel('WEIGHT') #y軸標(biāo)簽 plt.title('MY HEALTH TRACKING')#標(biāo)題 plt.savefig('liuyang.png') #保存圖片名稱 lena = mping.imread(’liuyang.png’) #讀取圖片文件信息 lena.shape #(512,512,3) plt.imshow(lena) #顯示圖片 plt.axis(’off’) #不顯示坐標(biāo)軸 plt.title('') plt.show() #顯示def get_weight_data(filename): time = [] weight = [] fileContent=open(filename,'r') for eachline in fileContent: eachData = eachline.strip(’n’).split(',') if eachData[-1].strip() ==’’: continue else: time.append(eachData[0]) weight.append(eachData[1]) return [time, weight]data = get_weight_data('data.csv')draw_trend_chart(data[0],data[1])
以上就是python繪制趨勢圖的示例的詳細(xì)內(nèi)容,更多關(guān)于python繪制趨勢圖的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. Python如何批量生成和調(diào)用變量2. windows服務(wù)器使用IIS時thinkphp搜索中文無效問題3. Python基于requests實(shí)現(xiàn)模擬上傳文件4. python利用opencv實(shí)現(xiàn)顏色檢測5. Python sorted排序方法如何實(shí)現(xiàn)6. Python 中如何使用 virtualenv 管理虛擬環(huán)境7. 通過CSS數(shù)學(xué)函數(shù)實(shí)現(xiàn)動畫特效8. ASP.NET MVC實(shí)現(xiàn)橫向展示購物車9. ASP.Net Core(C#)創(chuàng)建Web站點(diǎn)的實(shí)現(xiàn)10. Python獲取B站粉絲數(shù)的示例代碼
