Control handles for canvas tools. Parameters ---------- ax : `~matplotlib.axes.Axes` Matplotlib Axes where tool handles are displayed. positions : 1D array Positions of handles in data coordinates. direction : {"horizontal", "vertical"} Direction of
| 3104 | |
| 3105 | |
| 3106 | class ToolLineHandles: |
| 3107 | """ |
| 3108 | Control handles for canvas tools. |
| 3109 | |
| 3110 | Parameters |
| 3111 | ---------- |
| 3112 | ax : `~matplotlib.axes.Axes` |
| 3113 | Matplotlib Axes where tool handles are displayed. |
| 3114 | positions : 1D array |
| 3115 | Positions of handles in data coordinates. |
| 3116 | direction : {"horizontal", "vertical"} |
| 3117 | Direction of handles, either 'vertical' or 'horizontal' |
| 3118 | line_props : dict, optional |
| 3119 | Additional line properties. See `.Line2D`. |
| 3120 | useblit : bool, default: True |
| 3121 | Whether to use blitting for faster drawing (if supported by the |
| 3122 | backend). See the tutorial :ref:`blitting` |
| 3123 | for details. |
| 3124 | """ |
| 3125 | |
| 3126 | def __init__(self, ax, positions, direction, *, line_props=None, |
| 3127 | useblit=True): |
| 3128 | self.ax = ax |
| 3129 | |
| 3130 | _api.check_in_list(['horizontal', 'vertical'], direction=direction) |
| 3131 | self._direction = direction |
| 3132 | |
| 3133 | line_props = { |
| 3134 | **(line_props if line_props is not None else {}), |
| 3135 | 'visible': False, |
| 3136 | 'animated': useblit, |
| 3137 | } |
| 3138 | |
| 3139 | line_fun = ax.axvline if self.direction == 'horizontal' else ax.axhline |
| 3140 | |
| 3141 | self._artists = [line_fun(p, **line_props) for p in positions] |
| 3142 | |
| 3143 | @property |
| 3144 | def artists(self): |
| 3145 | return tuple(self._artists) |
| 3146 | |
| 3147 | @property |
| 3148 | def positions(self): |
| 3149 | """Positions of the handle in data coordinates.""" |
| 3150 | method = 'get_xdata' if self.direction == 'horizontal' else 'get_ydata' |
| 3151 | return [getattr(line, method)()[0] for line in self.artists] |
| 3152 | |
| 3153 | @property |
| 3154 | def direction(self): |
| 3155 | """Direction of the handle: 'vertical' or 'horizontal'.""" |
| 3156 | return self._direction |
| 3157 | |
| 3158 | def set_data(self, positions): |
| 3159 | """ |
| 3160 | Set x- or y-positions of handles, depending on if the lines are |
| 3161 | vertical or horizontal. |
| 3162 | |
| 3163 | Parameters |
no outgoing calls
no test coverage detected
searching dependent graphs…