schrodinger.application.desmond.mplchart module

Tools for using matplotlib charts.

Copyright Schrodinger, LLC. All rights reserved.

schrodinger.application.desmond.mplchart.remove_temp_dir(path)

Remove the temporary directory we created

schrodinger.application.desmond.mplchart.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.
schrodinger.application.desmond.mplchart.get_xy_plot_widget(xvals, *ylists, **kw)

Create a scatter or line chart. The line chart may optionally have error bars associated with it. Multiple series can be plotted by passing in more than one list of y values, i.e. get_xy_plot(x, y1, y2, chart_type=’scatter’)

The plot is returned in a QFrame widget.

Parameters:
  • xvals (list) – the x values to plot
  • ylists (one or more lists) – Each y series to plot should be given as an argument to the function, and each should be the same length as x
  • err_y (list of lists) – the i’th item of err_y is a list of numerical error bars, one for each item in the i’th y list
  • chart_type (str) – type of chart to produce - scatter: scatterplot - line: line (default)
  • marker (tuple) –
    tuple of (symbol, color, size), only used for scatter plots
    • 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
    • color (str)
      • black
      • red
      • green
      • blue
      • purple
      • yellow
      • orange
      • violet
      • skyblue
      • gold
      • grey
    • size (int)
  • size (tuple) – (x, y) plot size
  • x_label (str) – X-axis label
  • y_label (str) – Y-axis label
  • x_range (tuple) – (min, max) values for the X-axis
  • y_range (tuple) – (min, max) values for the Y-axis
  • color (list) – list of color names to cycle through. See marker:color for some color names.
  • bg (str) – color name for the plot background. See marker:color for some color names.
  • legend (list) – list of strings, each item is the name of a y series in the legend
  • title (str) – the title of the plot
  • dpi (int) – dots per inch for the plot
  • fontsize (int or str) – size in points, or one of the following - - xx-small - x-small - small - medium - large - x-large - xx-large
Return type:

QFrame

Returns:

The QFrame widget that contains the plot

schrodinger.application.desmond.mplchart.get_xy_plot(xvals, *ylists, **kw)

Create a scatter or line chart. The line chart may optionally have error bars associated with it. Multiple series can be plotted by passing in more than one list of y values, i.e. get_xy_plot(x, y1, y2, chart_type=’scatter’)

The plot is saved as an image file, the filename parameter should contain the path to the file to write. filename is written and the value of filename is simply returned.

Parameters:
  • xvals (list) – the x values to plot
  • ylists (one or more lists) – Each y series to plot should be given as an argument to the function, and each should be the same length as x
  • err_y (list of lists) – the i’th item of err_y is a list of numerical error bars, one for each item in the i’th y list
  • chart_type (str) – type of chart to produce - scatter: scatterplot - line: line (default)
  • marker (tuple) –
    tuple of (symbol, color, size), only used for scatter plots
    • 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
    • color (str)
      • black
      • red
      • green
      • blue
      • purple
      • yellow
      • orange
      • violet
      • skyblue
      • gold
      • grey
    • size (int)
  • size (tuple) – (x, y) plot size
  • x_label (str) – X-axis label
  • y_label (str) – Y-axis label
  • x_range (tuple) – (min, max) values for the X-axis
  • y_range (tuple) – (min, max) values for the Y-axis
  • color (list) – list of color names to cycle through. See marker:color for some color names.
  • bg (str) – color name for the plot background. See marker:color for some color names.
  • legend (list) – list of strings, each item is the name of a y series in the legend
  • title (str) – the title of the plot
  • dpi (int) – dots per inch for the plot
  • fontsize (int or str) – size in points, or one of the following - - xx-small - x-small - small - medium - large - x-large - xx-large
  • filename (str) – The pathway to a file that the image of this plot should be saved in.
  • format (str) – the image format to save the chart in. Must be a matplotlib-recognized format argument to Figure.savefig(format=nnn). Default is nnn=’png’
Return type:

filename

Returns:

The filename the image of the plot was saved into (same string as passed in with the filename keyword).

