'''
将前面的知识进行练习
plot,scatter,legend等
'''
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import cm as cm
#定义数据
x = np.linspace(0.5, 3.5, 100)
y = np.sin(x)
y1 = np.random.rand(100) #scatter图
plt.scatter(x, y1, c = "0.25", label = "scatter figure") #plot图
plt.plot(x, y, ls = "--", lw = 2, label = "plot figure")
#以下蓝色代码未学,后面会讲
#some clean up(removing chartunk)
#turn the top spine and the right spine off
for spine in plt.gca().spines.keys():
if spine == "top" or spine == "right":
plt.gca().spines[spine].set_color("none")
#turn bottom tick for x-axis on
plt.gca().xaxis.set_ticks_position("bottom")
#set tick_line position of bottom #turn left tick for y-axis on
plt.gca().yaxis.set_ticks_position("left")
#set tick_line position of left #设置x,y的显示区间
plt.xlim(0, 4)
plt.ylim(-3, 3) #设置轴标签
plt.xlabel("x_axis")
plt.ylabel("y_axis") #设置x,y轴网格线
plt.grid(True,ls = ":", color = "r") #添加垂直参考线
plt.axhline(y = 0.0, c="r", ls="--",lw=2)
#添加参考区域
plt.axvspan(xmin=1.0, xmax=2.0, facecolor="y",alpha=0.3) #添加指向型注释文本
plt.annotate("maximum", xy=(np.pi/2, 1.0),xytext=((np.pi/2)+.15,1.5),weight="bold",color="r",arrowprops=dict(arrowstyle="->", connectionstyle="arc3",color="b"))
plt.annotate("", xy=(3.5, -2.98),xytext=((3.6,-2.70)), arrowprops=dict(arrowstyle="->", connectionstyle="arc3",color="b"))
#设置文本
plt.text(3.6,-2.7,"'|' is tickline", weight="bold",color="b")
plt.text(3.6,-2.95,"3.5 is ticklabel", weight="bold",color="b")
#设置标题
plt.title("structure of matplotlib")
#设置图例
plt.legend()
#显示图形
plt.show()

matplotlib学习日记(二)----图表组成练习的更多相关文章

  1. matplotlib学习日记(一)------图表组成元素

      1.使用函数绘制matplotlib的图表组成元素 (1)函数plot---变量的变化趋势 import matplotlib.pyplot as plt import numpy as np x ...

  2. Python学习日记(二十八) hashlib模块、configparse模块、logging模块

    hashlib模块 主要提供字符加密算法功能,如md5.sha1.sha224.sha512.sha384等,这里的加密算法称为摘要算法.什么是摘要算法?它又称为哈希算法.散列算法,它通过一个函数把任 ...

  3. matplotlib学习日记(十)-划分画布的主要函数

    (1)函数subplot()绘制网格区域中的几何形状相同的子区布局 import matplotlib.pyplot as plt import numpy as np '''函数subplot的介绍 ...

  4. matplotlib学习日记(十)-共享绘图区域的坐标轴

    (1)共享单一绘图区域的坐标轴 ''' 上一讲介绍了画布的划分,有时候想将多张图放在同一个绘图区域, 不想在每个绘图区域只绘制一幅图形,这时候借助共享坐标轴的方法实现在一个绘图区 绘制多幅图形的目的. ...

  5. matplotlib学习日记(九)-图形样式

    (一)刻度线定位器和刻度格式器的使用方法 import matplotlib.pyplot as plt import numpy as np from matplotlib.ticker impor ...

  6. matplotlib学习日记(八)----完善统计图

    (一)再说legend() import matplotlib.pyplot as plt import numpy as np x = np.arange(0, 2.1, 0.1) y = np.p ...

  7. matplotlib学习日记(七)---误差棒图

    (一)误差棒图----误差置信区间的表示 import matplotlib.pyplot as plt import numpy as np x = np.linspace(0.1, 0.6, 10 ...

  8. matplotlib学习日记(六)-箱线图

    (一)箱线图---由一个箱体和一对箱须组成,箱体是由第一个四分位数,中位数和第三四分位数组成,箱须末端之外的数值是离散群,主要应用在一系列测量和观测数据的比较场景 import matplotlib ...

  9. matplotlib学习日记(五)-各种饼状图的绘制

    (一)分裂式饼状图 import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np mpl.rcParams[& ...

随机推荐

  1. Linux 学习笔记03丨Linux文件系统、文件基本属性、目录处理及文件查看

    Chapter 2. 文件系统 2.1 Linux 系统目录结构 命令窗口下输入命令: $ ls /,能够看到根目录下的全部目录及文件 树状目录结构为: 最顶级的目录: / :根目录 / 是根目录,~ ...

  2. 配置Nginx 扩展实现图片剪裁

    在此之前需要安装ngx_http_image_filter_module,如果是采用的Docker的话可以看看我历史文章. 然后修改配置文件,增加几个location模块,配置如下,仅供参考 serv ...

  3. 【mq学习笔记】mq 过期文件删除机制

    broker不会关注这个文件上的消息是否全部被消费.默认每个文件的过期时间为72小时.

  4. C中memcpy函数用法

    1.函数原型 void *memcpy(void *destin,void *source,unsigned n); 其中, destin代表用于存储复制内容的目标数组,类型强制转换为void*指针. ...

  5. Spring Security + JJWT 实现 JWT 认证和授权

    关于 JJWT 的使用,可以参考之前的文章:JJWT 使用示例 一.鉴权过滤器 @Component public class JwtAuthenticationTokenFilter extends ...

  6. Python中动态编译函数compile(source, filename, mode, ......)参数filename的作用是什么?

    动态编译函数compile调用语法如下: compile(source, filename, mode, flags=0, dont_inherit=False, optimize=-1) 其中的fi ...

  7. 转:浅析windows下字符集和文件编码存储/utf8/gbk

    最近老猿在学习文件操作及网络爬虫相关知识,发现字符集及编码的处理非常重要,而老猿原来对此了解并不多,因此找了几篇文章看了一下,将老猿认为比较的相关文章转载一下.感谢各位原创大神! 1,字符集 这里主要 ...

  8. 第9章 Python文件操作目录

    第9章 Python文件操作 第9.1节 Python的文件打开函数open简介 第9.2节 Python的文件打开函数open详解 第9.3节 Python的文件行读取:readline 第9.4节 ...

  9. PyQt(Python+Qt)学习随笔:QTreeView树形视图的uniformRowHeights属性

    老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 uniformRowHeights属性用于控制视图中所有数据项是否保持相同高度,所有高度都与视图中第 ...

  10. python安装Scrapy框架

    看到自己写的惨不忍睹的爬虫,觉得还是学一下Scrapy框架,停止一直造轮子的行为 我这里是windows10平台,python2和python3共存,这里就写python2.7安装配置Scrapy框架 ...