Python3 使用 matplotlib 画折线图
2017-09-19 15:11
357 查看
ChartUtil.py
import matplotlib.pyplot as plt from pylab import mpl def plotLine(xData,yData,xLabel,chartTitle): mpl.rcParams['font.sans-serif'] = ['FangSong'] # 指定默认字体 mpl.rcParams['axes.unicode_minus'] = False # 解决保存图像是负号'-'显示为方块的问题 fig = plt.figure() ax = fig.add_subplot(1, 1, 1) #xData = range(0, 5) #xLabel = ["2009-June", "2009-Dec", "2010-June", "2010-Dec", "2011-June"] ax.set_xticks(range(len(xLabel))) ax.set_xticklabels(xLabel, rotation=40) ax.set_title(chartTitle)#设置标题 #yData = [10, 13, 5, 40, 30] ax.plot(xData, yData, marker='o') # plt.plot(x1,y1,label='Frist line',linewidth=1.5,color='blue',marker='o',markerfacecolor='red',markersize=7) # plt.plot(x1,y1,'bo') plt.show()
使用
import DbUtil as dbu import ChartUtil as cu conn, cursor = dbu.getDbConnection() sql="select * from data_house where create_time BETWEEN '2017-09-18 00:00:00' and '2017-09-19 00:00:00' "; cursor.execute(sql); results = cursor.fetchall(); xLable=[] yData=[] for row in results: xLable.append(row[3]) yData.append(row[4]) createTime=row[2] dbu.closeDb(conn, cursor) dataCount=len(xLable) xData=range(0,dataCount,1) chartTitle=str(createTime) + ' Average Price' cu.plotLine(xData, yData, xLable,chartTitle)结果
相关文章推荐
- 使用python的matplotlib(pyplot)画折线图和柱状图
- python使用matplotlib模块绘制多条折线图、散点图
- python 数据可视化 matplotlib学习二 : 对折线图使用颜色映射
- Python绘图和数值工具:matplotlib 和 numpy下载与使用
- Python:使用matplotlib绘制图表
- python使用matplotlib绘图 -- barChart
- python使用matplotlib绘图 -- barChart
- 使用 python Matplotlib 库绘图
- 使用 python Matplotlib 库绘图
- python 使用numpy matplotlib绘制图表
- 使用Matplotlib与Python
- 广义mandelbrot集,使用python的matplotlib绘制,支持放大缩小
- python使用matplotlib绘制xy坐标轴图
- 使用 python Matplotlib 库绘图
- Python:使用matplotlib绘制图表
- 转:使用 python Matplotlib 库 绘图 及 相关问题
- 使用 python Matplotlib 库绘图
- python使用matplotlib绘图 -- barChart
- 使用 python Matplotlib 库绘图
- Python Matplotlib安装方法以及使用