Python/Matplotlib:转换轴 <=>数据坐标系 [英] Python/Matplotlib : convert Axis &lt;=&gt; Data coordinates systems

查看:90
本文介绍了Python/Matplotlib:转换轴 <=>数据坐标系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题很简单:在matplotlib中,如何轻松地将Axis系统中的坐标转换为Data System中的坐标?(理想情况下,我正在寻找一个简单的函数 output_coords = magic_func(input_coords))

My question is quite simple : in matplotlib, how can I easily convert coordinates in Axis system to/from Data system (Ideally I'm looking for a simple function output_coords = magic_func(input_coords) )

实际上我的确切问题是:我想绘制一个 matplotlib.patches.Ellipse ,他的中心在 Axis 系统中,但他的大小(宽度和长度)在数据系统中.但是 transforms.blended_transform_factory 方法在这种情况下不起作用.

Actually my exact problem is : I'd like to plot an matplotlib.patches.Ellipse with his center in Axis system but his size (width & length) in Data system. But the transforms.blended_transform_factory method doesn't work in this case.

谢谢!

推荐答案

要从 Axes 实例 ax 获取转换,您可以使用

To get transformations from the Axes instance ax, you can use

axis_to_data = ax.transAxes + ax.transData.inverted()
points_data = axis_to_data.transform(points_axis)
data_to_axis = axis_to_data.inverted()
numpy.testing.assert_allclose(points_axis, data_to_axis.transform(points_data))

这篇关于Python/Matplotlib:转换轴 <=>数据坐标系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