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. 得到XML文檔大小的方法2. WMLScript的語法基礎(chǔ)3. 使用Spry輕松將XML數(shù)據(jù)顯示到HTML頁的方法4. ASP中if語句、select 、while循環(huán)的使用方法5. xml中的空格之完全解說6. ASP中解決“對象關(guān)閉時(shí),不允許操作。”的詭異問題……7. 輕松學(xué)習(xí)XML教程8. html小技巧之td,div標(biāo)簽里內(nèi)容不換行9. XML入門的常見問題(四)10. msxml3.dll 錯(cuò)誤 800c0019 系統(tǒng)錯(cuò)誤:-2146697191解決方法
