schrodinger.application.bioluminate.sliderchart module¶
Tools for using matplotlib charts.
Copyright Schrodinger, LLC. All rights reserved.
- schrodinger.application.bioluminate.sliderchart.prevent_overlapping_x_labels(canvas, axes_number=0)¶
Given a canvas that contains a figure that contains at least one axes instance, checks the x-axis tick labels to make sure they don’t overlap. If they do, the number of ticks is reduced until there is no overlap.
- Parameters
canvas (matplotlib canvas object) – the canvas that contains the figure/axes objects
axes_number (int) – the index of the axes on the figure to examine. Default is 0, which is the first set of axis added to the figure.
- class schrodinger.application.bioluminate.sliderchart.SliderPlot(xvals=None, yvals=None, size=(400, 400), x_label='Residue Sequence', y_label='Values', x_range=None, y_range=None, color='black', cvals=None, bg='white', title='Results', fontsize='small', chart_type='line', marker='square', marker_size=9, shade_color='0.70', hslider_color='red', vslider_color='blue', slider_thickness=3, slider_pick_tolerance=7, slider_moved_callback=None, use_hsliders=True, xstart=0.2, xextent=None, subplot_pos=None)¶
Bases:
PyQt6.QtWidgets.QFrame
A chart that contains four lines the user can slide to select a region of the chart.
- __init__(xvals=None, yvals=None, size=(400, 400), x_label='Residue Sequence', y_label='Values', x_range=None, y_range=None, color='black', cvals=None, bg='white', title='Results', fontsize='small', chart_type='line', marker='square', marker_size=9, shade_color='0.70', hslider_color='red', vslider_color='blue', slider_thickness=3, slider_pick_tolerance=7, slider_moved_callback=None, use_hsliders=True, xstart=0.2, xextent=None, subplot_pos=None)¶
Create a SliderPlot instance.
The plot is returned in a QFrame widget.
- Parameters
xvals (list) – the x values to plot
yvals (list) – y series to plot, should be the same length as xvals
size (tuple) – (x, y) plot size in pixels
x_label (str) – X-axis label
y_label (str) – Y-axis label
x_range (tuple) – (min, max) values for the X-axis, default is to show all values
y_range (tuple) – (min, max) values for the Y-axis, default is to show all values
color (str) – color for the line plot - this is overridden by cvals if cvals is given.
cvals (list, tuple or str) – For scatterplots, either a list or tuple of color values for every point, or a string to set a single color for all points. Do not use an RGB list or tuple to set a single color for all points, as that will be interpreted as intended to set individual colors for 3 (or 4 for RGBA) points. This overrides the value of color, and is not used for line plots, only scatter plots. If not given, the value of color is used.
bg (str) – color name for the plot background. See marker:color for some color names.
title (str) – the title of the plot
chart_type (str) – ‘line’ if the chart is a line plot (default), ‘scatter’ if the chart is scatterplot
shade_color (str) – A matplotlib-recognized color string that the unselected areas will be shaded
hslider_color (str) – A matplotlib-recognized color string that the horizontal sliders will be colored
vslider_color (str) – A matplotlib-recognized color string that the vertical sliders will be colored
slider_thickness (int) – Linewidth of the slider lines
slider_pick_tolerance (int) – Number of pixels the mouse click can be off and still grab the slider
slider_moved_callback (callable) – Called when one of the slider lines has been moved. The callback will receive the SlidableLine object that was moved.
marker (tuple) – tuple of (symbol, color, size), only used for scatter plots
Marker names are:
symbol (1-character str)
s - square (‘square’, rectangle accepted)
o - circle (‘circle’ accepted)
^ - triangle up (‘arrow’ accepted)
> - triangle right
< - triangle left
v - triangle down
d - diamond (‘diamond’ accepted)
p - pentagon
h - hexagon
8 - octagon
plus (‘cross’ accepted)
x - x
- Parameters
marker_size (int) – size of the marker
fontsize (int or str) – size in points, or one of the following - - xx-small - x-small - small - medium - large - x-large - xx-large
use_hsliders (bool) – horizontal slider is enabled, if True
xstart – left percentage margin of the figure
xextent (float of None) – if float, right percentage margin of the figure
subplot_pos (int) – A three digit integer, where the first digit is the number of rows, the second the number of columns, and the third the index of the current subplot. Index goes left to right, followed but top to bottom. Hence in a 4 grid, top-left is 1, top-right is 2 bottom left is 3 and bottom right is 4. Subplot overrides x_start, y_start, x_end, and y_end.
- Xstart
float
- Return type
QFrame
- Returns
The QFrame widget that contains the plot
- replot()¶
Replot the chart with the current settings
- removeColorsForMissingPoints()¶
Remove any colors for points that are missing X or Y data (X or Y = None) from the list of original values. Does nothing if the point colors are not a list or tuple.
- setCVals(cvals)¶
Set the color values for scatterplot points and replot
- Parameters
cvals (list, tuple or str) – Either a list or tuple of color values for every point, or a string to set a single color for all points. Do not use an RGB list or tuple to set a single color for all points, as that will be interpreted as intended to set individual colors for 3 (or 4 for RGBA) points.
- removeMissingPoints()¶
Remove any points that are missing X or Y data (X or Y = None) from the list of original values
- Return type
tuple
- Returns
tuple of (x-values, y-values) where each item is a list of values. Any point for which x-value or y-value is None has been removed.
- setXY(xvals, yvals, x_range=None, y_range=None, replot=True)¶
Change the X and Y values of the plot
- Parameters
xvals (list) – the x values to plot
yvals (list) – y series to plot, should be the same length as xvals
x_range (tuple) – (min, max) values for the X-axis, default is to show all values
y_range (tuple) – (min, max) values for the Y-axis, default is to show all values
replot (bool) – True of plot should be redrawn (default), False if not. False can be used if a subsequent setY is required.
- setX(xvals, x_range=None, replot=True, reset_yrange=False)¶
Change the X values of the plot
- Parameters
xvals (list) – the x values to plot
x_range (tuple) – (min, max) values for the X-axis, default is to show all values
replot (bool) – True of plot should be redrawn (default), False if not. False can be used if a subsequent setY is required.
reset_yrange (bool) – True if the y_range should be reset, False (default) if not. It is useful to reset this if the number of datapoints is changing.
- setY(yvals, y_range=None, replot=True, reset_xrange=False)¶
Change the Y values of the plot
- Parameters
yvals (list) – the y values to plot
y_range (tuple) – (min, max) values for the Y-axis, default is to show all values
replot (bool) – True of plot should be redrawn (default), False if not. False can be used if a subsequent setY is required.
reset_xrange (bool) – True if the y_range should be reset, False (default) if not. It is useful to reset this if the number of datapoints is changing.
- getHSliderMin()¶
Get the current value of the minimum horizontal slider line in plot data units
- Return type
float or -INF
- Returns
The current value of the minimum horizontal slider, if in use
- getHSliderMax()¶
Get the current value of the maximum horizontal slider line in plot data units
- Return type
float or INF
- Returns
The current value of the maximum horizontal slider, if in use
- getVSliderMin()¶
Get the current value of the minimum vertical slider line in plot data units
- Return type
float
- Returns
The current value of the minimum vertical slider
- getVSliderMax()¶
Get the current value of the maximum vertical slider line in plot data units
- Return type
float
- Returns
The current value of the maximum vertical slider
- getSelectedIndexes()¶
Get the index in the x-value list of points that are contained within the slider lines.
- Return type
list
- Returns
index in the x-value list of points that are within the box bounded by the slider lines.
- getSelectedXY()¶
Get the set of (x, y) points that are contained within the slider lines
- Return type
list
- Returns
(x, y) data points that are within the box bounded by the slider lines
- getSelectedX()¶
Get the set of x values for all points that are contained within the slider lines.
- Return type
list
- Returns
x values of data points that are within the box bounded by the slider lines
- setToolbarMessage(event)¶
Set toolbar message to also work with subplots and show coordinates of subplots in the message
- Parameters
event (matplotlib.backend_bases.MouseEvent) – the mouse event prompting this method to be called. Contains information about the location of the cursor and above which
matplotlib.axes.Axes
object the cursor was at the time of the event, if any.
- reset()¶
Reset the plot
- class schrodinger.application.bioluminate.sliderchart.SlidableLine(parent, axes, line, tolerance=7, border='high', shade_color='0.70', callback=None)¶
Bases:
object
A line on a matplotlib plot that can be grabbed and moved by the user
- __init__(parent, axes, line, tolerance=7, border='high', shade_color='0.70', callback=None)¶
Create a SlidableLine object
- Parameters
parent (SliderPlot object) – The matplotlib canvas these lines are plotted on
axes (matplotlib Axes object) – The matplotlib axes these lines are plotted on
line (matplotlib Line2D object) – the actual line that will be moved
tolerance (int) – The amount that the user can “miss” the line and still grab it
border (str) – either “high” or “low”, the role this line plays in bounding the box - high lines are those that bound the upper value of X or Y
shade_color (str) – A matplotlib-recognized color string that the unselected areas will be shaded
callback (callable) – Called when the slider line has been moved. The callback will receive the SlidableLine object that was moved.
- onRelease(event)¶
Stop checking for movement when the mouse button is released
- remove()¶
Remove this from the plot
- class schrodinger.application.bioluminate.sliderchart.SlidableHLine(*args, **kwargs)¶
Bases:
schrodinger.application.bioluminate.sliderchart.SlidableLine
A horizontal line on a matplotlib plot that can be grabbed and moved by the user
- __init__(*args, **kwargs)¶
Create a SlidableHLine object
See parent class for argument documentation
- getPosition()¶
Return the position of the line in data coordinates
- Return type
float
- Returns
The current position of the line in data coordinates
- getAxisExtreme()¶
Return the most extreme (high or low) value this line should take
- Return type
float
- Returns
The most extreme value this line can take in data coordinates
- setPosition(value)¶
Change the position of the line to value. However, we don’t allow the high/low boundary lines to cross, or to go off the plot.
- Parameters
value (float) – The new y value to attempt to place the line at
- onMotion(event)¶
Move the line if it is currently moving and the mouse moved
- Parameters
event (matplotlib mouse event) – the event object generated by mouse movement
- onPress(event)¶
Check to see if the user clicked this line
- Parameters
event (matplotlib mouse event) – the event object generated by mouse click
- class schrodinger.application.bioluminate.sliderchart.SlidableVLine(*args, **kwargs)¶
Bases:
schrodinger.application.bioluminate.sliderchart.SlidableLine
A vertical line on a matplotlib plot that can be grabbed and moved by the user
- __init__(*args, **kwargs)¶
Create a SlidableVLine object
See parent class for argument documentation
- getPosition()¶
Return the position of the line in data coordinates
- Return type
float
- Returns
The current position of the line in data coordinates
- setPosition(value)¶
Change the position of the line to value. However, we don’t allow the high/low boundary lines to cross, or to go off the plot.
- Parameters
value (float) – The new x value to attempt to place the line at
- getAxisExtreme()¶
Return the most extreme (high or low) value this line should take
- Return type
float
- Returns
The most extreme value this line can take in data coordinates
- onMotion(event)¶
Move the line if it is currently moving and the mouse moved
- Parameters
event (matplotlib mouse event) – the event object generated by mouse movement
- onPress(event)¶
Check to see if the user clicked this line
- Parameters
event (matplotlib mouse event) – the event object generated by mouse click