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)
)
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.
Thanks !
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))
Following the transforms tutorial, the simplest way is to use ax.transLimits
.
output_coords = ax.transLimits.transform(input_coords)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With