Getting the pixel coordinates of text or ticks in matplotlib
The exact pixel coordinates of title, labels, legends or ticks are important information for the training data of deep learning.
import numpy as np
import matplotlib.pyplot as plt plt.plot([1,2],label="first_image")
plt.plot([2,1],label="second_image")
leg = plt.legend() tit = plt.title("sss")
xla = plt.xlabel("xxx") plt.gcf().canvas.draw()
ticks = [t for t in plt.gca().get_xticklabels()] print(tit.get_text(),str(tit.get_window_extent())) # return the context and pixel coordinates of 'tit'
print(np.array(tit.get_window_extent()))
print(xla.get_text(),str(xla.get_window_extent())) for i, t in enumerate(ticks):
print ("Label "+str(i)+", data: "+t.get_text()+str(t.get_window_extent())) print ("Legend location: "+str(leg.get_window_extent()))
for i, l in enumerate(leg.texts):
print ("Label "+str(i)+", data: "+l.get_text()+str(l.get_window_extent()))
pass
#plt.savefig("test.png")
plt.show()
sss Bbox(x0=211.8375, y0=256.44, x1=230.9625, y1=269.44)
[[ 211.8375 256.44 ]
[ 230.9625 269.44 ]]
xxx Bbox(x0=212.5875, y0=5.0, x1=230.2125, y1=15.0)
Label 0, data: Bbox(x0=69.21818181818182, y0=29.0, x1=69.21818181818182, y1=29.0)
Label 1, data: 0.0Bbox(x0=61.21818181818182, y0=19.0, x1=77.21818181818182, y1=29.0)
Label 2, data: 0.2Bbox(x0=122.0909090909091, y0=19.0, x1=138.0909090909091, y1=29.0)
Label 3, data: 0.4Bbox(x0=182.9636363636364, y0=19.0, x1=198.9636363636364, y1=29.0)
Label 4, data: 0.6Bbox(x0=243.83636363636367, y0=19.0, x1=259.83636363636367, y1=29.0)
Label 5, data: 0.8Bbox(x0=304.70909090909095, y0=19.0, x1=320.70909090909095, y1=29.0)
Label 6, data: 1.0Bbox(x0=365.5818181818182, y0=19.0, x1=381.5818181818182, y1=29.0)
Label 7, data: Bbox(x0=69.21818181818182, y0=29.0, x1=69.21818181818182, y1=29.0)
Legend location: Bbox(x0=276.05, y0=127.31375, x1=383.8, y1=162.12625)
Label 0, data: first_imageBbox(x0=308.05, y0=147.22, x1=363.925, y1=158.12625)
Label 1, data: second_imageBbox(x0=308.05, y0=131.31375, x1=379.8, y1=142.22)
reference:
1. https://matplotlib.org/api/text_api.html#matplotlib.text.Annotation.get_window_extent
2. https://matplotlib.org/api/transformations.html#matplotlib.transforms.Bbox
Getting the pixel coordinates of text or ticks in matplotlib的更多相关文章
- UnderStand Perspective Rasterization, SV_POSITION(gl_FragCoord) to Pixel, SV mean Systems Value
Shader "UnderStandPRR" { Properties { _MainTex ("Texture", 2D) = "white&quo ...
- Unity UGUI图文混排(五) -- 一张图集对应多个Text
继上一篇说的更新了一张图集对应多个Text的功能,为了节省资源嘛 这里,但是也没有舍弃之前的一个Text一个图集,因为我感觉应该两个都有用,于是我重新写了一个脚本 1.其实大体跟前面的都没变,解析标签 ...
- 【论文速读】Chuhui Xue_ECCV2018_Accurate Scene Text Detection through Border Semantics Awareness and Bootstrapping
Chuhui Xue_ECCV2018_Accurate Scene Text Detection through Border Semantics Awareness and Bootstrappi ...
- [UGUI]图文混排(二):Text源码分析
UGUI源码: https://bitbucket.org/Unity-Technologies/ui/downloads/?tab=tags 首先下载一份UGUI源码,这里我下载的版本是5.3.2f ...
- Quartz2D Text
[Quartz2D Text] Quartz 2D provides a limited, low-level interface for drawing text encoded in the Ma ...
- 使用Python一步一步地来进行数据分析总结
原文链接:Step by step approach to perform data analysis using Python译文链接:使用Python一步一步地来进行数据分析--By Michae ...
- 数据可视化(4)--jqplot
本来打算继续研究Google Charts,但上头下了指示让看jqplot,无奈,只好先将Google Charts放一放,不过真心觉得Google Charts不错,现在先开始jqplot. jqP ...
- 扩展卡尔曼滤波(MRPT)
EKF relies on a linearisation of the evolution and observation functions which are good approximatio ...
- 烟大 Contest1024 - 《挑战编程》第一章:入门 Problem E: Graphical Editor(模拟控制台命令形式修改图形)
Problem E: Graphical Editor Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 2 Solved: 2[Submit][Statu ...
随机推荐
- PHPStorm+PHPStudy新建第一个PHP项目
img { max-width: 100% } 熟悉了.net的编程,偶尔也来客串一下PHP.前几天闲来无事随便加了一个PHP的开发群,入群之后傻眼了,群里有大小各位程工1600多人,所以决定学习一下 ...
- PHP defined() 函数
定义和用法 defined() 函数检查某常量是否存在. 若常量存在,则返回 true,否则返回 false. 语法 defined(name) 参数 描述 name 必需.规定要检查的常量的名称. ...
- JavaScript实现Tab栏切换
本文最初发表于博客园,并在GitHub上持续更新前端的系列文章.欢迎在GitHub上关注我,一起入门和进阶前端. 以下是正文. 京东网页上,可以看到下面这种tab栏的切换: 我们把模型抽象出来,实现一 ...
- es6重点笔记:Symbol,Set,Map,Proxy,Reflect
一,Symbol 原始数据类型,不是对象,它是JavaScript第七种数据类型,表示独一无二的值.Symbol是通过Symbol函数生成的: let s = Symbol(); typeof s / ...
- css scale放大缩小
.product-content ul li a img:hover{ transform: scale(1.1); }
- JSP之JSTL_functions
<?xml version="1.0" encoding="UTF-8" ?> <taglib xmlns="http://java ...
- ajax请求返回乱码
1,web.xml中有如下配置: <!-- 编码过滤器 --> <filter> <filter-name>encodingFilter</filter-na ...
- Log4j源码解析--Appender接口解析
本文转自上善若水的博客,原文出处:http://www.blogjava.net/DLevin/archive/2012/07/10/382676.html.感谢作者的无私的分享. Appender负 ...
- VMware PowerCLi 使用示例
这几天研究PowerCLI,积累了几个例子,记下来,以便以后或者大家使用.部分例子来着网络,具体出处参考附录 1 获取vm 磁盘 和磁盘对应的datastore的信息 这个例子可以针对一台虚机有多个磁 ...
- Tomcat服务器的Web安全的解决方法
.概述 在任何一种WEB应用开发中,不论大中小规模的,每个开发者都会遇到一些需要保护程序数据的问题,涉及到用户的LOGIN ID和PASSWORD.那么如何执行验证方式更好呢?实际上,有很多方式来实现 ...