DraggablePlot

class visualife.core.DraggablePlot(viewport, min_screen_x, max_screen_x, min_screen_y, max_screen_y, min_data_x, max_data_x, min_data_y, max_data_y, axes_definition='BL')

Bases: visualife.core.Plot

Represents a draggable plot object

Attributes Summary

axes Dictionary of axes in a plot - key is a letter defines axis (U,B,R,L) and Axis object is a value
axes_svg Returns axes
clip_path_name Defines clip_path_name of this plot
clip_path_tics Defines clip_path_name of this plot
converter
data_ids Returns data_ids
drag_x Returns drag_x value
drag_y Returns drag_y value
extra_labels Provides access to the list of extra labels of this plot
is_dragged Returns True if plot is dragged
max_drag_x Returns max_drag_x value
max_drag_y Returns max_drag_y value
plot_label Defines title (label) of this plot
plot_label_font_size Defines the font size used to draw title (label) of this plot
shift_x Returns shift_x value
shift_y Returns shift_y value
viewport Returns viewport

Methods Summary

add_extra_label(label_text, data_x, data_y, …) Adds a new label that will be drawn in the plot.
axes_svg_x() Returns axes elements as an svg object
axes_svg_y() Returns axes elements as an svg object
bars(*args, **kwargs) Creates a bar plot
boxes(*args, **kwargs)
bubbles(*args, **kwargs) Creates a bubble chart
clear()
drag(evt) Performs the actual drag action
draw(**kwargs) Draws this plot on its viewport
draw_axes() Draws axes as an <svg> element
draw_grid() Draws grid as an <svg> element
draw_legend([position]) Calculates legend position and size and draws it
draw_plot_label() Draws a plot label - its title and all extra labels that has been added to this plot
end_drag(evt) Function called when “mouseup” event is recorded; drag is stopped at that moment
line(*args, **kwargs) Creates a line plot
prepare_data_colors(kwargs_dict) Returns list of colors used to draw points
scale(scale) Scales plot :param scale: provides a scale :type scale: float
scatter(*args, **kwargs) Creates a scatterplot
set_axes()
set_plot_at_xy(x, y) Sets the middle of plot in (x,y) point.
start_drag(evt) Function called when “mousedown” event is recorded; drag is started at that moment

Attributes Documentation

axes

Dictionary of axes in a plot - key is a letter defines axis (U,B,R,L) and Axis object is a value

Getter:returns a dictionary holding axes objects; dictionary keys are B, U, R and L for bottom, top, right and left axis, respectively
Type:dictionary(Axis)
axes_svg

Returns axes

clip_path_name

Defines clip_path_name of this plot

Getter:returns the clip path name
Setter:sets the new clip path name
Type:string
clip_path_tics

Defines clip_path_name of this plot

Getter:returns the clip path name
Setter:sets the new clip path name
Type:string
converter
data_ids

Returns data_ids

drag_x

Returns drag_x value

drag_y

Returns drag_y value

extra_labels

Provides access to the list of extra labels of this plot

Returns:a list of labels, each label as a tuple (x, y, "text", dict). The dict holds kwargs with plotting style
is_dragged

Returns True if plot is dragged

max_drag_x

Returns max_drag_x value

max_drag_y

Returns max_drag_y value

plot_label

Defines title (label) of this plot

Getter:returns the label as text
Setter:sets the new label text
Type:string
plot_label_font_size

Defines the font size used to draw title (label) of this plot

Getter:returns the label font size
Setter:sets the new label font size
Type:float
shift_x

Returns shift_x value

shift_y

Returns shift_y value

viewport

Returns viewport

Methods Documentation

add_extra_label(label_text, data_x, data_y, **kwargs)

Adds a new label that will be drawn in the plot.

Besides tics labels, axis labels, etc a plot may also have extra labels, placed in arbitrary locations given in data coordinates. Plot object will convert these X,Y coordinates do screen coordinates using main X and Y axes

Parameters:
  • label_text – text to be written in this plot
  • data_x
    • data X coordinate of a label
  • data_y
    • data y coordinate of a label
  • kwargs
    • style parameters
Returns:

None

axes_svg_x()

Returns axes elements as an svg object

axes_svg_y()

Returns axes elements as an svg object

bars(*args, **kwargs)

Creates a bar plot

Keyword Arguments (**kwargs)(**kwargs):
 
  • colors (list [ string ], list [ float ] or list [ color in HEX format ]) – define fill color for points; the colors are cycled over for all points, so if the list contains a single elements, all points will have the same fill color
  • stroke (float or color in HEX format ) - stroke color
  • width (float) - width of each bar (in data units!)
  • title (string) - title of this data series; if not provided, the word “bars” will be used
  • converter_type (string) - converter type to calculate axis range - may be “primary”

(bottom and left axis) or “secondary” (upper and rigth axis)

  • adjust_range - False if you want to keep values from Plot constructor and True (default) if you want to have automatically adjust scale
boxes(*args, **kwargs)
bubbles(*args, **kwargs)

