[[327436]]

在索县等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供网站设计、网站制作 网站设计制作按需网站策划,公司网站建设,企业网站建设,品牌网站设计,营销型网站,成都外贸网站建设,索县网站建设费用合理。
- import pandas as pd
 - import numpy as np
 - import matplotlib.pyplot as plt
 - import matplotlib
 
目的
plt.plot()的定义及调用
定义:
调用:
位置参数:
关键字传参:
x序列的不同类型
文本型的x序列
- # data
 - X = [8,3,5,'t'] # 会按顺序【0,1,2,3】被定位在x轴的刻度上
 - Y = [1,2,3,4]
 - plt.plot(X,Y,marker = 'o',c='g')
 - ax = plt.gca()
 - print('x轴刻度:',plt.xticks()) #list
 - xticklabels_lst = ax.get_xticklabels()
 - print('-'*70)
 
x轴刻度:([0, 1, 2, 3], )
----------------------------------------------------------------------
- print('x轴刻度标签:',list(xticklabels_lst)) #是个文本标签
 
x轴刻度标签:[Text(0, 0, '8'), Text(1, 0, '3'), Text(2, 0, '5'), Text(3, 0, 't')]
数字型的x序列
- # data
 - X = [8,3,5,1] # 会按数字【8,3,5,1】被定位在x轴的刻度上
 - Y = [1,2,3,4]
 - plt.plot(X,Y,marker = 'o',c='g')
 - ax = plt.gca()
 - print('x轴刻度:',plt.xticks()) # array
 - xticklabels_lst = ax.get_xticklabels()
 - print('-'*70)
 
x轴刻度:(array([0., 1., 2., 3., 4., 5., 6., 7., 8., 9.]), )
----------------------------------------------------------------------
- print('x轴刻度标签:',list(xticklabels_lst)) #是个按序号排列的文本标签
 
x轴刻度标签:[Text(0.0, 0, '0'), Text(1.0, 0, '1'), Text(2.0, 0, '2'), Text(3.0, 0, '3'), Text(4.0, 0, '4'), Text(5.0, 0, '5'), Text(6.0, 0, '6'), Text(7.0, 0, '7'), Text(8.0, 0, '8'), Text(9.0, 0, '9')]
2种类型-2条线
- # data
 - X1 = [8,3,5,'t']
 - X2 = [8,3,5,1]
 - Y = [1,2,3,4]
 - plt.plot(X2,Y,marker = 'o',c='r')
 - plt.plot(X1,Y,marker = 'o',c='g')
 - ax = plt.gca()
 - print('x轴刻度:',plt.xticks())
 - xticklabels_lst = ax.get_xticklabels()
 - print('-'*70)
 
x轴刻度:([0, 1, 2, 3], )
----------------------------------------------------------------------
- print('x轴刻度标签:',list(xticklabels_lst))
 
x轴刻度标签:[Text(0, 0, '8'), Text(1, 0, '3'), Text(2, 0, '5'), Text(3, 0, 't')]
提供不同数量的位置参数
几种方式的调用
无参数
- #返回一个空列表
 - plt.plot()
 
[]
plot([x], y, [fmt], *, data=None, **kwargs) plot([x], y, [fmt], [x2], y2, [fmt2], ..., **kwargs)
1个参数
- #提供一个数(点)
 - plt.plot(4.5,marker='o')
 
