Text

为plots添加文本或者公式,反正就是添加文本了

参考链接:https://matplotlib.org/api/_as_gen/matplotlib.pyplot.text.html#matplotlib.pyplot.text

参考链接(应用):https://matplotlib.org/tutorials/text/text_intro.html#sphx-glr-tutorials-text-text-intro-py

补充:

  获取设置的text:

  参考链接:https://matplotlib.org/3.1.1/api/text_api.html

  get_text:

print( frames_names['text%s'%algorithm_list[i].__name__].get_text)#注意没加括号也能

  

  

  get_text()

print( frames_names['text%s'%algorithm_list[i].__name__].get_text())

  

简单使用:(更多例子见应用)

#参数介绍:
matplotlib.pyplot.text(x, y, s, fontdict=None, withdash=<deprecated parameter>, **kwargs)
s:添加的文本
time_text = ax.text(0.1, 0.9, '', transform=ax.transAxes)
#替换文本时可以
time_text.set_text(time_template %(0.1*i))
其中time_template = 'time = %.1fs',这样是为了替换时方便一些,若是只添加一次的话,直接在上面写全就好

出现的问题:

*)下面代码不显示添加的text,最后查看原因发现是axs.cla()的原因,所以在animate里直接添加axs.text(....)

time_template='time=%.2fs'
time_text=axs.text(0.1,0.90,"",transform=axs.transAxes)
# def init():
# time_text.set_text("")
# return time_text
frames=bidirectional_bubble_sort(original_data_object)
def animate(fi):
bars=[]
if len(frames)>fi:
axs.cla()
# axs.text(0.1,0.90,time_template%(0.1*fi),transform=axs.transAxes)#所以这样
time_text.set_text(time_template%(0.1*fi))#这个必须没有axs.cla()才行 axs.set_title('bubble_sort_visualization')
axs.set_xticks([])
axs.set_yticks([])
bars=axs.bar(list(range(Data.data_count)),#个数
[d.value for d in frames[fi]],#数据
1, #宽度
color=[d.color for d in frames[fi]]#颜色
).get_children()
return bars
anim=animation.FuncAnimation(fig,animate,frames=len(frames), interval=frame_interval,repeat=False)

  

transform

transform就是转换的意思,是不同坐标系的转换

参考链接:https://matplotlib.org/users/transforms_tutorial.html

拿上面的例子来讲,在为plots添加text时,就用到了坐标转换

xs.text(0.1,0.90,time_template%(0.1*fi),transform=axs.transAxes)#这里的,transform=axs.transAxes就是轴坐标,大概意思就是左边距离横坐标轴长的0.1倍,下面距离纵坐标轴的0.90倍,如果不写的话默认就是data坐标
,即0.1代表横轴的0.1个单位,即坐标点

  

Python 绘图与可视化 matplotlib text 与transform的更多相关文章

  1. Python 绘图与可视化 matplotlib(下)

    详细的参考链接:更详细的:https://www.cnblogs.com/zhizhan/p/5615947.html 图像.子图.坐标轴以及记号 Matplotlib中图像的意思是打开的整个画图窗口 ...

  2. Python 绘图与可视化 matplotlib 动态条形图 bar

    bar的参考链接:https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.bar.html 第一种办法 一种方法是每次都重新画,包括清除f ...

  3. Python 绘图与可视化 matplotlib(上)

    参考链接:https://www.cnblogs.com/dudududu/p/9149762.html 更详细的:https://www.cnblogs.com/zhizhan/p/5615947. ...

  4. Python 绘图与可视化 matplotlib 制作Gif动图

    参考链接:https://blog.csdn.net/theonegis/article/details/51037850 官方文档:https://matplotlib.org/3.1.0/api/ ...

  5. Python 绘图与可视化 matplotlib 散点图、numpy模块的random()

    效果: 代码: def scatter_curve(): # plt.subplot(1,1,1) n=1024 X=np.random.normal(0,1,n) Y=np.random.norma ...

  6. Python 绘图与可视化 matplotlib 填充fill和fill_between

    参考链接:https://blog.csdn.net/You_are_my_dream/article/details/53457960 fill()填充函数曲线与坐标轴之间的区域: x = np.l ...

  7. Python绘图与可视化

    Python有很多可视化工具,本篇只介绍Matplotlib. Matplotlib是一种2D的绘图库,它可以支持硬拷贝和跨系统的交互,它可以在Python脚本.IPython的交互环境下.Web应用 ...

  8. IPython绘图和可视化---matplotlib 入门

    最近总是需要用matplotlib绘制一些图,由于是新手,所以总是需要去翻书来找怎么用,即使刚用过的,也总是忘.所以,想写一个入门的教程,一方面帮助我自己熟悉这些函数,另一方面有比我还小白的新手可以借 ...

  9. 绘图和可视化---matplotlib包的学习

    matplotlib API函数都位于matplotlib.pyplot模块,通常引入约定为:import matplotlib.pyplot as plt 1.Figure和Subplot 图像都位 ...

随机推荐

  1. 4、Work-Queue

    Work Queues using the Java Client In the first tutorial we wrote programs to send and receive messag ...

  2. jmeter压测学习7-登录参数化(CSV 数据文件设置)

    前言 我们在压测登录接口的时候,如果只用一个账号去设置并发压测,这样的结果很显然是不合理的,一个用户并发无法模拟真实的情况. 如果要压测登录接口,肯定得准备几百,甚至上千的账号去登录,测试的结果才具有 ...

  3. Celery详解(3)

    1.什么是Celery? Celery是一个简单.灵活且可靠的,处理大量消息的分布式系统 专注于实时处理的异步任务队列,同时也支持任务调度 2.Celery架构 Celery的架构由三部分组成,消息中 ...

  4. 201871010109-胡欢欢《面向对象程序设计(java)》第十三周学习总结

    项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/nwnu-daizh/p ...

  5. git npm包管理

    #Node # node 一.安装nodejs 下载地址:http://nodejs.cn/download/ 二.安装git 下载地址:https://git-scm.com/download/wi ...

  6. 微信小程序特性总结

    一. 小程序不是运行在浏览器中, 所以没有BOM和DOM对象 即console.log(window)和console.log(document)是获取不到任何内容的 二. 小程序特有的额外js成员( ...

  7. 【day04】css

    一.CSS2.0[Cascading Style Sheets]层叠样式表  1.什么是CSS:修饰网页元素(标记)外观(比如给文字加颜色,大小,字体)的,W3C规定尽量用CSS样式替代XHTML属性 ...

  8. 洛谷 P1016 旅行者的预算

    传送门 感觉自己连点生活常识都没有,竟然连油用过之后要减去都不知道,这种贪心模拟题都做不出来--思路在代码里,我菜死了 思路&&代码 //看题解过的..一点都没有成就感 #includ ...

  9. [LeetCode] 896. Monotonic Array 单调数组

    An array is monotonic if it is either monotone increasing or monotone decreasing. An array A is mono ...

  10. [LeetCode] 272. Closest Binary Search Tree Value II 最近的二分搜索树的值之二

    Given a non-empty binary search tree and a target value, find k values in the BST that are closest t ...