python matplotlib 画图
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 画图的更多相关文章
- python matplotlib画图产生的Type 3 fonts字体没有嵌入问题
ScholarOne's 对python matplotlib画图产生的Type 3 fonts字体不兼容,更改措施: 在程序中添加如下语句 import matplotlib matplotlib. ...
- 用python matplotlib 画图
state-machine environment object-oriente interface figure and axes backend and frontend user interfa ...
- 使用python中的matplotlib 画图,show后关闭窗口,继续运行命令
使用python中的matplotlib 画图,show后关闭窗口,继续运行命令 在用python中的matplotlib 画图时,show()函数总是要放在最后,且它阻止命令继续往下运行,直到1.0 ...
- python使用matplotlib画图
python使用matplotlib画图 matplotlib库是python最著名的画图库.它提供了一整套和matlab类似的命令API.十分适合交互式地进行制图. 先介绍了怎样使用matplotl ...
- python使用matplotlib画图,jieba分词、词云、selenuium、图片、音频、视频、文字识别、人脸识别
一.使用matplotlib画图 关注公众号"轻松学编程"了解更多. 使用matplotlib画柱形图 import matplotlib from matplotlib impo ...
- 使用Python matplotlib做动态曲线
今天看到“Python实时监控CPU使用率”的教程: https://www.w3cschool.cn/python3/python3-ja3d2z2g.html 自己也学习如何使用Python ma ...
- matplotlib 画图
matplotlib 画图 1. 画曲线图 Tompson = np.array([0, 0, 0, 0, 0.011, 0.051, 0.15, 0.251, 0.35, 0.44, 0 ...
- matplotlib画图
matplotlib画图 import numpy as np import matplotlib.pyplot as plt x1=[20,33,51,79,101,121,132,145,162, ...
- python seaborn 画图
python seaborn 画图 59888745@qq.com 2017.08.02 distplot( ) kdeplot( ) distplot( )为hist加强版, kdeplot( ) ...
随机推荐
- RSA加密异常
在利用RSA进行数据加密时,出现如下异常: Exception bytes at com.sun.crypto.provider.RSACipher.a(DashoA13*..) at com.sun ...
- Oracle 12C -- truncate的级联操作
在之前的版本中,存在外键约束时,无法直接truncate父表.在12C中,对truncate操作添加了级联操作特性. 前提是创建外键约束时,使用了"on delete casacde&quo ...
- appium简明教程(11)——使用resource id定位(仅支持安卓4.3以上系统)
上一节乙醇带大家了解了appium的定位策略.实际上appium的控件定位方式是完全遵守webdriver的mobile扩展协议的. 这一节将分享一下如何使用resource id来定位android ...
- php开启与关闭错误提示
windows系统开关php错误提示 如果不具备修改php.ini的权限,可以将如下代码加入php文件中: 代码如下 复制代码 ini_set("display_errors", ...
- 在ubuntu14系统中将redis-server设置为开机启动项
1.redis安装完成后(我装的是redis-3.0.7),修改配置文件redis.conf,修改的项目如下 注意:以下内容都是在root用户下进行操作的 gedit redis.conf打开文件进行 ...
- 记一次mysql的存储过程改写
最近在对公司以前的老项目做整理,发现以前同事在程序中许多模块都是多次调用几个分散的存储过程..这样做无疑消耗了连接池的连接数,甚至会导致连接不够的时候创建连接池导致数据库处理的消耗..以及到处调用连接 ...
- 3dmax,查看场景中所有材质
- [转] 在 Windows 中让任务栏时间显示“秒”
1.运行 regedit,按回车键进入注册表编辑器 2.定位到: HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explore ...
- Android Eclipse Libs 的 jar 源码查看 (或者新版本ADT无法查看jar的源码)
问题背景:在使用比较新的ADT的时候,无法导入Jar中的源码包查看源码.只好自己打开压缩包,实在恼火.在半年前,只好这样. 问题解决方案:我就以 " android-support-v4.j ...
- 批处理向FTP上传指定属性的文件 批处理增量备份的例子
使用windows批处理向FTP上传具有指定属性的文件,类似增量备份功能. 对一个目录里的几个文件自动上传FTP时只上传有归档属性的文件,然后FTP上传成功后自动清除(本机)刚上传文件的归档属性. 类 ...