schrodinger.ui.qt.smatplotlib module¶
Contains Schrodinger helper widgets for matplotlib display in PyQt
- class schrodinger.ui.qt.smatplotlib.SmatplotlibToolbar(canvas, parent, coordinates=True, allow_log=True, allow_linear=True, clipboard=True, toolitems=None)¶
Bases:
schrodinger.ui.qt.navtoolbar.NavToolbar
Kept for backward compatibility - use navtoolbar.NavToolbar instead
- Deprecated
use schrodinger.ui.qt.navtoolbar.NavToolbar instead
- class schrodinger.ui.qt.smatplotlib.SmatplotlibCanvas(width=5, height=4, dpi=100, toolbar=True, layout=None, expanding=True, toolbar_class=None, **kwargs)¶
Bases:
matplotlib.backends.backend_qtagg.FigureCanvasQTAgg
- Custom subclass of FigureCanvasQTAgg that does the following:
- Allows for simultaneous definition of the Canvas, Figure and toolbar
objects, and placing them in a layout
Fixes known bugs with the mouse events detecting modifier keys
- TOOLBAR_CLASS¶
- __init__(width=5, height=4, dpi=100, toolbar=True, layout=None, expanding=True, toolbar_class=None, **kwargs)¶
- Parameters
width (number) – width of the plot Figure in inches
height (number) – height of the plot Figure in inches
dpi (int) – resolution of the plot
toolbar (boolean) – True if the toolbar should be created, but the parent parameter must be supplied in this case. The layout parameter is also typically required for this to function properly.
layout (QLayout object) – If layout is supplied, the toolbar and canvas will be placed in it.
expanding (bool) – if True, set canvas size policy to QSizePolicy.Expanding
toolbar_class (class) – If provided, the class to use for the toolbar
Extra keyword arguments are passed to the toolbar function
- eventFilter(obj, event)¶
The canvas needs to grab keyboard input in order to reliably tell when a modifier key (shift or control) is down when a mouse button is pressed/released.
Some environments have trouble with passing the control key in events - a control-left-click is often mapped to a right-click. Therefore we do our best to capture on our own when the control key is down. Note that even this breaks for multiple control-clicks on Linux running under VMWare Fusion on Macs, because VMWare by default “lifts” the control key after the first click.
- Parameters
obj (not used) – not used
event (QEvent) – the event object
- mousePressEvent(event)¶
Add in the control modifier key to the button_press_event
- Parameters
event (QMouseEvent) – the QMouseEvent that triggered this handler
self._key is matplotlib’s way of storing the modifier keys
- mouseReleaseEvent(event)¶
Add in the control modifier key to the button_release_event
- Parameters
event (QMouseEvent) – the QMouseEvent that triggered this handler
self._key is matplotlib’s way of storing the modifier keys
- drawAndUpdate(tight_layout=True)¶
Update canvas and toolbar after plotting.
- Parameters
tight_layout (bool) – Whether to apply tight layout after plotting
- schrodinger.ui.qt.smatplotlib.autoset_axis_range(axes, yaxis=True, minimum_span=0.01)¶
Set the axis range based on the min and max values of the plotted data.
- Parameters
axes (matplotlib.axes.Axes) – The plot that its axis range will be set.
yaxis (bool) – If True, the y-axis range will be set. If False, the x-axis range will be set.
minimum_span (float) – Minimum span between axis min and max
- schrodinger.ui.qt.smatplotlib.add_axis_margins(min_val: float, max_val: float, margin_frac: float = 0.05) Tuple[float] ¶
Return a new range with an added margin to both the min and max values. Mainly for aesthetic benefit.
- Min_val
The current minimum value.
- Max_val
The current maximum value. Assumed to be >
min_val
- Margin_frac
The fraction of the value range that we want to add as margin to each side.
- schrodinger.ui.qt.smatplotlib.get_annotation_position(text_obj: matplotlib.text.Text, ax: matplotlib.axes._axes.Axes, x_cursor: int, y_cursor: int) Tuple[float, float] ¶
Return the new position at which
text_obj
should be placed relative to the annotation origin, which is the top left corner by default. The main philosophy here is to always keep the annotation within the bounds of the axes. This is because the annotation will get clipped if it extends beyond the edge of the parent view. This may not always happen, but it’s very possible when annotation is large and there is little padding between the plot and the edge of the parent panel.Rules: 1. The annotation should be placed below the mouse and to the right when possible to mimic normal tooltip behavior. 2. If drawing the annotation below the cursor would cause it to extend below the axes, it should instead be placed above the cursor. 3. If drawing the annotation to the right of the cursor would cause it to extend off the axes to the right, it should instead be placed to the left of the cursor.
- Parameters
text_obj – The annotation to be moved.
ax – The axes in which the annotation is being placed.
x_cursor – The x-coordinate of the cursor.
y_cursor – The y-coordinate of the cursor.