Drawing¶
Clusters¶
Useful functions to draw clusters
Networks¶
Functions to visualise networks and temporal networks
- draw_graph(graph, ax=None, label_nodes=True, color='mediumseagreen')[source]¶
Basic graph drawing function
- Parameters
graph (networkx.Graph) –
ax (matplotlib.Axes, optional) – Axes on which to draw the graph
label_nodes (bool, optional) – Whether to label the nodes or just leave them as small circles (default True)
color (str, optional) – Color to use for the graph nodes and edges (default mediumseagreen)
- Returns
- Return type
None
- highlight_subgraphs(graphs, colors, ax=None, label_nodes=True)[source]¶
Draw multiple nested subgraphs on the same axes
- Parameters
graphs (list of networkx.Graph) –
colors (list of str) – List of colours, one for each of the graphs in ‘graphs’
ax (matplotlib.Axes, optional) – Axes to plot on
label_nodes (bool, optional) – Whether or not to label the graph nodes or leave them as circles
- Returns
- Return type
None
Drawing¶
Useful drawing functions
- plot_events(events, ax=None, text_y_pos=None, text_x_offset=0, period=None, n_periods=1, add_labels=True, orientation='vertical', zorder=- 1, alpha=1, va='bottom')[source]¶
Plot events as vertical lines on axes
- Parameters
events (list of tuples (time, name, line_style)) – time - time at which the event occurred name - the name of the event line_style - any string accepted by matplotlib.lines.Line2D.set_linestyle
ax (matplotlib.Axes, optional) – Axes on which to plot the events
text_y_pos (float, optional) – Height at which to place the name of the event (default None)
text_x_offset (float, optional) – Distance along x-axis by which to offset the placement of the event name (default 0)
period (float or None, optional) – Length of time of one period, if events repeat periodically.
n_periods (int, optional) – Number of periods to draw, if events repeat periodically.
add_labels (bool, optional) – Wether to display the label of each vertical line, True by default.
- Returns
- Return type
None
- plot_interval(binary_series, times, y=0, peak=None, color='k', ax=None, zorder=0)[source]¶
Plot a binary series as a sequence of coloured intervals
Specifically, when a binary series has value 1, plot it as a continuous rectangular interval. When it has value 0 do nothing.
- Parameters
binary_series (ndarray) – 2D array of binary data to plot
times (ndarray) – 1D array consisting of the corresponding time points
y (float, optional) – Height (y-axis value) at which to plot the interval (default 0)
color (str, optional) – Color to use for the intervals (default ‘k’)
ax (matplotlib.Axes, optional) – Axes to plot on
zorder (int, optional) – Height on the z-axis which to plot the interval (default 0)
- Returns
- Return type
None
- plot_phases(phases, ax=None, y_pos=None, ymin=0, ymax=1, t_offset=0)[source]¶
Plot phases as shaded regions on axes
- Parameters
phases (list of tuples (start_time, end_time, name)) –
ax (matplotlib.Axes) – Axes on which to plot the phases
y_pos (float or None, optional) – Height at which to place the name of the phase
ymin (float, optional) – Height at which to start shaded region (default 0)
ymax (float, optional) – Height at which to stop shaded region (default 1)
t_offset (float, optional) – Offset of phase on the time axis
- Returns
- Return type
None
- threshold_plot(x, y, threshold, color_below_threshold, color_above_threshold, ax=None)[source]¶
Plot values above a certain threshold in a particular colour
- Parameters
x (array) – 1D array of alues to plot along x-axis
y (array) – 1D array of values to plot along y-axis
threshold (float) – Only plot in colour the points (x,y) with y >= threshold
colour_below_threshold (str) – Colour to use for points below threshold
colour_above_threshold (list of str) – Colour to use for points above threshold
ax (matplotlib.Axes, optional) – Axes to use
- Returns
- Return type
None
Utils¶
General utility functions for plots
- adjust_margin(ax=None, top=0, bottom=0, left=0, right=0)[source]¶
Extend the margin of a plot by a percentage of its original width/height
- Parameters
ax (matplotlib.Axes, optional) – Axes whose margins to adjust
top (float, optional) – Percentage (as decimal) by which to increase top margin
bottom (float, optional) – Percentage (as decimal) by which to increase bottom margin
left (float, optional) – Percentage (as decimal) by which to increase left margin
right (float, optional) – Percentage (as decimal) by which to increase right margin
- Returns
- Return type
None
Method to tidy up cases where we have a grid of plots with shared axes, by deleting unused subplots (if number of of subplots is not rectangular) and adding axes ticks
- Parameters
rows (int) – Number of rows in the grid of subplots
columns (int) – Number of columns in the grid of subplots
total_subplots (int) – Number of subplots in the grid; need not be a ‘rectangular’ number
xlabel (str) – Label of the x-axis
ylabel (str) – Label of the y-axis
fig (matplotlib.Figure) – Figure that the subplots are a part of
axes (list of matplotlib.Axes) – Axes containing the subplots
- Returns
- Return type
None