schrodinger.ui.qt.schart module

A module for plotting with QChart.

Simple chart with a scatter plot and trendline:

self.chart = schart.SChart(

title=’Simple Chart’, xtitle=’Hobnobs’, ytitle=’Grobniks’, layout=layout)

xvals = [3, 5, 9] yvals = [7, 12, 14] series_data = self.chart.addDataSeries(‘Production’, xvals,

yvals=yvals, fit=True)

Copyright Schrodinger, LLC. All rights reserved.

schrodinger.ui.qt.schart.compute_tick_interval(length, max_ticks=11, deltas=(1, 2, 5, 10, 10))

Computes the tick interval to span length with a maximum number of ticks using deltas to get the preferred tick intervals (scaled to a range of 0-10).

Note: delta should start with 1 and end with two 10s.

Parameters
  • length (float) – the length of the axis, usually the highest - lowest value

  • max_ticks (int) – the maximum number of ticks to use

  • deltas (indexable of float) – the preferred tick intervals to use

Returns

the tick interval to use

Return type

float

class schrodinger.ui.qt.schart.SeriesData(series, bar_set=None)

Bases: object

Holds the data for a plotted series

__init__(series, bar_set=None)

Create a SeriesData object

Parameters
  • series (QtCharts.QAbstractSeries) – The plotted series

  • bar_set (QtCharts.QBarSet) – For histograms, the plotted bar set

createTrendLine(name=None, fitter=None)

Add or recompute a trendline to a series

Parameters
  • name (str) – The name of the trendline series

  • fitter (callable) – The function to fit the data. Must have the same API as the fitLine method. If not provided, a linear regression is performed

Raises

FitError – If an error occurs when fitting the data

static fitLine(xvals, yvals, buffer=0)

Fit a trendline to the data

Parameters
  • xvals (list) – The x values

  • yvals (list) – The y values

  • buffer (float) – The data points returned will be at the minimum x value minus the buffer and the maximum x value plus the buffer

Return type