schrodinger.application.desmond.mplchart.create_mpl_plot_on_figure(figure, xvals, *ylists, **kw)

Create a scatter or line chart. The line chart may optionally have error bars associated with it. Multiple series can be plotted by passing in more than one list of y values, i.e. get_xy_plot(x, y1, y2, chart_type=’scatter’)

Parameters:
  • figure (matplotlib Figure object) – the Figure object the plot should be created on.
  • xvals (list) – the x values to plot
  • ylists (one or more lists) – Each y series to plot should be given as an argument to the function, and each should be the same length as x
  • err_y (list of lists) – the i’th item of err_y is a list of numerical error bars, one for each item in the i’th y list
  • chart_type (str) – type of chart to produce - scatter: scatterplot - line: line (default)
  • marker (tuple) –
    tuple of (symbol, color, size), only used for scatter plots
    • 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
    • color (str)
      • black
      • red
      • green
      • blue
      • purple
      • yellow
      • orange
      • violet
      • skyblue
      • gold
      • grey
    • size (int)
  • x_label (str) – X-axis label
  • y_label (str) – Y-axis label
  • x_range (tuple) – (min, max) values for the X-axis
  • y_range (tuple) – (min, max) values for the Y-axis
  • color (list) – list of color names to cycle through. See marker:color for some color names.
  • bg (str) – color name for the plot background. See marker:color for some color names.
  • legend (list) – list of strings, each item is the name of a y series in the legend
  • title (str) – the title of the plot
  • fontsize (int or str) – size in points, or one of the following - - xx-small - x-small - small - medium - large - x-large - xx-large
schrodinger.application.desmond.mplchart.get_2var_plot(data, **kw)

Create a 2d contour or 3d surface plot.

The plot is saved as an image file, the filename parameter should contain the path to the file to write. filename is written and the value of filename is simply returned.

Parameters:
  • data (list of tuples) – the (x, y, z) values to plot. List items should be arranged so they are sorted by X and then by Y (so that the Y varies faster than X), and there is a Z value for every X/Y combination.
  • chart_type (str) – type of chart to produce - contour: 2d contour - surface: 3d surface - wireframe: 3d wireframe surface
  • size (tuple) – (x, y) plot size
  • x_label (str) – X-axis label
  • y_label (str) – Y-axis label
  • z_label (str) – Z-axis label (surface and wireframe only)
  • x_range (tuple) – (min, max) values for the X-axis. (contour plots only)
  • y_range (tuple) – (min, max) values for the Y-axis (contour plots only)
  • x_reverse (bool) – True if the X axis should be reversed, False (default) if not
  • y_reverse (bool) – True if the Y axis should be reversed, False (default) if not
  • z_reverse (bool) – True if the Z axis should be reversed, False (default) if not (surface and wireframe only)
  • color_map (str) – Name of a matplotlib color map
  • color_range (tuple) – (min, max) of the color range. Values of min and below will get the minimum color, values of max and above will get the maximum color. Setting all the contour levels with the levels keyword may the be preferred way of accomplishing this.
  • bg (str) – color name for the plot background.
  • legend (bool) – True if a colorbar legend that shows the contour levels should be included, False if not (False is default)
  • legend_format (str) – String format specifier for the colorbar legend. This format is also used for contour labels.
  • legend_orientation (str) – Either ‘vertical’ (default) or ‘horizontal’
  • title (str) – the title of the plot
  • dpi (int) – dots per inch for the plot
  • fontsize (int or str) – size in points, or one of the following - - xx-small - x-small - small - medium - large - x-large - xx-large
  • filename (str) – The pathway to a file that the image of this plot should be saved in.
  • format (str) – the image format to save the chart in. Must be a matplotlib-recognized format argument to Figure.savefig(format=nnn). Default is nnn=’png’
  • fill (bool) – True if the contours should be filled, False (default) if lines on a white background (contour plots only)
  • labels (bool) – True (default) if the contour lines should be labeled, False if not (contour plots only)
  • contours (int) – The number of contour lines to draw (default of 0 indicates that matplotlib should choose the optimal number) (contour plots only)
  • levels (list) – list of values to place contour lines at (contour plots only)
  • viewpoint (tuple of 2 float) – (a, b) describing the point of view from which the plot is viewed, where a is the elevation and b is the rotation of the plot. Default is (45, 45). (surface and wireframe only)
