Matplotlib中使用get和set axis方法的相对坐标

编程入门 行业动态 更新时间:2024-10-25 00:28:03
本文介绍了Matplotlib中使用get和set axis方法的相对坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

一种控制新的 axes 应该在 figure 对象中的位置的方法是使用 add_axes 方法.此方法接受一个包含 4 个值的列表或元组,这些值代表 [左、底部、宽度、高度],其中所有数量都是图形宽度和高度的分数.例如:

One way to control where in the figure object a new axes is supposed to go is by using the add_axes method. This method takes in a list or tuple of 4 values which represent [left, bottom, width, height] where all quantities are in fractions of figure witdth and height. For example:

import matplotlib fig = plt.figure() fig.add_axes([0.1,0.2,0.3, 0.4])

在指定的相对坐标中添加一个新的 axes 对象.如果我继续尝试提取这些坐标:

Adds a new axes object in the specified relative coordinates. If I then go on to try to extract these coordinates:

fig.axes[0].get_position()

结果是一个 Bbox 对象:

>>> Bbox([[0.1, 0.2], [0.4, 0.6000000000000001]])

问题是我不需要Bbox对象,我想找回我的相对坐标,这样我就可以使用 set_axes 对其进行操作了(它再次接受了左侧,底部宽度和高度)以重新定位我的坐标轴.

The issue is I don't want a Bbox object, I want to get my relative coordinates back so that I can operate on them using set_axes (which takes in left, bottom width and height again) to relocate my axes.

反正有没有将 Bbox 转换为我需要的格式,或者可能是强制 get_position()方法吐出相对坐标?>

Is there anyway to convert the Bbox to the format that I need, or perhaps to force the get_position() method to spit out relative coordinates like so?

[0.1,0.2,0.3,0.4]

推荐答案

图的 add_axes 方法将 rect

add_axes(* args,** kwargs) 在 rect [left, bottom, width, height]

axes.get_position()返回 BBox 对象.从其文档中可以看到,该属性

axes.get_position() returns a BBox object. This has, as seen from its documentation, a property

界限 (属性)返回(x0, y0, width, height).

所以你想打电话

ax.get_position().bounds

获取轴矩形的边界.

更多推荐

Matplotlib中使用get和set axis方法的相对坐标

本文发布于:2023-10-08 02:51:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1471296.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:坐标   方法   Matplotlib   set   axis

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!