(list of float, list of float, scipy.stats._stats_mstats_common.LinregressResult`)

Returns

The x values of the data points the form the line, the corresponding y values, and the scipy line fit resuls object

exception schrodinger.ui.qt.schart.FitError

Bases: Exception

Raised for an error in fitting a trendline

class schrodinger.ui.qt.schart.BarSeriesSizeSpinBox(text, side='left', stretch=True, after_label='', layout=None, tip=None, **kwargs)

Bases: schrodinger.ui.qt.swidgets.SLabeledDoubleSpinBox

A spinbox that can have its value updated without emitting a signal

A group of these spinboxes are all connected together. When the value of one spinbox changes, all of the others update their values. Thus, we need to catch the signal when the first spinbox value is changed, but need a way to update all the others without also triggering their valueChanged signals or we end up in an infinite loop.

nonEmittingUpdate(value)

Change the value of the spinbox without emitting a signal

Parameters

value (flot) – The new value of the spinbox

class schrodinger.ui.qt.schart.SeriesParams(series, layout, row, name_only=False)

Bases: object

A set of widgets that control the visual plotting of a QChart series

SHAPES = {'Circle': MarkerShape.MarkerShapeCircle, 'Rectangle': MarkerShape.MarkerShapeRectangle}
LINE = 'line'
SCATTER = 'scatter'
BAR = 'bar'
SUPPORTED_TYPES = {<class 'PyQt6.QtCharts.QScatterSeries'>: 'scatter', <class 'PyQt6.QtCharts.QLineSeries'>: 'line', <class 'PyQt6.QtCharts.QBarSeries'>: 'bar'}
__init__(series, layout, row, name_only=False)

Create a SeriesParams object

Note that there is no overall enclosing frame or layout for this set of widgets because they are placed individually in cells of a grid layout.

Parameters
  • series (QtCharts.QAbstractSeries) – The plotted series. Currently this class is only implemented with Line and Scatter series in mind.

  • layout (QtWidgets.QGridLayout) – The layout to place these widgets in

  • row (int) – The row of the grid layout for these widgets

  • name_only (bool) – Show only the edit for the name of the series

static getParamRows(series, layout, row)

Get a SeriesParam object for each set of plot items managed by this series. For an QXYSeries, there will be one SeriesParam. For a QBarSeries, there will be one SeriesParam for each QBarSet.

Parameters
  • series (QtCharts.QAbstractSeries) – The series to create parameters for

  • layout (swidgets.SGridBoxLayout) – The layout to place the SeriesParam widgets in

  • row (int) – The row of the grid layout to place the widgets in

Return type

list

Returns

Each item of the list

getSize()

Get the current size of the series. What “size” means depends on the the series type

Return type

float

Returns

The series size

setSize()

Set the size of the series. What size means depends on the series type.

getName()

Get the name of the series

Return type

str

Returns

The name of the series

setName()

Set the name of the series based on the widget settings

getColor()

Get the color of the series

getColorFromWidget()

Get the color from the color widget

Return type

QtGui.QColor

Returns

The current color of the color widget

setColor()

Set the color of the series

apply()

Apply the current widget settings to the series

class schrodinger.ui.qt.schart.BarSeriesParams(barset, *args, subrow=False, **kwargs)

Bases: schrodinger.ui.qt.schart.SeriesParams

A set of widgets that control the visual plotting of a QChart bar series

__init__(barset, *args, subrow=False, **kwargs)

Create a BarSeriesParams instance

Parameters
  • barset (QtCharts.QBarSet) – The bar set for these parameters

  • subrow (bool) – False if this is for the first bar set in the series, True if for one of the lower ones. Only the first bar set sets the properties that must be the same for all sets in the series

getSize()

See paraent method for documentation

setSize()

See paraent method for documentation

getName()

See paraent method for documentation

setName()

See paraent method for documentation

getColor()

See paraent method for documentation

setColor()

See paraent method for documentation

class schrodinger.ui.qt.schart.SeriesDialog(series, *args, title='Series Parameters', help_topic='QCHART_SERIES_DIALOG', **kwargs)

Bases: schrodinger.ui.qt.swidgets.SDialog

A dialog allowing the user to control the visual look of series

__init__(series, *args, title='Series Parameters', help_topic='QCHART_SERIES_DIALOG', **kwargs)

Create a SeriesDialog object

Parameters

series (list) – The list of series to display in this dialog

See parent class for additional documentation

layOut()

Lay out the widgets

accept()

Apply the current settings

class schrodinger.ui.qt.schart.AxisParams(axis, series, label, layout, row)

Bases: object

A set of widgets to control QChart axis parameters

__init__(axis, series, label, layout, row)

Create an AxisParams object

The widgets are in an enclosing frame.

Parameters
  • axis (QtCharts.QValueAxis) – The axis to control

  • series (list) – The list of data series on the plot

  • label (str) – The name of the axis in the dialog

  • layout (QtWidgets.QGridBoxLayout) – The layout to place the widgets into

  • row (int) – The row in the grid layout where these params start

apply()

Apply the current widget settings

logChanged()

Check if the current state of the log checkbox is different from the current type of axis

Return type

bool

Returns

True if the current axis is inconsistent with the state of the log checkbox

class schrodinger.ui.qt.schart.AxesDialog(axes, series, *args, title='Axes Parameters', help_topic='QCHART_AXES_DIALOG', **kwargs)

Bases: schrodinger.ui.qt.swidgets.SDialog

A dialog for controlling the axes in a QtChart

Parameters

axes (list) – A list of QAbstractAxes objects this dialog should control

See parent class for additional documentation

logToggled

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

__init__(axes, series, *args, title='Axes Parameters', help_topic='QCHART_AXES_DIALOG', **kwargs)

Create an AxesDialog object

layOut()

Lay out the widgets

accept()

Apply the current settings

class schrodinger.ui.qt.schart.BinsDialog(series, *args, title='Number of Bins', help_topic='QCHART_BINS_DIALOG', **kwargs)

Bases: schrodinger.ui.qt.swidgets.SDialog

A dialog for controlling the bins in a QtChart histogram

BINS = 'Number of bins:'
EDGES = 'Define bin edges:'
__init__(series, *args, title='Number of Bins', help_topic='QCHART_BINS_DIALOG', **kwargs)

Create an BinsDialog object

Parameters

series (list) – The list of series to display in this dialog

See parent class for additional documentation

layOut()

Lay out the widgets

modeChanged(update=True)

React to changing between defining the number of bins and the edge values

Parameters

update (bool) – Whether to update the plotted bins

updateToggled()

React to a change in the interactivity state

updateBins(edges=None, force=False)

Update the plotted bins

Parameters
  • edges (list) – A list of the bin edges. Each item is a float

  • force (bool) – Whether to force the update regardless of the interactivity state

accept()

Update the bins and close the dialog

reject()

Reset the bins to their original state and close the dialog

class schrodinger.ui.qt.schart.SChartView(chart, width, height, layout=None)

Bases: PyQt6.QtCharts.QChartView

The View for a QChart

PADDING = 10
HOVER_LABEL_X_FORMAT = '.3f'
HOVER_LABEL_Y_FORMAT = '.3f'
__init__(chart, width, height, layout=None)

Create an SChartView object

Parameters
  • chart (QtCharts.QChart) – The chart for this view

  • width (int) – The recommended minimum width (pixels) of the chart

  • height (int) – The recommended minimum height (pixels) of the chart

  • layout (QtWidgets.QBoxLayout) – The layout to place this chart into

sizeHint(*args)

Overwrite the parent method to ensure a minimum height and width of the chart. Without this QCharts open at a minimum unreadable size.

See parent method for implementation details

setHoverLabelFormat(x_format=None, y_format=None)

Set the string format specifiers for the hover label. These values only apply if the data passed in to updateHoverLabel is not a string.

Parameters
  • x_format (str) – The format for the x value (%.3f, %d, etc). If None, no change will be made to the current format.

  • y_format (str) – The format for the y value (%.3f, %d, etc). If None, no change will be made to the current format.

updateHoverLabel(xval, yval, bold=False)

Update the text in the hover label

Can be overwritten in subclasses to show custom data

clearHoverLabel()

Clear the hover label text

readjustHoverLabel()

Make sure the hover label is in the upper right corner of the view

paintEvent(*args, **kwargs)

Overwrite the parent method to make sure the hover label stays put

See parent method for implementation details

class schrodinger.ui.qt.schart.SHistogramBarSeries(*args, **kwargs)

Bases: PyQt6.QtCharts.QBarSeries

A QBarSeries with additional functionality for histograms

binsChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

__init__(*args, **kwargs)

See parent class for documentation

setEdges(edges)

Set the edges (the bin boundaries). Since the bins occur between the edges, there will be one more edge than there is bins

Parameters

edges (list or numpy.array) – The bin edges. The first bin appears between edges[0] and edges[1], the last bin appears between edges[-2] and edges[-1]

getEdges()

Get the edges (the bin boundaries). Since the bins occur between the edges, there will be one more edge than there is bins

Return type

list or numpy.array

Returns

The bin edges. The first bin appears between edges[0] and edges[1], the last bin appears between edges[-2] and edges[-1]

hasEdges()

Check if this series has edges set yet or not

Return type

bool

Returns

Whether edges are set for this series or not

updateHistograms(bin_settings)

Update all the histograms in this series based on the bin setting

Parameters

bin_settings (str, int or list) – This is passed to the numpy.histogram method or the user’s supplied histogram method as the bins parameter. May be a string such as SChart.AUTO to indicate how the bins are to be determined. May be an integer to give the total number of bins, or may be a list of bin edge values.

updateAxes()

Update the plot axes based on the current histograms

getBinIndices(data, include_last_edge=True)

Get the zero-based bin indices of the passed data. The left limit of each bin is closed and the right limit is open. The index is -1 or num_bins if the value falls outside the range.

Parameters
  • data (array_like) – The data to get indices for

  • include_last_edge (bool) – Whether the last right limit should be closed

Return list

List of bin indices of each value in the passed data

numBins()

Get the number of bins

Return int

The number of bins

class schrodinger.ui.qt.schart.SHistogramBarSet(data, name, series, fitter=<function histogram>)

Bases: PyQt6.QtCharts.QBarSet

A QBarSet with additional functionality for histograms

__init__(data, name, series, fitter=<function histogram>)

Create an SHistogramBarSet instance

Parameters
  • data (list) – If fitter is not None, data is the values that the fitter will compute the histogram from. If fitter is None, data is the pre-computed histogram values

  • name (str) – The name of this histogram set

  • series (SHistogramBarSeries) – The series this barset is part of

  • fitter (callable) – The function used to fit the histogram. By default it is the numpy.histogram function. Any user-supplied function should have the same api. Use None to indicate that the list of values in data are the precomputed histogram values and should not be recomputed.

fixLegend(legend)

Fix the legend marker shapes for this bar set

Parameters

legend (QLegend) – The legend containing markers for this set

updateHistogram(bin_settings)

Update the histogram based on the current bin settings

Parameters

bin_settings (str, int or list) – This is passed to the numpy.histogram method or the user’s supplied histogram method as the bins parameter. May be a string such as SChart.AUTO to indicate how the bins are to be determined. May be an integer to give the total number of bins, or may be a list of bin edge values.

Return type

(numpy.array, numpy.array)

Returns

The first array is the list of values, one for each bin of the histogram. The second array is the bin ediges. There is one more edge than bin.

class schrodinger.ui.qt.schart.SChart(master=None, title='', xtype=None, ytype=None, xlog=None, ylog=None, xtitle='', ytitle='', width=400, height=400, legend='right', tracker=True, tools=('zoom_in', 'axes', 'series', 'copy', 'legend'), colors=(<GlobalColor.blue: 9>, <GlobalColor.red: 7>, <GlobalColor.darkGreen: 14>, <PyQt6.QtGui.QColor object>, <GlobalColor.cyan: 10>, <GlobalColor.magenta: 11>, <GlobalColor.darkYellow: 18>, <GlobalColor.darkBlue: 15>, <GlobalColor.green: 8>, <GlobalColor.darkRed: 13>, <GlobalColor.gray: 5>, <GlobalColor.darkCyan: 16>, <GlobalColor.darkMagenta: 17>, <GlobalColor.yellow: 12>), viewclass=<class 'schrodinger.ui.qt.schart.SChartView'>, layout=None)

Bases: PyQt6.QtCharts.QChart

A customized implementation of the QChart class

LINE = 'line'
SCATTER = 'scatter'
RIGHT = 'right'
LEFT = 'left'
BOTTOM = 'bottom'
TOP = 'top'
ALIGNMENTS = {'bottom': AlignmentFlag.AlignBottom, 'left': AlignmentFlag.AlignLeft, 'right': AlignmentFlag.AlignRight, 'top': AlignmentFlag.AlignTop}
ZOOM = 'zoom_in'
AXES = 'axes'
SERIES = 'series'
COPY = 'copy'
LEGEND = 'legend'
BINS = 'bins'
DEFAULT_TOOLS = ['zoom_in', 'axes', 'series', 'copy', 'legend']
VALUE = 'value'
LOG = 'log'
CATEGORY = 'category'
BASE_10 = 10
AUTO = 'auto'
DEFAULT_AXIS_BUFFER_PCT = 10.0
DEFAULT_AXIS_FONT_SIZE = 0
DEFAULT_CATEGORY_LABEL_ANGLE = -60
DEFAULT_NONCATEGORY_LABEL_ANGLE = 0
DEFAULT_LEGEND_CB = True
COPY_RESOLUTION = 5
COLORS = (<GlobalColor.blue: 9>, <GlobalColor.red: 7>, <GlobalColor.darkGreen: 14>, <PyQt6.QtGui.QColor object>, <GlobalColor.cyan: 10>, <GlobalColor.magenta: 11>, <GlobalColor.darkYellow: 18>, <GlobalColor.darkBlue: 15>, <GlobalColor.green: 8>, <GlobalColor.darkRed: 13>, <GlobalColor.gray: 5>, <GlobalColor.darkCyan: 16>, <GlobalColor.darkMagenta: 17>, <GlobalColor.yellow: 12>)
__init__(master=None, title='', xtype=None, ytype=None, xlog=None, ylog=None, xtitle='', ytitle='', width=400, height=400, legend='right', tracker=True, tools=('zoom_in', 'axes', 'series', 'copy', 'legend'), colors=(<GlobalColor.blue: 9>, <GlobalColor.red: 7>, <GlobalColor.darkGreen: 14>, <PyQt6.QtGui.QColor object>, <GlobalColor.cyan: 10>, <GlobalColor.magenta: 11>, <GlobalColor.darkYellow: 18>, <GlobalColor.darkBlue: 15>, <GlobalColor.green: 8>, <GlobalColor.darkRed: 13>, <GlobalColor.gray: 5>, <GlobalColor.darkCyan: 16>, <GlobalColor.darkMagenta: 17>, <GlobalColor.yellow: 12>), viewclass=<class 'schrodinger.ui.qt.schart.SChartView'>, layout=None)

Create an SChart object

Parameters
  • master (QtWidgets.QWidget) – A QWidget - required for parenting dialogs

  • title (str) – The chart title

  • xtype (str) – The type of x axis. If None, it will be inferred.

  • ytype (str) – The type of y axis. If None, it will be inferred.

  • xlog (int) – The log base of the X axis (None for a non-log axis)

  • ylog (int) – The log base of the Y axis (None for a non-log axis)

  • xtitle (str) – The title of the X axis

  • ytitle (str) – The title of the Y axis

  • width (int) – The recommended minimum width (pixels) of the chart

  • height (int) – The recommended minimum height (pixels) of the chart

  • legend (str or None) – The alignment of the legend relative to the chart (one of the class legend side constants TOP, BOTTOM, RIGHT, LEFT), or None to not show the legend

  • tracker (bool) – Whether to show the label in the upper right corner that tracks the mouse coordinates

  • tools (tuple of str) – The tools to include in the toolbar - should be a tuple of class tools constants.

  • colors (list or None) – A list of colors to use when adding series without specifying the color explicitly. Use None to get the default QChart color cycle, which has 5 colors in the default theme and cycles repeatedly through them without noting which colors currently exist on the chart - leading often to multiple series with the same colors in dynamic charts. With colors specified, an attempt is made to reuse colors early in the list if no current series has that color, and no existing color is reused - instead a random color will be generated if all colors current exist on the chart.

  • viewclass (class or None) – The view class (not object) for this chart - typically a subclass of SChartView

  • layout (QtWidgets.QBoxLayout) – The layout to place this chart into

setupToolBar(layout)

Create the toolbar

Parameters

layout (QtWidgets.QBoxLayout) – The layout to place this toolbar into

getChartImage()

Get the chart image

Return type

QtGui.QImage

Returns

The chart image as a QImage

copyToClipboard()

Copy the chart image to the clipboard

exportImage(file_path)

Export the chart image to a file

Parameters

file_path (str) – The path to export the image to

Return type

bool

Returns

True if exported, False if export failed

openBinsDialog()

Open the dialog that allows the user to modify the histogram bins

getNextColor()

Get the next color to use for plotting a series. Colors at the beginning of the list will be reused if no series with that color currently exists. If all available colors are currently used, a random color will be generated.

Return type

QtGui.QColor or None

Returns

The next color to use for plotting, or None if there is no color list defined

static setSeriesSize(series, size)

Set the size for this series. This is marker size for scatter plots or thickness for line plots.

Parameters
  • series (QtCharts.QAbstractSeres) – The series to modify

  • size (int) – The size for the series

Raises

RuntimeError – If the series is not scatter or line

openSeriesDialog()

Open the dialog that allows user control of series parameters

openAxesDialog()

Open the dialog that allows user control of axis parameters

resetAxisLabels()

Reset axis labels’ angle and font size

resetView()

Unzoom the plot and reset the axes parameters if necessary

showLegend(show)

Set the legend visibility

Parameters

show (bool) – The legend visibility

hoverMoveEvent(event)

Catch the mouse moving in the chart and update the hover tracking label with its coordinates

Parameters

event (QtGui.QHoverEvent) – The event object

hoverLeaveEvent(event)

Hide the position tracker when the mouse leaves the chart area

Parameters

event (QtGui.QGraphicsSceneHoverEvent) – The hover leave event

addSeries(series)

Add the series to the chart

Note

This function changes the color of black series to a theme color - this is done automatically by QtCharts when adding a series

Parameters

series (QtCharts.QAbstractSeries) – The series to add to the chart

static changeAxisFontSize(axis, labels=0, title=0)

Change the font sizes for the axis

Parameters
  • axis (QAbstractAxis) – The axis

  • labels (int) – The font size for labels

  • title (int) – The font size for the title

static isLogAxis(axis)

Check if this axis is a log axis

Return type

bool

Returns

Whether the axis is log or not

static isValueAxis(axis)

Check if this axis is a value axis

Return type

bool

Returns

Whether the axis is value or not

toggleLogAxis(old_axis, base=10)

Change a linear axis to log, or vise versa

Parameters
  • old_axis (QAbstractAxis) – The axis to change

  • base (int) – The log base if changing to a log axis

Return type

QAbstractAxis

Returns

The new axis

Raises

RuntimeError – if old_axis is not a QLogValueAxis or QValueAxis

createAxis(side, title, log=10, unique=True, atype='value')

Create an axis on one side of the chart. Note that if an axis in that direction already exists, there will be multiple axes in that direction.

Parameters
  • side (str) – A side class constant giving the side of the chart the axis will be on

  • title (str) – The label for the axis

  • log (int) – The log base of the axis if a log axis is requested

  • unique (bool) – If True, remove any existing axis on this side. Any series attached to a removed axis must be manually attached to a new axis.

  • atype (str) – The type of axis. Should be a class axis type constant

Return type

QtCharts.QAbstractAxis

Returns

The axis that was created

setXMinMax(minimum=None, maximum=None, side='bottom')

Set the min and max values of the x axis

Parameters
  • minimum (float) – The minimum value of the axis

  • maximum (float) – The maximum value of the axis

  • side (str) – The side of the plot the desired axis is attached to. Must be a class side constant.

setYMinMax(minimum=None, maximum=None, side='left')

Set the min and max values of the y axis

Parameters
  • minimum (float) – The minimum value of the axis

  • maximum (float) – The maximum value of the axis

  • side (str) – The side of the plot the desired axis is attached to Must be a class side constant.

setAxisMinMax(axis, minimum, maximum)

Set the min and max values of an axis

Parameters
  • axis (QtCharts.QAbstractAxis) – The axis to set.

  • minimum (float) – The minimum value of the axis

  • maximum (float) – The maximum value of the axis

setXAutoRange(buffer=0, buffer_pct=10.0, side='bottom')

Automatically set the x axis range based on the min and max values of the plotted data

Parameters
  • buffer (float) – Additional absolute amount to increase the axis range beyond the min and max plotted values (0 will truncate the axis at exactly the min and max values)

  • buffer_pct (float) – Additional percent amount to increase the axis range beyond the min and max plotted values. The percent is computed of the entire range and then applied to both the low and high end of the axis.

  • side (str) – The side of the plot the desired axis is attached to Must be a class side constant.

setYAutoRange(buffer=0, buffer_pct=10.0, side='left')

Automatically set the y axis range based on the min and max values of the plotted data

Parameters
  • buffer (float) – Additional absolute amount to increase the axis range beyond the min and max plotted values (0 will truncate the axis at exactly the min and max values)

  • buffer_pct (float) – Additional percent amount to increase the axis range beyond the min and max plotted values. The percent is computed of the entire range and then applied to both the low and high end of the axis.

  • side (str) – The side of the plot the desired axis is attached to Must be a class side constant.

static getAxisDataRange(axis, series)

Find the range of data attached to the given axis

Parameters
  • axis (QtCharts.QAbstractAxis) – The axis

  • series (list) – The current list of data series

Return type

float, float

Returns

The min and max data values. numpy.inf is returned if there is no associated data

setAxisAutoRange(axis, buffer=0, buffer_pct=10.0)

Automatically set the y axis range based on the min and max values of the plotted data

Parameters
  • axis (QtCharts.QAbstractAxis) – The axis to set.

  • buffer (float) – Additional absolute amount to increase the axis range beyond the min and max plotted values (0 will truncate the axis at exactly the min and max values)

  • buffer_pct (float) – Additional percent amount to increase the axis range beyond the min and max plotted values. The percent is computed of the entire range and then applied to both the low and high end of the axis.

warning(msg, **kwargs)

Pop up a warning dialog with the given message

Parameters

msg (str) – The message to display

getSideAxis(side)

Get the axis associated with the given side of the chart. If more than one axis is associated with that side, the first one is returned.

Parameters

side (str) – The side of the plot the desired axis is attached to. Must be a class side constant.

Return type

QtCharts.QAbstractAxis

Returns

The axis attached to this side of the chart

Raises
  • KeyError – if side is not a valid constant

  • ValueError – If no such axis exists

property bottom_axis

Get the axis on the bottom. Will return the first one if more than one exist

Raises

ValueError – If no such axis exists

Return type

QtCharts.QAbstractAxis

Returns

The axis attached to the bottom side of the chart

property left_axis

Get the axis on the left. Will return the first one if more than one exist

Raises

ValueError – If no such axis exists

Return type

QtCharts.QAbstractAxis

Returns

The axis attached to the left side of the chart

property top_axis

Get the axis on the top. Will return the first one if more than one exist

Raises

ValueError – If no such axis exists

Return type

QtCharts.QAbstractAxis

Returns

The axis attached on the top side of the chart

property right_axis

Get the axis on the right. Will return the first one if more than one exist

Raises

ValueError – If no such axis exists

Return type

QtCharts.QAbstractAxis

Returns

The axis attached on the right side of the chart

static getSeriesXVals(series)

Get the x values for a series

Parameters

series (QtCharts.QXYSeries) – The series to get data from

Return type

list

Returns

The x values of all points in the series

Raises

ValueError – if series is not a supported type

static getSeriesYVals(series)

Get the y values for a series. Note that for bar series, ALL the y values of all the bar sets are returned as a single list.

Parameters

series (QtCharts.QAbstractSeries) – The series to get data from. Only QXYSeries and QBarSeries are currently supported

Return type

list

Returns

The y values of all points in the series

Raises

ValueError – if series is not a supported type

addDataSeries(name, xvals, yvals=None, series_type=None, color=None, shape=None, size=None, line_style=PenStyle.SolidLine, legend=True, autorange=True, fit=False, fitter=None, xside='bottom', yside='left')

Add a new data series to the chart

Parameters
  • name (str) – The name of the series - this will be the name of the series shown in the legend

  • xvals (list of float or list of tuple) – Either a list of x data, or a list of (x, y) tuples

  • yvals (list) – List of y data if xvals is not (x, y) tuples

  • series_type (str) – The series type - must be a class series type constant

  • color (QtGui.QColor or Qt.GlobalColor constant or None) – The color for this series. If None, a color from the current color list will be used.

  • shape (QtCharts.QScatterSeries.MarkerShape) – For scatter series, the shape of the markers

  • size (int) – For scatter series, the size of the markers. For line series, the thickness of the line.

  • line_style (int) – Type of the line. Values from Qt::PenStyle enum

  • legend (bool) – Whether the series should show in the legend

  • autorange (bool) – Whether to auto-set the axes ranges after adding this series

  • fit (bool) – Whether to add a trendline to the series

  • fitter (callable) – A function to call to fit the trendline. Must follow the API of the fitLine method

  • xside (str) – The X axis side to attach the series to. Should be either BOTTOM or TOP

  • yside (str) – The Y axis side to attach the series to. Should be either LEFT or RIGHT

Return type

SeriesData

Returns

The newly created series will be in the SeriesData.series property. If a trendline is added, data about the trendline will also be included.

addHistogram(name, values, bin_settings='auto', bar_series=None, color=None, size=1, legend=True, fitter=<function histogram>, xside='bottom', yside='left', barset_class=<class 'schrodinger.ui.qt.schart.SHistogramBarSet'>, barseries_class=<class 'schrodinger.ui.qt.schart.SHistogramBarSeries'>)

Add a new histogram to the chart.

Note that for QCharts, a “bar set” is a set of bars that make up a histogram (or other data related by a bunch of bars). A “bar series” is a collection of one or more bar sets. For instance, if you wanted to display two different histograms on the same chart in the same location. A bar set is much more analogous to a normal QXYSeries than a bar series is.

Parameters
  • name (str) – The name of the histogram - this will be the name of the series shown in the legend

  • values (list) – The set of values from which the histogram will be computed. See also the fitter parameter.

  • bin_settings (str, int or list) – This is passed to the numpy.histogram method or the user’s supplied histogram method as the bins parameter. May be a string such as SChart.AUTO to indicate how the bins are to be determined. May be an integer to give the total number of bins, or may be a list of bin edge values. See also the bar_series parameter.

  • bar_series (SHistogramBarSeries) – An existing series that this histogram should be associated with. If used, the value of bin_settings is ignored if the bar_series has existing edges.

  • color (QtGui.QColor or Qt.GlobalColor constant or None) – The color for this histogram. If None, a color from the current color list will be used.

  • size (int) – The width of the histogram bars. 1 indicates bars that should touch but not overlap. Values < 1 will leave a proportionate amount of space between the bars.

  • legend (bool) – Whether the series should show in the legend

  • fitter (callable) – A function to call to compute the histogram using the data in values. Must follow the API of the numpy.histgram function. If None, then the data in values is considered the pre-computed histogram and will be used directly without modification. In this case, the bin_settings should be the list of bin edges.

  • xside (str) – The X axis side to attach the series to. Should be either BOTTOM or TOP

  • yside (str) – The Y axis side to attach the series to. Should be either LEFT or RIGHT

  • barset_class (class) – The class to use to create the bar set for this histogram

  • barseries_class (class) – The class to use to create the bar series this histogram should be attached to.

Return type

SeriesData

Returns

The bar series will be in the SeriesData.series property. The new bar set will be in the SeriesData.bar_set property.

seriesHovered(point, is_hovered)

Callback for when the mouse is over a point in the series

Parameters
  • point (QtCore.QPointF) – The point the mouse is over

  • is_hovered – True if the mouse is over the point, False if the mouse left the point.

barsHovered(is_hovered, index)

Callback for when the mouse is over a bar in a bar set

Parameters
  • is_hovered – True if the mouse is over the bar, False if the mouse left the bar.

  • index (int) – The index of the bar the mouse is over. It may belong to one of many different bar sets

addAndAttachSeries(series, xside='bottom', yside='left')

Add the series to the chart and attach it to the x and y axes

Parameters
  • series (QtCharts.QAbstractSeries) – The series to add to the chart

  • xside (str) – The X axis side to attach the series to. Should be either BOTTOM or TOP

  • yside (str) – The Y axis side to attach the series to. Should be either LEFT or RIGHT

addTrendLine(data, name=None, fitter=None)

Add a trendline to a series

Parameters
  • data (SeriesData) – The SeriesData that contains the series to add the trendline to

  • name (str) – The name of the trendline series

  • fitter (callable) – The function to fit the data. Must have the same API as the fitLine method.

showSeriesInLegend(series, show=True)

Set the visibility of the given series in the legend

Parameters
  • series (QtCharts.QAbstractSeries) – The series to set the visibility for

  • show (bool) – Whether to show the series or not

setSingleClickable()

When set, clicking once on a plot object will emit a “clicked” signal (as opposed to the default behavior of requiring a double click).

resetLegendCB()

Set default state of legend_checkbox and show legend if shown by default and if the legend exists

reset()

Remove all the series from the chart, resets the view, and resets axis labels

class schrodinger.ui.qt.schart.Callout(chart, series, pos, text_list)

Bases: PyQt6.QtWidgets.QGraphicsItem

A callout is a rounded rectangle that displays values for a point on a QChart

__init__(chart, series, pos, text_list)
paint(self, painter: Optional[QPainter], option: Optional[QStyleOptionGraphicsItem], widget: Optional[QWidget] = None)
generateBoundingRect()

Creates a bounding rect based on text length/height and chart position

boundingRect(self) QRectF