MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _get_xy

Method _get_xy

lib/matplotlib/patches.py:4774–4834  ·  view source on GitHub ↗

Calculate the pixel position of given point.

(self, xy, s, axes=None)

Source from the content-addressed store, hash-verified

4772 self._annotation_clip = None
4773
4774 def _get_xy(self, xy, s, axes=None):
4775 """Calculate the pixel position of given point."""
4776 s0 = s # For the error message, if needed.
4777 if axes is None:
4778 axes = self.axes
4779
4780 # preserve mixed type input (such as str, int)
4781 x = np.array(xy[0])
4782 y = np.array(xy[1])
4783
4784 fig = self.get_figure(root=False)
4785 if s in ["figure points", "axes points"]:
4786 x = x * fig.dpi / 72
4787 y = y * fig.dpi / 72
4788 s = s.replace("points", "pixels")
4789 elif s == "figure fraction":
4790 s = fig.transFigure
4791 elif s == "subfigure fraction":
4792 s = fig.transSubfigure
4793 elif s == "axes fraction":
4794 s = axes.transAxes
4795
4796 if s == 'data':
4797 trans = axes.transData
4798 x = cbook._to_unmasked_float_array(axes.xaxis.convert_units(x))
4799 y = cbook._to_unmasked_float_array(axes.yaxis.convert_units(y))
4800 return trans.transform((x, y))
4801 elif s == 'offset points':
4802 if self.xycoords == 'offset points': # prevent recursion
4803 return self._get_xy(self.xy, 'data')
4804 return (
4805 self._get_xy(self.xy, self.xycoords) # converted data point
4806 + xy * self.get_figure(root=True).dpi / 72) # converted offset
4807 elif s == 'polar':
4808 theta, r = x, y
4809 x = r * np.cos(theta)
4810 y = r * np.sin(theta)
4811 trans = axes.transData
4812 return trans.transform((x, y))
4813 elif s == 'figure pixels':
4814 # pixels from the lower left corner of the figure
4815 bb = self.get_figure(root=False).figbbox
4816 x = bb.x0 + x if x >= 0 else bb.x1 + x
4817 y = bb.y0 + y if y >= 0 else bb.y1 + y
4818 return x, y
4819 elif s == 'subfigure pixels':
4820 # pixels from the lower left corner of the figure
4821 bb = self.get_figure(root=False).bbox
4822 x = bb.x0 + x if x >= 0 else bb.x1 + x
4823 y = bb.y0 + y if y >= 0 else bb.y1 + y
4824 return x, y
4825 elif s == 'axes pixels':
4826 # pixels from the lower left corner of the Axes
4827 bb = axes.bbox
4828 x = bb.x0 + x if x >= 0 else bb.x1 + x
4829 y = bb.y0 + y if y >= 0 else bb.y1 + y
4830 return x, y
4831 elif isinstance(s, transforms.Transform):

Callers 2

_check_xyMethod · 0.95

Calls 3

convert_unitsMethod · 0.80
get_figureMethod · 0.45
transformMethod · 0.45

Tested by

no test coverage detected