Plots

Plots in Boomslang are constructed by adding plot elements to Plot objects. The Plot object’s API is defined below.

class boomslang.Plot.Plot

Represents a single plot, usually consisting of a single X and Y axis.

add(plottableObject)

Add a plottable object (a Line, Bar, etc.) to this plot, causing it to be drawn when the plot is drawn.

addInset(plot, **kwargs)

Add plot (a Plot object) as an inset to this plot object.

Valid arguments are as follows:

Argument Description
width The width of the inset as a fraction of the size of the parent plot
height The height of the inset as a fraction of the size of the parent plot
location The location of the inset. See Locations for valid locations.
padding The amount of padding between the edge of the parent plot and the inset as a fraction of the size of the parent plot
addLineColor(color)

Add a line color to the list of line colors through which the plot will cycle when drawing lines. If no line colors are specified, the line colors specified by the Line objects themselves will be used.

Note that, when drawing lines, all line styles for a given color are cycled through before another color is used.

addLineStyle(style)

Add a line style to the list of line styles through which the plot will cycle when drawing lines. If no line styles are specified, the plot will default to the line style specified in the Line objects themselves.

Note that, when drawing lines, all line styles for a given color are cycled through before another color is used.

addMarker(marker)

Add a marker style to the list of marker styles through which the plot will cycle when drawing lines. If no markers are specified, the markers specified by the Line objects themselves will be used.

Note that, when drawing lines, all line style/color combinations are cycled through with a given marker before a new marker is chosen.

axesLabelSize = None

The size of the text used for labeling the x and y axes.

drawPlot(fig, ax)

Used by PlotLayout to plot the graph at a given location in the layout.

getDimensions()

Get the dimensions of this plot.

grid

A boomslang.Grid.Grid that defines the properties of this plot’s grid lines. See Grid Lines for configuration options.

hasFigLegend(columns=1, location='best', scatterPoints=3, draw_frame=True, bbox_to_anchor=None, labelSize=None, title=None, labelOrdering=None, leftToRight=False)

Declare that the figure has a legend with a given number of columns and location.

hasLegend(columns=1, location='best', scatterPoints=3, draw_frame=True, bbox_to_anchor=None, labelSize=None, title=None, labelOrdering=None, leftToRight=False)

Declare that the plot has a legend with a given number of columns and location.

hideTicks = None

If True, this plot’s tick labels are hidden.

legendLabelSize

The size of the text in this plot’s legend.

logbase = None

The base of the logarithm used to draw log scale axes.

logbasex = None

The base of the logarithm used to draw the x-axis. Overrides logbase, and only takes effect if logx or loglog are True.

logbasey = None

The base of the logarithm used to draw the y-axis. Overrides logbase, and only takes effect if logy or loglog are True.

loglog = None

If true, both this plot’s axes will be drawn in log scale.

logx = None

If true, this plot’s x-axis will be drawn in log scale.

logy = None

If true, this plot’s y-axis will be drawn in log scale.

plot()

Draw this plot to a matplotlib canvas.

projection = None

Defines the projection used when drawing this plot. The only currently supported value other than the standard (no projection) is ‘polar’.

save(filename, **kwargs)

Save this plot to a file.

setDimensions(width=None, height=None, dpi=100)

Set the dimensions for this plot to width x height

setPlotParameters(**kwdict)

Set the margins of this plot. See matplotlib’s SubplotParams documentation for more details. It is recommended that you set boomslang.Plot.Plot.tight to True instead of setting these parameters.

setTitleProperties(**propList)

Set the properties of the title. See Labels for more information about valid properties.

setTwinX(label, index, yMin=None, yMax=None)

Make the plot use a secondary y-axis with the provided label. All registered plottable objects at or after the given index will use this second axis.

setXFormatter(formatter)

Set the x-axis formatter used by this plot to the given function.

setYFormatter(formatter)

Set the y-axis formatter used by this plot to the given function.

split(pieces)

Split this plot into pieces separate plots, each showing a different portion of the x-axis

tight = None

If True, this plot is auto-scaled so that axis labels don’t get cut off.

title = None

The plot’s title (will be centered above the axes themselves)

titleSize = None

The size of the text used for plot title.

xLabel = None

The label for the plot’s x-axis

xLabelProperties

A dictionary of properties that control the appearance of the X axis’ axis label. See Labels for more information on which properties can be set.

xLimits

A pair giving the minimum and maximum values visible on the x-axis.

xTickLabelSize = None

The size of the text used for x-axis tick labels

yLabel = None

The label for the plot’s y-axis

yLabelProperties

A dictionary of properties that control the appearance of the Y axis’ axis label. See Labels for more information on which properties can be set.

yLimits

A pair giving the minimum and maximum values visible on the x-axis.

yTickLabelSize = None

The size of the text used for y-axis tick labels

Grid Lines

boomslang.Plot.Plot.grid is a boomslang.Grid.Grid object that defines the appearance of the plot’s grid lines. By default, there are no grid lines.

class boomslang.Grid.Grid(color='#dddddd', style='-', width=0.5, visible=True)

The Grid plot element defines a set of gridlines that are displayed behind all other plot elements

color = None

The color of the gridlines; see Colors for more information on available colors.

lineWidth = None

The width of gridlines.

style

The style of the grid’s lines; see Line Styles for more information about available line styles.

visible = None

If True, the grid’s lines are visible. If False, they are invisible.

which = None

If “major”, the plot’s major ticks have grid lines. If “minor”, the plot’s minor ticks have grid lines. If “both”, both major and minor ticks have grid lines.

Locations

Parts of a plot like legends and insets allow the user to explicitly specify their location (by default, matplotlib tries do to place the legend/inset where it is least obtrusive). Boomslang defines the standard matplotlib location strings along with a number of aliases that some find more intuitive than the defaults.

Valid location strings (clockwise from top middle, plus centered) are as follows:

  • “upper center”, “top middle” “upper middle”
  • “upper right”, “top right”
  • “center right”, “middle right”, “right”
  • “lower right”, “bottom right”
  • “lower center”, “bottom middle”, “bottom center”
  • “lower left”, “bottom left”
  • “center left”, “middle left”, “left”,
  • “upper left”, “top left”
  • “center”, “middle”