[
- #提供一个数字序列
 - plt.plot([4.5,2,3],marker='o')
 
[
2个参数
自动解析位置参数的原则
(x,y)形式
- # x/y 为序列
 - plt.plot([2,1,3],[0.5,2,2.5],marker='o')
 
[
- # x/y 为标量
 - plt.plot(2,['z'],marker = 'o')
 
[
(y,fmt)形式
- # plt.plot(2,'z',marker = 'o') #Unrecognized character z in format string
 
- # y 为标量
 - plt.plot(2,'r',marker = 'o')
 
[
- # y 为序列
 - plt.plot([2,1,3],'r--*')
 
[
3个参数
([x],y,[fmt])形式
- plt.plot([2,1,3],[0.5,2,2.5],'p--g',
 - # marker='o'
 - markersize = 15
 - )
 
[
- # fmt不写,或者‘’,则使用默认样式
 - plt.plot([2,1,3],[0.5,2,2.5],'',
 - # marker='o'
 - markersize = 15
 - )
 
[
绘图Line2D
仅画线:绘图的默认情况
默认样式:蓝色的【线】【无标记】
- # marker = None 表示不做设置
 - plt.plot([2,2.5,1])
 
[
仅画标记
- plt.plot([2,2.5,1],'o')
 
[
画线+标记
- plt.plot([2,2.5,1],'o-')
 
[
- plt.plot([2,1,3],'bo--')
 
[
fmt的组合顺序随意的?
6图合一及结论
- # 6种组合
 - # [color][marker][line],3种任意组合为6种可能
 - # b :蓝色
 - # o: 圆圈标记
 - # --:虚线
 - fmt = ['bo--','b--o','ob--','o--b','--bo','--ob']
 - for i in range(len(fmt)):
 - plt.subplot(2,3,i+1)
 - plt.plot([2,1,3],fmt[i])
 - # 结论:[color][marker][line],每个都是可选的,每个属性可以选择写或者不写
 - # 而且与组合中它们所在的位置顺序无关
 
fmt支持的【线】-line
Line Styles
==== character description ====
'-' solid line style '--' dashed line style '-.' dash-dot line style ':' dotted line style
fmt支持的【标记】-marker
Markers
==== character description ====
'.' point marker ',' pixel marker \\\'o\\\' circle marker 'v' triangle_down marker '^' triangle_up marker '<' triangle_left marker '>' triangle_right marker '1' tri_down marker '2' tri_up marker '3' tri_left marker '4' tri_right marker 's\\\' square marker 'p' pentagon marker '*' star marker 'h' hexagon1 marker 'H' hexagon2 marker '+' plus marker 'x' x marker 'D' diamond marker 'd' thin_diamond marker '|' vline marker '_' hline marker
fmt支持的【颜色】-color
Colors
The supported color abbreviations are the single letter codes
==== character color ====
'b' blue 'g' green 'r' red 'c' cyan 'm' magenta 'y' yellow 'k' black 'w' white
所有样式:标记、线、颜色参考大全
链接:https://www.kesci.com/home/project/5ea4e5da105d91002d506ac6
样式属性
线条的属性
- # 包含:(颜色除外)
 - # 线的样式、线的宽度
 - # linestyle or ls: {'-', '--', '-.', ':', '', }
 - # linewidth or lw: float
 - ls_lst = ['-', '--', '-.', ':',]
 - lw_lst = [1,3,5,7]
 - for i in range(len(ls_lst)):
 - plt.plot([1,2,3,4],[i+1]*4,ls_lst[i],lw = lw_lst[i])
 
标记的属性
- # 包含:
 - '''
 - marker: marker style
 - #边框(颜色及边框粗细)
 - markeredgecolor or mec: color
 - markeredgewidth or mew: float
 - #面颜色
 - markerfacecolor or mfc: color
 - markerfacecoloralt or mfcalt: color #备用标记颜色
 - #标记的大小
 - markersize or ms: float
 - markevery: None or int or (int, int) or slice or List[int] or float or (float, float)
 - '''
 - # linestyle = None 表示不做设置,以默认值方式
 - # linestyle = '' linestyle = 'none' 表示无格式,无线条
 - plt.plot([4,2,1,3],linestyle = 'none',
 - marker = 'o',
 - markersize = 30,
 - # edge
 - markeredgecolor = 'r',
 - markeredgewidth = 5,
 - # face
 - markerfacecolor = 'g',
 - # markerfacecolor = 'none',
 - # markerfacecolor = None,
 - )
 
[
综合:带有空心圆标记的线条图
- '''
 - 标记点是覆盖在线条的上面,位于上层
 - 图层层次:[top] spines > marker > line > backgroud [bottom]
 - spines:轴的4个边框
 - spines 将线条图围在里面
 - '''
 - plt.plot([1,5,3,4],
 - marker = 'o',
 - markersize = 20,
 - # edge
 - markeredgecolor = 'r',
 - markeredgewidth = 5,
 - # face
 - markerfacecolor = 'w', # 白色,与背景色相同,把线条覆盖着,营造空心的视觉效果
 - # markerfacecolor = 'none', # 无色,透明,会看到线条
 - # markerfacecolor = None, # 不设置,默认颜色
 - )
 - # markerfacecolor = ' ', # 无法识别
 - # markerfacecolor = '', # 无法识别
 
[
data关键字的使用
字典数据
- #字典数据
 - d = {'name':list('abcd'),'age':[22,20,18,27]}
 - plt.plot('name','age',ddata = d)
 
[
DataFrame数据
- #DataFrame数据
 - d = {'name':list('abcd'),'age':[22,20,18,27]}
 - df = pd.DataFrame(d)
 - df
 
| name | age | |
|---|---|---|
| 0 | a | 22 | 
| 1 | b | 20 | 
| 2 | c | 18 | 
| 3 | d | 27 | 
- plt.plot('name','age',data = df)
 
[
总结
定义:
调用:
x,y,fmt均不能使用关键字传参
推荐使用:
                网站题目:超详解matplotlib中的折线图方法plot()
                
                网站URL:http://www.csdahua.cn/qtweb/news0/555350.html
            
网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 快上网