MCPcopy Create free account
hub / github.com/matplotlib/matplotlib / ExtremeFinderSimple

Class ExtremeFinderSimple

lib/mpl_toolkits/axisartist/grid_finder.py:46–98  ·  view source on GitHub ↗

A helper class to figure out the range of grid lines that need to be drawn.

Source from the content-addressed store, hash-verified

44
45
46class ExtremeFinderSimple:
47 """
48 A helper class to figure out the range of grid lines that need to be drawn.
49 """
50
51 def __init__(self, nx, ny):
52 """
53 Parameters
54 ----------
55 nx, ny : int
56 The number of samples in each direction.
57 """
58 self.nx = nx
59 self.ny = ny
60
61 def __call__(self, transform_xy, x1, y1, x2, y2):
62 """
63 Compute an approximation of the bounding box obtained by applying
64 *transform_xy* to the box delimited by ``(x1, y1, x2, y2)``.
65
66 The intended use is to have ``(x1, y1, x2, y2)`` in axes coordinates,
67 and have *transform_xy* be the transform from axes coordinates to data
68 coordinates; this method then returns the range of data coordinates
69 that span the actual axes.
70
71 The computation is done by sampling ``nx * ny`` equispaced points in
72 the ``(x1, y1, x2, y2)`` box and finding the resulting points with
73 extremal coordinates; then adding some padding to take into account the
74 finite sampling.
75
76 As each sampling step covers a relative range of ``1/nx`` or ``1/ny``,
77 the padding is computed by expanding the span covered by the extremal
78 coordinates by these fractions.
79 """
80 tbbox = self._find_transformed_bbox(
81 _User2DTransform(transform_xy, None), Bbox.from_extents(x1, y1, x2, y2))
82 return tbbox.x0, tbbox.x1, tbbox.y0, tbbox.y1
83
84 def _find_transformed_bbox(self, trans, bbox):
85 """
86 Compute an approximation of the bounding box obtained by applying
87 *trans* to *bbox*.
88
89 See ``__call__`` for details; this method performs similar
90 calculations, but using a different representation of the arguments and
91 return value.
92 """
93 grid = np.reshape(np.meshgrid(np.linspace(bbox.x0, bbox.x1, self.nx),
94 np.linspace(bbox.y0, bbox.y1, self.ny)),
95 (2, -1)).T
96 tbbox = Bbox.null()
97 tbbox.update_from_data_xy(trans.transform(grid))
98 return tbbox.expanded(1 + 2 / self.nx, 1 + 2 / self.ny)
99
100
101class _User2DTransform(Transform):

Callers 2

curvelinear_test1Function · 0.90
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…