Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# The thickness(es) of the contour lines.
# It can be either a scalar value, valid for all contour lines, or a list
# of widths. If the list is too short with respect to then number of
# contour lines, the values are repeated from the beginning of the list.
# Widths are associated with levels of increasing value.
widths = Trait(1.0, Float, List)
# The line dash style(s).
styles = Trait("signed", Str, List)
# Line style for positive levels.
positive_style = LineStyle("solid")
# Line style for negative levels.
negative_style = LineStyle("dash")
#------------------------------------------------------------------------
# Private traits
#------------------------------------------------------------------------
# Are the cached contours valid? If False, new ones need to be computed.
_contour_cache_valid = Bool(False)
# Cached collection of traces.
_cached_contours = Dict
# Is the cached width data valid?
_widths_cache_valid = Bool(False)
# Is the cached style data valid?
_styles_cache_valid = Bool(False)
#: The name of the metadata to look at for dataspace bounds. The metadata
#: can be either a tuple (dataspace_start, dataspace_end) in "selections" or
#: a boolean array mask of seleted dataspace points with any other name
metadata_name = Str("selections")
#------------------------------------------------------------------------
# Appearance traits
#------------------------------------------------------------------------
#: The color of the selection border line.
border_color = ColorTrait("dodgerblue")
#: The width, in pixels, of the selection border line.
border_width = Float(1.0)
#: The line style of the selection border line.
border_style = LineStyle("solid")
#: The color to fill the selection region.
fill_color = ColorTrait("lightskyblue")
#: The transparency of the fill color.
alpha = Float(0.3)
#------------------------------------------------------------------------
# AbstractOverlay interface
#------------------------------------------------------------------------
def overlay(self, component, gc, view_bounds=None, mode="normal"):
""" Draws this component overlaid on another component.
Overrides AbstractOverlay.
"""
axis_ndx = self.axis_index
lower_left = [0,0]
you want can require some verbose code. The create_line_plot() function
in plot_factory.py can hide some of this verbosity for common cases.
"""
#: The color of the line.
color = black_color_trait
#: The RGBA tuple for rendering lines. It is always a tuple of length 4.
#: It has the same RGB values as color_, and its alpha value is the alpha
#: value of self.color multiplied by self.alpha.
effective_color = Property(Tuple, depends_on=['color', 'alpha'])
#: The color to use to highlight the line when selected.
selected_color = ColorTrait("lightyellow")
#: The style of the selected line.
selected_line_style = LineStyle("solid")
#: The name of the key in self.metadata that holds the selection mask
metadata_name = Str("selections")
#: The thickness of the line.
line_width = Float(1.0)
#: The line dash style.
line_style = LineStyle
#: The rendering style of the line plot.
#:
#: connectedpoints
#: "normal" style (default); each point is connected to subsequent and
#: prior points by line segments
#: hold
# The location of the axis relative to the plot. This determines where
# the axis title is located relative to the axis line.
orientation = Enum("top", "bottom", "left", "right")
# Is the axis line visible?
axis_line_visible = Bool(True)
# The color of the axis line.
axis_line_color = ColorTrait("black")
# The line thickness (in pixels) of the axis line.
axis_line_weight = Float(1.0)
# The dash style of the axis line.
axis_line_style = LineStyle('solid')
# A special version of the axis line that is more useful for geophysical
# plots.
small_haxis_style = Bool(False)
# Does the axis ensure that its end labels fall within its bounding area?
ensure_labels_bounded = Bool(False)
# Does the axis prevent the ticks from being rendered outside its bounds?
# This flag is off by default because the standard axis *does* render ticks
# that encroach on the plot area.
ensure_ticks_bounded = Bool(False)
# Fired when the axis's range bounds change.
updated = Event
#------------------------------------------------------------------------
# Data-related traits
#------------------------------------------------------------------------
# The thickness(es) of the contour lines.
# It can be either a scalar value, valid for all contour lines, or a list
# of widths. If the list is too short with respect to then number of
# contour lines, the values are repeated from the beginning of the list.
# Widths are associated with levels of increasing value.
widths = Trait(1.0, Float, List)
# The line dash style(s).
styles = Trait("signed", Str, List)
# Line style for positive levels.
positive_style = LineStyle("solid")
# Line style for negative levels.
negative_style = LineStyle("dash")
#------------------------------------------------------------------------
# Private traits
#------------------------------------------------------------------------
# Are the cached contours valid? If False, new ones need to be computed.
_contour_cache_valid = Bool(False)
# Cached collection of traces.
_cached_contours = Dict
# Is the cached width data valid?
_widths_cache_valid = Bool(False)
from chaco.abstract_mapper import AbstractMapper
from chaco.base import point_dtype, rgba_dtype
from chaco.base_xy_plot import BaseXYPlot
class SegmentPlot(BaseXYPlot):
""" Plot that draws a collection of line segments. """
#: The single color to use when color_by_data is False.
color = black_color_trait(redraw=True)
#: The thickness of the line.
line_width = Float(1.0, redraw=True)
#: The line dash style.
line_style = LineStyle(redraw=True)
#: The rendering style of the segment plot.
#:
#: line
#: "Normal" direct connection between start and end points.
#: orthogonal
#: Connect the start and end points by two line segments in orthogonal
#: directions.
#: quad
#: Connect the start and end points by a quadratic Bezier curve.
#: cubic
#: Connect the start and end points by a cubic Bezier curve.
#:
#: For non-linear segments, the tangent at the start matches the
#: orientation of the plot (ie. horizontal orientation means
#: a horizontal tangent).
scale = Float(1.0)
offset = Float(0.0)
fast_clip = Bool(False)
# The color of the lines.
color = black_color_trait
# A function that returns the color of lines. Overrides `color` if not None.
color_func = Trait(None, None, Callable)
# The color to use to highlight the line when selected.
selected_color = ColorTrait("lightyellow")
# The style of the selected line.
selected_line_style = LineStyle("solid")
# The name of the key in self.metadata that holds the selection mask
metadata_name = Str("selections")
# The thickness of the line.
line_width = Float(1.0)
# The line dash style.
line_style = LineStyle
use_global_bounds = Bool(True)
# Minimum value in the `value` data source. This must be provided
# in the call to the constructor.
global_min = Float
#------------------------------------------------------------------------
#: whether or not to display a selection
show_selection = Bool(True)
#: the plot data metadata name to watch for selection information
selection_metadata_name = Str("selections")
#: the thickness, in pixels, of the selected lines
selected_line_width = Float(1.0)
#: the color of the selected lines
selected_color = ColorTrait("yellow")
#: The line dash style of the selected line.
selected_line_style = LineStyle("solid")
#: The fade amount for unselected regions
unselected_alpha = Float(0.3)
#------------------------------------------------------------------------
# Private methods
#------------------------------------------------------------------------
def _draw_plot(self, gc, view_bounds=None, mode="normal"):
""" Draw the plot """
coord = self._compute_screen_coord()
lines = empty(shape=(len(coord), 4))
if self.orientation == 'v':
lines[:, 0] = self.x
lines[:, 1] = coord
if len(x) < 2 or len(y) < 2:
self.fit_params = None
self.centroid = None
else:
self.fit_params = tuple(polyfit(x,y,1))
self.centroid = (sum(x)/len(x)), (sum(y)/len(y))
else:
self.fit_params = None
self.centroid = None
return
class RegressionOverlay(LassoOverlay):
line_color = ColorTrait("black")
line_style = LineStyle("dash")
line_width = Float(2.0)
_label = Instance(Label, kw=dict(bgcolor="white", border_color="black",
font="modern 14", border_width=1))
def _draw_component(self, gc, view_bounds=None, mode="normal"):
LassoOverlay._draw_component(self, gc, view_bounds, mode)
selection = self.lasso_selection
if selection.fit_params is not None:
# draw the label overlay
self._label.component = self.component
c = self.component
if selection.fit_params[1] < 0:
operator = "-"
origin_axis_color_ = (0,0,0,1)
# The width of the origin axis.
origin_axis_width = 2.0
# The origin axis is visible.
origin_axis_visible=True
# The grid is visible.
grid_visible= True
# The orientation of the plot is horizontal; for any other value, it is
# transposed
orientation = 'h'
# The color of the line.
color = black_color_trait
# The width of the line.
line_width = Float(1.0)
# The style of the line.
line_style = LineStyle("solid")
# The style of the grid lines.
grid_style= LineStyle("dot")
def _gather_points(self):
"""
Collects the data points that are within the plot bounds and caches them
"""
# This is just a stub for now. We should really find the lines only
# inside the screen range here.
x = self.index.get_data()
y = self.value.get_data()
rad= min(self.width/2.0,self.height/2.0)
sx = x*rad+ self.x + self.width/2.0
sy = y*rad+ self.y + self.height/2.0