schrodinger.ui.qt.label_cursor module

class schrodinger.ui.qt.label_cursor.MultiAxesLabelCursor(labels, index_func=None)

Bases: object

A label for a matplotlib plot that follows the cursor. A vertical line is drawn at the cursor, and two columns of text are placed at the top of the plot describing the current x-value. This class allows the cursor to span multiple axes in the same canvas. See LabelCursor for a single axes convenience class.

Variables
  • _needclear (bool) – Do we need to make the label invisible if the user moves off the plot? (i.e. Is the label currently visible?)

  • _first_draw (bool) – Will the next drawing of the text be the first one? Note that drawing the vertical line without rendering the text doesn’t count, since that won’t set the height and width of the text box.

  • _on_draw_cid – The callback ID for the _onDraw call. (Used so we can later disconnect the callback.)

__init__(labels, index_func=None)
Parameters
  • labels (list) – A list of LabelCursorAxes objects for each set of axes to be labeled

  • index_func (function) – A function for calculating the appropriate LabelCursorAxes left_label_data/right_label_data index from an x data coordinate. Defaults to rounding the x coordinate to the nearest int.

set_visible(visible)

Set the visibility of the cursor. (Note that this function is set_visible() rather than setVisible() to match matplotlib’s function.)

Parameters

visible (bool) – What the visibility should be set to

onMove(event)

If the user moves the mouse inside of a labeled axes, draw the labels. If the user moves the mouse outside of the axes, erase the labels.

Parameters

event (matplotlib.backend_bases.LocationEvent) – The move event that triggered this callback

onDraw(event)

After the first time we draw the labels (and only the first time), immediately re-draw them. We do this because we can’t possibly know the width of the text before the first draw, but we can’t position the text correctly unless we know the width. To get around this catch 22, we initially draw the labels as invisible using alpha transparency. The alpha transparency prevents the user from seeing the incorrectly placed labels, but still allows us to determine their width. Immediately following this invisible draw, we re-calculate the text positions (now that we know their width), make the labels visible, and re-draw.

As this function only needs to be called after the first draw of the labels, it removes its own callback

Parameters

event (matplotlib.backend_bases.LocationEvent) – The move event that happened immediately before this draw. Note that this is not the draw event.

class schrodinger.ui.qt.label_cursor.LabelCursorAxes(ax, left_label_text, left_label_data, right_label_text, right_label_data, skip=None, font_size=None, text_y=0.98, line_width=2, line_color='blue')

Bases: object

A label for a matplotlib plot that follows the cursor. A vertical line is drawn at the cursor, and two columns of text are placed at the top of the plot describing the current x-value.

Variables
  • Z_INDEX (int) – The starting Z-index for the matplotlib elements

  • OFFSET (int) – The spacing placed around the text boxes

  • _max_width (list) – The max width of the left and right labels that we’ve seen.

  • _text_min (list) – The cached value of the y-coordinate of the bottom of the left and right labels in axis coordinates.

Z_INDEX = 10
OFFSET = 4
__init__(ax, left_label_text, left_label_data, right_label_text, right_label_data, skip=None, font_size=None, text_y=0.98, line_width=2, line_color='blue')
Parameters
  • ax (matplotlib.axes.AxesSubplot) – The matplotlib axes that this cursor should appear on

  • left_label_text (str) – The string to display in the left column of text

  • left_label_data (list or dict) – The data to interpolate into left_label_text. For any given x-value, left_label_data[x] will be interpolated.

  • right_label_text (str) – The string to display in the right column of text

  • right_label_data (list or dict) – The data to interpolate into right_label_text. For any given x-value, right_label_data[x] will be interpolated.

  • skip (list or None) – A list of indices to not display the label for. Defaults to displaying the labels for all indices. (Note that indices that aren’t present in left_label_data and right_label_data will be skipped automatically, regardless of this list.)

  • font_size (NoneType, int, or str) – The font size for the label. May be an absolute font size in points or a size string (e.g. “small”, “xx-large”). Defaults to the default Matplotlib font size.

  • text_y (float) – The vertical location of the top of the text boxes, ranging from 0 to 1, with 1 being the top of the axes.

  • line_width (int) – The width of the vertical line

  • line_color (str) – The color of the vertical line

set_visible(visible)

Set the visibility of the cursor. (Note that this function is set_visible() rather than setVisible() to match matplotlib’s function.)

Parameters

visible (bool) – What the visibility should be set to

set_alpha(alpha)

Set the alpha transparency of the cursor. (Note that this function is set_alpha() rather than setAlpha() to match matplotlib’s function.)

Parameters

alpha (float, int, or NoneType) – What the alpha transparency should be set to

updateLabel(x, xdata, idx)

Update the positions of the text blocks and the vertical line

Parameters
  • x (int) – The x coordinate of the cursor in canvas pixel coordinates

  • xdata (float) – The x coordinate of the cursor in data coordinates

  • idx (int) – The current index for left_label_data and right_label_data

labelDrawn(idx)

Will the text labels be drawn for the specified index? An index for which there’s no valid data or one that’s on the skip list won’t be drawn.

Parameters

idx (int) – The specified index (i.e. index to left_label_data and right_label_data).

Returns

Will the text labels be drawn for the specified index?

Return type

bool

class schrodinger.ui.qt.label_cursor.LabelCursor(ax, left_label_text, left_label_data, right_label_text, right_label_data, skip=None, font_size=None, text_y=0.98, line_width=2, line_color='blue', index_func=None)

Bases: schrodinger.ui.qt.label_cursor.MultiAxesLabelCursor

A convenience class for using a MultiAxesLabelCursor on a single set of axes

__init__(ax, left_label_text, left_label_data, right_label_text, right_label_data, skip=None, font_size=None, text_y=0.98, line_width=2, line_color='blue', index_func=None)

See LabelCursorAxes.__init__ for documentation for all arguments other than index_func. See MultiAxesLabelCursor.__init__ for documentation on index_func.