import numpy as np

import matplotlib.pyplot as plt

from pylab import *

numpy 常用来组织源数据: 使用 plot 函数直接绘制上述函数曲线,

可以通过配置 plot 函数参数调整曲线的样式、粗细、颜色、标记等:

曲线图:matplotlib.pyplot.plot(data)

灰度图:matplotlib.pyplot.hist(data)

散点图:matplotlib.pyplot.scatter(data)

箱式图:matplotlib.pyplot.boxplot(data)

# 定义数据部分 x = np.arange(0., 10, 0.2) y1 = np.cos(x) y2 = np.sin(x) y3 = np.sqrt(x)

# 绘制 3 条函数曲线

plt.plot(x, y1, color='blue', linewidth=1.5, linestyle='-', marker='.', label=r'$y = cos{x}$')

plt.plot(x, y2, color='green', linewidth=1.5, linestyle='-', marker='*', label=r'$y = sin{x}$')

plt.plot(x, y3, color='m', linewidth=1.5, linestyle='-', marker='x', label=r'$y = \sqrt{x}$')

# 坐标轴上移

ax = plt.subplot(111) ax.spines['right'].set_color('none')

# 去掉右边的边框线 ax.spines['top'].set_color('none')       # 去掉上边的边框线

# 移动下边边框线,相当于移动 X 轴

#ax.xaxis.set_ticks_position('bottom')

#ax.spines['bottom'].set_position(('data', 0))

# 移动左边边框线,相当于移动 y 轴

#ax.yaxis.set_ticks_position('left')

#ax.spines['left'].set_position(('data', 0))

# 设置 x, y 轴的取值范围 #plt.ylim(-1.5, 4.0)

# 设置 x, y 轴的刻度值

plt.xticks([2, 4, 6, 8, 10], [r'2', r'4', r'6', r'8', r'10']) plt.yticks([-1.0, 0.0, 1.0, 2.0, 3.0, 4.0],     [r'-1.0', r'0.0', r'1.0', r'2.0', r'3.0', r'4.0'])

# 添加文字

plt.text(8, 2, r'$x \in [0.0, \ 10.0]$', color='k', fontsize=15) plt.text(8, 1, r'$y \in [-1.0, \ 4.0]$', color='k', fontsize=15)

# 特殊点添加注解

plt.scatter([8,8],[2,2.8], 300, color ='m')  # 使用散点图放大当前点

#plt.annotate(r'$2\sqrt{2}$', xy=(8, np.sqrt(8)), xytext=(8.5, 2.2), fontsize=16, color='#090909', arrowprops=dict(arrowstyle='->', connectionstyle='arc3, rad=0.1', color='#090909'))

# 设置标题、x轴、y轴

plt.title(r'$the \ function \ figure \ of \ cos(), \ sin() \ and \ sqrt()$', fontsize=19)

plt.xlabel(r'$the \ input \ value \ of \ x$', fontsize=18, labelpad=88.8)

plt.ylabel(r'$y = f(x)$', fontsize=18, labelpad=12.5)

# 设置图例及位置 plt.legend(loc='up right')

# plt.legend(['cos(x)', 'sin(x)', 'sqrt(x)'], loc='up right')

# 显示网格线 plt.grid(True)

# 显示绘图 plt.show()

python matplotlib 画图的更多相关文章

  1. python matplotlib画图产生的Type 3 fonts字体没有嵌入问题

    ScholarOne's 对python matplotlib画图产生的Type 3 fonts字体不兼容,更改措施: 在程序中添加如下语句 import matplotlib matplotlib. ...

  2. 用python matplotlib 画图

    state-machine environment object-oriente interface figure and axes backend and frontend user interfa ...

  3. 使用python中的matplotlib 画图,show后关闭窗口,继续运行命令

    使用python中的matplotlib 画图,show后关闭窗口,继续运行命令 在用python中的matplotlib 画图时,show()函数总是要放在最后,且它阻止命令继续往下运行,直到1.0 ...

  4. python使用matplotlib画图

    python使用matplotlib画图 matplotlib库是python最著名的画图库.它提供了一整套和matlab类似的命令API.十分适合交互式地进行制图. 先介绍了怎样使用matplotl ...

  5. python使用matplotlib画图,jieba分词、词云、selenuium、图片、音频、视频、文字识别、人脸识别

    一.使用matplotlib画图 关注公众号"轻松学编程"了解更多. 使用matplotlib画柱形图 import matplotlib from matplotlib impo ...

  6. 使用Python matplotlib做动态曲线

    今天看到“Python实时监控CPU使用率”的教程: https://www.w3cschool.cn/python3/python3-ja3d2z2g.html 自己也学习如何使用Python ma ...

  7. matplotlib 画图

    matplotlib 画图 1. 画曲线图       Tompson = np.array([0, 0, 0, 0, 0.011, 0.051, 0.15, 0.251, 0.35, 0.44, 0 ...

  8. matplotlib画图

    matplotlib画图 import numpy as np import matplotlib.pyplot as plt x1=[20,33,51,79,101,121,132,145,162, ...

  9. python seaborn 画图

    python seaborn 画图 59888745@qq.com 2017.08.02 distplot( )  kdeplot( ) distplot( )为hist加强版, kdeplot( ) ...

随机推荐

  1. IIS7虚拟目录出现HTTP错误500.19(由于权限不足而无法读取配置文件)的解决方案

    今天在window7上配置asp.net网站,但是访问总是提示 错误摘要HTTP 错误 500.19 - Internal Server Error无法访问请求的页面,因为该页的相关配置数据无效.详细 ...

  2. mysql快速移植表数据

    使用select into outfile xxx ,  load data infile xxx 例如 : SELECT * into outfile '/tmp/out.txt' FROM `db ...

  3. C++的坑真的多吗?

    先说明一下,我不希望本文变成语言争论贴.希望下面的文章能让我们客观理性地了解C++这个语言.(另,我觉得技术争论不要停留在非黑即白的二元价值观上,这样争论无非就是比谁的嗓门大,比哪一方的观点强,毫无价 ...

  4. java基础知识总结(二)

    +=隐含了强制类型转换. x+=y;等价与:x = (x的数据类型)(x + y); 函数重载? 函数名同样.參数列表不同.跟返回值不关,就是函数重载 封装是什么? 隐藏对象的属性和详细的实现细节,仅 ...

  5. DVWA安装——一个菜鸟的入门教程

    DVWA的安装非常简单: 1.更改config/config.inc.php文件中的数据库配置信息 2.访问setup.php,点击create/reset database即可 3.默认用户名/密码 ...

  6. Echarts 新认知 地图的label到底怎么居中?

    试过了offset和很多Api,都无法实现label居中 后来无意中发现,原来在geojson注册的时候,可以定义 properties.cp 属性,实现文本的坐标自定义,实现居中. echarts. ...

  7. application配置和profile隔离配置(转)

    前言 github: https://github.com/vergilyn/SpringBootDemo 说明:我代码的结构是用profile来区分/激活要加载的配置,从而在一个project中写各 ...

  8. 全相FFT

    作者:桂. 时间:2017-12-02  23:29:48 链接:http://www.cnblogs.com/xingshansi/p/7956491.html 一.相位提取 以正弦信号为例,x = ...

  9. “TableDetails”中列“IsPrimaryKey”的值为DBNull. Mysql EntityFramework

                                                                                Entity Framework连接MySQL时 ...

  10. activiti设置流程变量

    public static void mian(String args[]){ ProcessEngine processEngine  = ProcessEngine.getDefaultProce ...