Creates a bubble chart

Bubble chart displays three dimensions of data. Radius of each bubble is proportional to the square root of Z value of each point

Parameters:

*args – data to be plotted; see DataSet.__init__() documentation

Keyword Arguments (**kwargs)(**kwargs):
 
  • markersize (float) – a value used to scale radius of each bubbles
  • colors (list [ string ], list [ float ] or list [ color in HEX format ]) – define fill color for points; the colors are cycled over for all points, so if the list contains a single elements, all points will have the same fill color
  • stroke (float or color in HEX format ) - stroke color
  • stroke_width (float) - stroke width
  • title (string) - title of this data series; if not provided, the word “bubble chart” will be used
  • converter_type (string) - converter type to calculate axis range - may be “primary”

(bottom and left axis) or “secondary” (upper and rigth axis

  • adjust_range - False if you want to keep values from Plot constructor and True (default) if you want to have automatically adjust scale
clear()
drag(evt)

Performs the actual drag action

@param evt: event object passed by a web browser; mouse coordinates are extracted from it

draw(**kwargs)

Draws this plot on its viewport

Its necessary to call this method at the end of plotting; only then this plot will be actually drawn. Also, any adjustments (e.g. extra labels, axis, etc.) added after this call will not be included in this plot.

Keyword Arguments (**kwargs)(**kwargs):
 
  • axes (bool) – draws axes if True (as default)
  • grid (bool) – draws grid if True (default is False)
  • plot_label (bool ) – draws plot_label if True (as default)
  • legend (string``or ``bool) – legend position; default is False; if True then default location is set (see PlotLegend.__init__())
draw_axes()

Draws axes as an <svg> element

draw_grid()

Draws grid as an <svg> element

draw_legend(position='RU')

Calculates legend position and size and draws it

draw_plot_label()

Draws a plot label - its title and all extra labels that has been added to this plot

end_drag(evt)

Function called when “mouseup” event is recorded; drag is stopped at that moment

@param evt: event object passed by a web browser

line(*args, **kwargs)

Creates a line plot

Line plot displays data conected with lines.

Keyword Arguments (**kwargs)(**kwargs):
 
  • colors (list [ string ], list [ float ] or list [ color in HEX format ]) – define fill color for points; the colors are cycled over for all points, so if the list contains a single elements, all points will have the same fill color
  • stroke (float or color in HEX format ) - stroke color
  • width (float) - stroke width
  • title (string) - title of this data series; if not provided, the word “line” will be used
  • converter_type (string) - converter type to calculate axis range - may be “primary”

(bottom and left axis) or “secondary” (upper and rigth axis)

  • adjust_range - False if you want to keep values from Plot constructor and True (default) if you want to have automatically adjust scale
prepare_data_colors(kwargs_dict)

Returns list of colors used to draw points

This method makes the following choice:

  • if kwargs_dict does not contain "colors" key, a single color will be returned to plot all points the returned color will be selected from the current palette assigned to differentiate between data series
  • if "colors" provides a string that is a valid color palette name (i.e. registered in styles.known_color_scales) the requested pallete is returned
  • if "colors" provides a int, the number is interpreted as an index of a color in the data series palette; a single color is returned
  • if "colors" provides a list of values, a color is evaluated separately for every value using a color map If kwargs_dict provides "cmap" key, the requested color map is used for that purpose; otherwise a default "blues" map is used. In addition, when "cmap_reversed" key is set to True, the cmap will be reversed, e.g. "red_blue" color map will become "blue_red"

The colors are defined based on what user requested by kwargs parameters passed to plotting methods as``bubbles()``, scatter() or line()

scale(scale)

Scales plot :param scale: provides a scale :type scale: float

scatter(*args, **kwargs)

Creates a scatterplot

Keyword Arguments (**kwargs)(**kwargs):
 
  • markersize (float) – size of points of this scatterplot
  • markerstyle (char) – point type; available types are:
    • ‘o’ – circle
    • ‘c’ – circle (same as ‘o’)
    • ‘s’ – square
    • ‘t’ – triangle
    • ‘r’ – rhomb
  • colors (list [ string ], list [ float ] or list [ color in HEX format ]) – define fill color for points; the colors are cycled over for all points, so if the list contains a single elements, all points will have the same fill color
  • stroke (float or color in HEX format ) - stroke color
  • stroke_width (float) - stroke width
  • title (string) - title of this data series; if not provided, the word “scatter” will be used
  • flush (bool) – if True, the plot will be automatically send to HTML viewport have no efefct on SVG viewport; defalit is True
  • converter_type (string) - converter type to calculate axis range - may be “primary”

(bottom and left axis) or “secondary” (upper and rigth axis)

  • adjust_range - False if you want to keep values from Plot constructor and True (default) if you want to have automatically adjust scale
set_axes()
set_plot_at_xy(x, y)

Sets the middle of plot in (x,y) point. x and y are the screen coordinates

start_drag(evt)

Function called when “mousedown” event is recorded; drag is started at that moment

@param evt: event object passed by a web browser