Return type:

filename

Returns:

The filename the image of the plot was saved into (same string as passed in with the filename keyword).

schrodinger.application.desmond.mplchart.create_contour_plot_on_figure(figure, data, **kw)

Create a 2d contour or 3d surface plot.

The plot is saved as an image file, the filename parameter should contain the path to the file to write. filename is written and the value of filename is simply returned.

Parameters:
  • figure (matplotlib Figure object) – the Figure object the plot should be created on.
  • data (list of tuples) – the (x, y, z) values to plot. List items should be arranged so they are sorted by X and then by Y (so that the Y varies faster than X), and there is a Z value for every X/Y combination.
  • x_label (str) – X-axis label
  • y_label (str) – Y-axis label
  • x_range (tuple) – (min, max) values for the X-axis
  • y_range (tuple) – (min, max) values for the Y-axis

type x_reverse: bool :keyword x_reverse: True if the X axis should be reversed, False (default)

if not

type y_reverse: bool :keyword y_reverse: True if the Y axis should be reversed, False (default)

if not
Parameters:
  • color_map (str) – Name of a matplotlib color map
  • color_range (tuple) – (min, max) of the color range. Values of min and below will get the minimum color, values of max and above will get the maximum color. Setting all the contour levels with the levels keyword may the be preferred way of accomplishing this.
  • bg (str) – color name for the plot background.
  • legend (bool) – True if a colorbar legend that shows the contour levels should be included, False if not (False is default)
  • legend_format (str) – String format specifier for the colorbar legend. This format is also used for contour labels.
  • legend_orientation (str) – Either ‘vertical’ (default) or ‘horizontal’
  • title (str) – the title of the plot
  • fontsize (int or str) – size in points, or one of the following - - xx-small - x-small - small - medium - large - x-large - xx-large
  • filename (str) – The pathway to a file that the image of this plot should be saved in.
  • fill (bool) – True if the contours should be filled, False (default) if lines on a white background
  • labels (bool) – True (default) if the contour lines should be labeled, False if not
  • contours (int) – The number of contour lines to draw (default of 0 indicates that matplotlib should choose the optimal number)
  • levels (list) – list of values to place contour lines at
schrodinger.application.desmond.mplchart.create_surface_on_figure(figure, data, **kw)

Create a 2d contour or 3d surface plot.

The plot is saved as an image file, the filename parameter should contain the path to the file to write. filename is written and the value of filename is simply returned.

Parameters:
  • figure (matplotlib Figure object) – the Figure object the plot should be created on.
  • data (list of tuples) – the (x, y, z) values to plot. List items should be arranged so they are sorted by X and then by Y (so that the Y varies faster than X), and there is a Z value for every X/Y combination.
  • x_label (str) – X-axis label
  • y_label (str) – Y-axis label
  • z_label (str) – Y-axis label
  • x_reverse (bool) – True if the X axis should be reversed, False (default) if not
  • y_reverse (bool) – True if the Y axis should be reversed, False (default) if not
  • z_reverse (bool) – True if the Z axis should be reversed, False (default) if not
  • bg (str) – color name for the plot background.
  • legend (bool) – True if a colorbar legend that shows the surface levels should be included, False if not (False is default). Surface only.
  • legend_format (str) – String format specifier for the colorbar legend.
  • legend_orientation (str) – Either ‘vertical’ (default) or ‘horizontal’
  • title (str) – the title of the plot
  • fontsize (int or str) – size in points, or one of the following - - xx-small - x-small - small - medium - large - x-large - xx-large
  • viewpoint (tuple of 2 float) – (a, b) describing the point of view from which the plot is viewed, where a is the elevation and b is the rotation of the plot. Default is (45, 45).