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的更多相关文章

  1. UnderStand Perspective Rasterization, SV_POSITION(gl_FragCoord) to Pixel, SV mean Systems Value

    Shader "UnderStandPRR" { Properties { _MainTex ("Texture", 2D) = "white&quo ...

  2. Unity UGUI图文混排(五) -- 一张图集对应多个Text

    继上一篇说的更新了一张图集对应多个Text的功能,为了节省资源嘛 这里,但是也没有舍弃之前的一个Text一个图集,因为我感觉应该两个都有用,于是我重新写了一个脚本 1.其实大体跟前面的都没变,解析标签 ...

  3. 【论文速读】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 ...

  4. [UGUI]图文混排(二):Text源码分析

    UGUI源码: https://bitbucket.org/Unity-Technologies/ui/downloads/?tab=tags 首先下载一份UGUI源码,这里我下载的版本是5.3.2f ...

  5. Quartz2D Text

    [Quartz2D Text] Quartz 2D provides a limited, low-level interface for drawing text encoded in the Ma ...

  6. 使用Python一步一步地来进行数据分析总结

    原文链接:Step by step approach to perform data analysis using Python译文链接:使用Python一步一步地来进行数据分析--By Michae ...

  7. 数据可视化(4)--jqplot

    本来打算继续研究Google Charts,但上头下了指示让看jqplot,无奈,只好先将Google Charts放一放,不过真心觉得Google Charts不错,现在先开始jqplot. jqP ...

  8. 扩展卡尔曼滤波(MRPT)

    EKF relies on a linearisation of the evolution and observation functions which are good approximatio ...

  9. 烟大 Contest1024 - 《挑战编程》第一章:入门 Problem E: Graphical Editor(模拟控制台命令形式修改图形)

    Problem E: Graphical Editor Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 2  Solved: 2[Submit][Statu ...

随机推荐

  1. 微信小程序监听input输入并取值

    小程序的事件分为两种,冒泡和非冒泡事件,像<form/>的submit事件,<input/>的input事件,<scroll-view/>的scroll事件等非冒泡 ...

  2. JS中const、var 和let的区别

    今天第一次遇到const定义的变量,查阅了相关资料整理了这篇文章.主要内容是:js中三种定义变量的方式const, var, let的区别. 1.const定义的变量不可以修改,而且必须初始化. 1 ...

  3. oracle数据泵备份与恢复库

    假如  导出库的用户名是tiger,密码是1  导入到用户名是scott,密码是1 备份库 expdp tiger/1@orcl dumpfile=expdp.dmp DIRECTORY=dpdata ...

  4. TypeScript笔记 6--接口

    接口定义 接口和Java语言一样,都是通过关键字interface定义的,如下例子: interface People { name: string; age: number; hobby?: str ...

  5. 修改织梦默认栏目页、文章页URL命名规则,简化目录结构

    版权声明:本文为博主原创文章,未经博主允许不得转载. 用织梦Dedecms建站,建议优化系统默认的URL结构,这样能简化网站目录深度,利于搜索引擎收录. 现在织梦的默认文章命名规则是 {typedir ...

  6. Win7如何分享局域网并设置共享文件夹账户和密码

    https://jingyan.baidu.com/article/ceb9fb10ddf6c08cad2ba017.html 在办公或者其他场所,我们需要分享自己的文件给朋友或者同事,但又不想同一局 ...

  7. DOS基本命令(基本部分)

    一.cls(clear screen的简写) 命令作用:清屏屏幕 详细介绍:屏幕显示的所有字符信息都是存放在一个屏幕缓冲区中,cls命令的作用是清除屏幕上的文字,并将该缓冲区清空. 二.dir(dir ...

  8. MyBatis动态传入表名,字段名参数的解决办法

    原文:http://blog.csdn.net/xichenguan/article/details/50393748 要实现动态传入表名.列名,需要做如下修改 添加属性statementType=& ...

  9. Python中执行系统命令常见的几种方法

    (1) os.system 这个方法是直接调用标准C的system() 函数,仅仅在一个子终端运行系统命令,而不能获取命令执行后的返回信息. import os os.system('cat /pro ...

  10. 转:Python之路,Day6 - 面向对象学习

    这篇文章写的不错,转来收了 转自:http://www.cnblogs.com/alex3714/articles/5188179.html   本节内容:   面向对象编程介绍 为什么要用面向对象进 ...