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. .Net Core和RabbitMQ限制循環(huán)消費(fèi)的方法2. jsp網(wǎng)頁實(shí)現(xiàn)貪吃蛇小游戲3. asp(vbs)Rs.Open和Conn.Execute的詳解和區(qū)別及&H0001的說明4. ASP.NET MVC遍歷驗(yàn)證ModelState的錯(cuò)誤信息5. 用css截取字符的幾種方法詳解(css排版隱藏溢出文本)6. ASP 信息提示函數(shù)并作返回或者轉(zhuǎn)向7. asp中response.write("中文")或者js中文亂碼問題8. PHP設(shè)計(jì)模式中工廠模式深入詳解9. CSS hack用法案例詳解10. 將properties文件的配置設(shè)置為整個(gè)Web應(yīng)用的全局變量實(shí)現(xiàn)方法
