python库matplotlib绘制折线图,散点图以及设置样式

一:首先导入matplotlib库:

File->setting

Project Interpreter 点击右边的+号

搜索到之后点击左下角install package安装。

二:折线图:

#折线图
import matplotlib.pyplot as plt
x_valuse = [1,2,3,4,5]
y_squares = [1,4,9,16,25] #表示(0,1) (1,4) ……的点
plt.plot(x_valuse,y_squares, linewidth = 5) #设置横纵坐标和线条粗细
plt.xlabel("Value", fontsize=14) #横轴
plt.ylabel("Square of Value", fontsize=14) #横轴
plt.show()

三:散点图

#scatter绘制散点图
#plt.scatter(2,4)#绘制一个点
x_valuse = [1,2,3,4,5]
y_squares = [1,4,9,16,25]
'''
scatter参数总结:
x,y:表示的是shape大小为(n,)的数组,也就是我们即将绘制散点图的数据点,输入数据。
s:表示的是大小,是一个标量或者是一个shape大小为(n,)的数组,可选,默认20。
c:表示的是色彩或颜色序列,可选,默认蓝色’b’。但是c不应该是一个单一的RGB数字,也不应该是一个RGBA的序列,因为不便区分。c可以是一个RGB或RGBA二维行数组。
marker:MarkerStyle,表示的是标记的样式,可选,默认’o’。
cmap:Colormap,标量或者是一个colormap的名字,cmap仅仅当c是一个浮点数数组的时候才使用。如果没有申明就是image.cmap,可选,默认None。
norm:Normalize,数据亮度在0-1之间,也是只有c是一个浮点数的数组的时候才使用。如果没有申明,就是默认None。
vmin,vmax:标量,当norm存在的时候忽略。用来进行亮度数据的归一化,可选,默认None。
alpha:标量,0-1之间,可选,默认None。
linewidths:也就是标记点的长度,默认None。
'''
plt.scatter(x_valuse,y_squares,s=100)#绘制一系列点

plt.title("Square Numbers", fontsize=14)
plt.xlabel("Value", fontsize=14) #横轴
plt.ylabel("Square of Value", fontsize=14) #横轴
'''
tick_params参数的总结:
参数axis的值为’x’、’y’、’both’,分别代表设置X轴、Y轴以及同时设置,默认值为’both’。 
参数which的值为 ‘major’、’minor’、’both’,分别代表设置主刻度线、副刻度线以及同时设置,默认值为’major’ 
(主刻度线、副刻度线类似于厘米尺。CM与MM的区别) 
参数direction的值为’in’、’out’、’inout’,分别代表刻度线显示在绘图区内侧、外侧以及同时显示 
参数length和width分别用于设置刻度线的长度和宽度 
参数pad用于设置刻度线与标签间的距离 
参数color、labelcolor、colors分别用于设置刻度线的颜色、刻度线标签的颜色以及同时设置刻度线及标签颜色 
参数labelsize用于设置刻度线标签的字体大小 
参数bottom, top, left, right的值为布尔值,分别代表设置绘图区四个边框线上的的刻度线是否显示 
参数labelbottom, labeltop, labelleft, labelright的值为布尔值,分别代表设置绘图区四个边框线上的刻度线标签是否显示 
'''
plt.tick_params(axis='both', which='major',labelsize=14)

plt.show()

四:自动生成图以及使用颜色映射

#自动生成图形
x_valuse = list(range(1,100)) #创建一个整数列表,list() 方法用于将元组转换为列表,Python 的元组与列表类似,不同之处在于元组的元素不能修改。
y_squares = [x**2 for x in x_valuse] #!!!
#plt.scatter(x_valuse, y_squares, c='green', s=40)
plt.scatter(x_valuse, y_squares, c=y_squares, cmap=plt.cm.Blues, s=40)#使用颜色映射
plt.axis([0,100,0,10000])
plt.show()

 

五:保存图

#保存图
plt.savefig('a.png',bbox_inches='tight')#第二个参数表示将多余的空白区域剪掉

 

Orchestrator Server Windows Server Operating System - minimum required version: 2008 R2 SP1. Check the Software Requirements for the other supported versions. PowerShell - minimum required version: 4.0. To download PowerShell version 4.0, visit this link and install Windows Management Framework 4.0. .NET Framework - minimum required version: 4.7.2 To find out which .NET version is installed on your computer, please see Finding the Installed .NET Version. IIS - minimum required version: 7.5. this is part of the Web Server (IIS) role and is automatically enabled by the provided InstallRolesAndFeatures.ps1script, which can be found in this archive. URL Rewrite - Enables the website to redirect the calls to https (https://servername), instead of http (http://servername). Please download and install URL Rewrite by accessing this link. Server Roles and Features. We provide a PowerShell script, InstallRolesAndFeatures.ps1, that automatically adds the required roles and features to the application server(s). The list of roles and features is presented in Server Roles and Features. Please note that this chapter is for informational purposes only. The archive containing the script and the XML file can be downloaded here. Web-Deploy extension - minimum required version: 3.5, 64bit version. Please note that this is required only for PowerShell script installations, such as the Azure one. Enables you to deploy a website. Please download and install Web Deploy Extension 3.5 by accessing this link.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值