matplotlib绘图基础--3
来源:互联网 发布:杭州erp软件开发 编辑:程序博客网 时间:2024/06/07 08:25
pyplot允许你在图表的任意位置添加文本。这个功能由text()实现
text(x,y,s,fontdict=None,**kwargs)
前两个参数为文本在图形中的位置坐标。s为要添加的字符串,fontdict为文本要使用的字体
In [6]:plt.axis([0,5,0,20])
…:plt.title("My First Plot",fontsize=20,fontname="Times NewRoman")
…: plt.xlabel("Counting",color='green')
…: plt.ylabel("SquareValues",color='gray')
…:plt.text(1,1.5,'First')
:plt.text(2,4.5,'Second')
…:plt.text(3,9.5,'Third')
…:plt.text(4,16.5,'Fourth')
…:plt.plot([1,2,3,4],[1,4,9,16],'ro')
…: plt.show()
matplotlib不仅有如此,而且还整合了LaTeX表达式,支持在图表中插入数学表达式。
将表达式置于两个$符号之间,可在文本中添加LaTeX表达式。解释器会将该符号之间的文本识别成LaTeX表达式,将他们转换为数学表达式、公式、数学符号或希腊字母等,然后在图像中显示出来。
例如,添加描述图形各数据点趋势的公式,并为公式添加一个彩色边框。
In [17]: plt.axis([0,5,0,20])
...: plt.title("My FirstPlot",fontsize=20,fontname="Times New Roman")
...: plt.xlabel("Counting",color='green')
...: plt.ylabel("Square Values",color='gray')
...: plt.text(1,1.5,'First')
...: plt.text(2,4.5,'Second')
...: plt.text(3,9.5,'Third')
...: plt.text(4,16.5,'Fourth')
...: plt.text(1.1,12,r'$y=x^2$',fontsize=20,bbox={'facecolor':'yellow','alpha':0.2})
...: plt.plot([1,2,3,4],[1,4,9,16],'ro')
...:
Out[17]: [<matplotlib.lines.Line2D at0x9576828>]
In [18]: plt.show()
添加网格
在图表中添加网格直接在代码中加入grid()函数,穿入参数为True
plt.grid(True)
即可实现
- matplotlib绘图基础--3
- matplotlib绘图基础
- matplotlib绘图基础
- matplotlib绘图基础
- matplotlib绘图基础
- matplotlib绘图基础--1
- matplotlib绘图基础--2
- matplotlib绘图基础
- matplotlib绘图基础--笔记
- [053]matplotlib绘图基础
- matplotlib 2D绘图基础
- Matplotlib基础绘图函数示例
- matplotlib学习之绘图基础
- matplotlib学习之绘图基础
- matplotlib学习之绘图基础
- matplotlib学习之绘图基础
- matplotlib学习之绘图基础
- Python3.绘图基础matplotlib.pyplot
- 将图片做成视频文件
- Python-day10
- Spring Cloud构建微服务架构(四)分布式配置中心
- 使用angularjs,bootstrap快速实现手风琴效果
- 在SD卡中寻找指定类型文件的方法
- matplotlib绘图基础--3
- 开发者论坛一周精粹(第九期)
- BZOJ2976: [Poi2002]出圈游戏
- Spring深入理解之一,从概念开始
- 程序员必读的五本书籍
- extern C的作用详解
- java并发编程(五)--Java中的锁(读写锁ReentrantReadWriteLock)
- JAVA内存区域与内存溢出相关设置
- linux jenkins 自动化部署工具安装