python中matplotlib总结
该总结只是为了记录自己学习过程中容易遗忘的问题,权当一个记事本使用。
1:散点图
plt.scatter()函数的原型
scatter(x, y, s=s, c=c, marker=marker, cmap=cmap, norm=norm,vmin=vmin, vmax=vmax, alpha=alpha,
linewidths=linewidths, verts=verts,edgecolors=edgecolors, data=data, **kwargs)
各个参数的含义:
其中marker的含义
其中C的含义如下
下面进行简单的实例化演示:
下面的例子是:房价的预测:
数据源:
#利用模拟的模型进行画图 def show_linear_line(X_parameters,Y_parameters):
reg = linear_model.LinearRegression()
reg.fit(X_parameters,Y_parameters)
plt.scatter(X_parameters,Y_parameters,c = 'blue',,marker = 'o')
plt.plot(X_parameters,reg.predict(X_parameters),color = 'red',linewidth = 2 ,label = 'feet_price') #其中label表示线条的含义
# 设置图像的标题
plt.title('house_price')
#为图像设置网格
plt.grid()
#设置横纵坐标的范围
plt.xlim((150,700))
plt.ylim(5000,20000)
#设置坐标轴的刻度
plt.xticks(np.linspace(150,700,5))
plt.yticks(np.linspace(5000,20000,5))
#设置横纵坐标轴标签
plt.xlabel('square_feet')
plt.ylabel('price')
plt.legend()
plt.show()
房价的预测结果:
plot()函数
用于绘制模拟的线
如上面代码中所示,plot()函数可以添加多个参数
其中形状的种类如下图:https://matplotlib.org/api/_as_gen/matplotlib.pyplot.plot.html
线条的颜色如下:
plot([1,2,3], [1,2,3], 'go-', label='line 1', linewidth=2)
plot([1,2,3], [1,4,9], 'rs', label='line 2')
axis([0, 4, 0, 10])
legend()
savefig()函数
保存图片 https://matplotlib.org/api/pyplot_api.html 从api中查找各个参数的含义
savefig(fname, dpi=None, facecolor='w', edgecolor='w',
orientation='portrait', papertype=None, format=None,
transparent=False, bbox_inches=None, pad_inches=0.1,
frameon=None)
如下图:如果加上标红线的代码,则会将图片输出到该路径中
#利用模拟的模型进行画图 def show_linear_line(X_parameters,Y_parameters):
reg = linear_model.LinearRegression()
reg.fit(X_parameters,Y_parameters)
plt.scatter(X_parameters,Y_parameters,c = 'blue',marker = '^')
plt.plot(X_parameters,reg.predict(X_parameters),color = 'red',linewidth = 2 ,label = 'feet_price')
# 设置图像的标题
plt.title('house_price')
#为图像设置网格
plt.grid()
#设置横纵坐标的范围
plt.xlim((150,700))
plt.ylim(5000,20000)
#设置坐标轴的刻度
plt.xticks(np.linspace(150,700,5))
plt.yticks(np.linspace(5000,20000,5))
#设置横纵坐标轴标签
plt.xlabel('square_feet')
plt.ylabel('price')
#输出图片到改路径下面
plt.savefig('G:\\python\\20180108demo\\01Lineargression\\resultPic\\housePredicted.png')
plt.legend()
plt.show()
python中matplotlib总结的更多相关文章
- python 中matplotlib 绘图
python 中matplotlib 绘图 数学建模需要,对于绘图进行简单学习 matpoltlib之类的包安装建议之间用anaconda 绘制一条y=x^2的曲线 #比如我们要绘制一条y=x^2的曲 ...
- python中matplotlib画折线图实例(坐标轴数字、字符串混搭及标题中文显示)
最近在用python中的matplotlib画折线图,遇到了坐标轴 "数字+刻度" 混合显示.标题中文显示.批量处理等诸多问题.通过学习解决了,来记录下.如有错误或不足之处,望请指 ...
- Python中matplotlib模块解析
用Matplotlib绘制二维图像的最简单方法是: 1. 导入模块 导入matplotlib的子模块 import matplotlib.pyplot as plt import numpy as ...
- python中matplotlib的颜色及线条控制
参考网址: http://www.cnblogs.com/darkknightzh/p/6117528.html http://stackoverflow.com/questions/22408237 ...
- (原)python中matplotlib的颜色及线条控制
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/6117528.html 参考网址: http://stackoverflow.com/questions ...
- python中matplotlib 的简单使用
1.简单折线图的画图,轴标签.图的颜色,风格,等等参数,本文只介绍最常用的几个参数: import matplotlib.pyplot as plt import numpy as np x = np ...
- python中matplotlib绘图封装类之折线图、条状图、圆饼图
DrawHelper.py封装类源码: import matplotlib import matplotlib.pyplot as plt import numpy as np class DrawH ...
- Python中matplotlib.pyplot.imshow画灰度图的多种方法
转载:https://www.jianshu.com/p/8f96318a153f matplotlib库的教程和使用方法此处就不累赘了,网上有十分多优秀的教程资源.此处直接上代码: def demo ...
- python中matplotlib所绘制的图包含了很多的对象
上图中的top=‘off’意思是说顶部的grid lines 看不见. 去除frame,意思就是将这个矩形给去除掉,spine意思是脊柱 bars = plt.bar(pos, popularity, ...
随机推荐
- luogu P3065 first——trie树相关
题目描述 Bessie has been playing with strings again. She found that by changing the order of the alphabe ...
- 转:在使用angularjs过程,ng-repeat中track by的作用
转载:链接 <div ng-repeat="links in slides"> <div ng-repeat="link in links track ...
- Shellinabox安装及使用教程
本文转载自: shellinabox:一款使用 AJAX 的基于 Web 的终端模拟器 一.shellinabox简介 通常情况下,我们在访问任何远程服务器时,会使用常见的通信工具如OpenSSH和P ...
- Appium元素定位(uiautomatorviewer)
一.uiautomatorviewer元素定位 1.adroid-sdk的安装目录tools下有1个自带的工具uiautomatorviewer,打开后,如下所示: 点击后,如图所示: 步骤: a.链 ...
- EF6 code first 新建项目注意问题
1.一开始就建立自动迁移模式 打开Package Manager Console,确保Package source是nuget.org 命令行输入: enable-migrations 然后第一次运行 ...
- Vertical-Align: 关于inline,inline-block文本排版
inline, inline-block元素在同行元素的排版布局中非常有用,但是时常会出现一些莫名奇妙的问题.要解决这些问题,深刻理解inline,inline-block元素的特征有非常重要的意义. ...
- Windows server 2008系统各类版本的优缺点比较,Windows2008系统标准版 企业版 数据中心版 WEB版等
大家都知道Windows Server 2008 发行了多种版本,以支持各种规模的企业对服务器不断变化的需求.Windows Server 2008 有 5 种不同版本,另外还有三个不支持 Windo ...
- Scratch www 系统搭建
原文地址:https://blog.csdn.net/litianquan/article/details/82735809 Scratch www要基于Nodejs的环境才可以运行,我尝试了在Win ...
- 入门级 - 码云(Gitee),GitHub 教程
这篇文章的目的是记录我的关于GitHub的内容,从注册.下载直到设置成功每一步都有解释,其中有一些截图或者代码来自于网络. GitHub和码云均基于Git,所以两者的操作方法基本一致,只需要学习其中一 ...
- Current_Path 获取脚本所在路径(当前路径),取当前时间做文件名(uformat)
获取脚本当前所在路径: $CurrentPath = $MyInvocation.MyCommand.Path.substring(0,$MyInvocation.MyCommand.Path.Las ...