chaco.examples.demo.basic.hittest_tool module¶
Draws a random x-y lineplot and makes a tool which shows the closet point on the lineplot to the mouse position.
-
class
chaco.examples.demo.basic.hittest_tool.
Demo
¶ Bases:
traits.has_traits.HasTraits
-
class
chaco.examples.demo.basic.hittest_tool.
HittestTool
(component=None, **traits)¶ Bases:
enable.base_tool.BaseTool
,chaco.abstract_overlay.AbstractOverlay
This tool uses LinePlot.hittest() to get the closest point on the line to the mouse position and to draw it to the screen. Also implements an Overlay in order to draw the point.
-
normal_mouse_move
(event)¶
-
overlay
(plot, gc, view_bounds=None, mode='normal')¶ Draws this component overlaid on another component.
-
-
chaco.examples.demo.basic.hittest_tool.
random_sample
(size=None)¶ Return random floats in the half-open interval [0.0, 1.0).
Results are from the “continuous uniform” distribution over the stated interval. To sample \(Unif[a, b), b > a\) multiply the output of random_sample by (b-a) and add a:
(b - a) * random_sample() + a
- Parameters
size (int or tuple of ints, optional) – Output shape. If the given shape is, e.g.,
(m, n, k)
, thenm * n * k
samples are drawn. Default is None, in which case a single value is returned.- Returns
out – Array of random floats of shape size (unless
size=None
, in which case a single float is returned).- Return type
float or ndarray of floats
Examples
>>> np.random.random_sample() 0.47108547995356098 # random >>> type(np.random.random_sample()) <class 'float'> >>> np.random.random_sample((5,)) array([ 0.30220482, 0.86820401, 0.1654503 , 0.11659149, 0.54323428]) # random
Three-by-two array of random numbers from [-5, 0):
>>> 5 * np.random.random_sample((3, 2)) - 5 array([[-3.99149989, -0.52338984], # random [-2.99091858, -0.79479508], [-1.23204345, -1.75224494]])