python绘制趋势图的示例
程序员文章站
2022-08-15 23:28:35
import matplotlib.pyplot as plt #plt用于显示图片import matplotlib.image as mping #mping用于读取图片import dateti...
import matplotlib.pyplot as plt #plt用于显示图片 import matplotlib.image as mping #mping用于读取图片 import datetime as dt import matplotlib.dates as mdates from pylab import * def draw_trend_chart(dates,y): mpl.rcparams['font.sans-serif'] = ['simhei'] #指定默认字体 mpl.rcparams['axes.unicode_minus'] = false #解决保存图像是负号'-'显示为方块的问题 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轴标签 plt.ylabel("weight") #y轴标签 plt.title("my health tracking")#标题 plt.savefig("liuyang.png") #保存图片名称 lena = mping.imread('liuyang.png') #读取图片文件信息 lena.shape #(512,512,3) plt.imshow(lena) #显示图片 plt.axis('off') #不显示坐标轴 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绘制趋势图的示例的详细内容,更多关于python绘制趋势图的资料请关注其它相关文章!
上一篇: 临床医生应该就是专门管住宿的