badcrossbar.plotting package#

Submodules#

badcrossbar.plotting.color_bar module#

badcrossbar.plotting.color_bar.axis_label(ctx, color_bar_pos, color_bar_dims, label='Current (A)')[source]#

Draws axis label of a color bar.

Parameters
  • ctx (Context) – Context.

  • color_bar_pos (tuple[float, float]) – Coordinates of the top left point of the color bar.

  • color_bar_dims (tuple[float, float]) – Width and height of the color bar.

  • label (str) – Axis label of the color bar.

badcrossbar.plotting.color_bar.dimensions(surface_dims, color_bar_fraction, border_fraction)[source]#

Extracts dimensions of the color bar.

Parameters
  • surface_dims (tuple[float, float]) – Dimensions of the surface.

  • color_bar_fraction (tuple[float, float]) – The fraction of the surface that the color bar region will take on the right (vertically and horizontally).

  • border_fraction (float) – Fraction of the max_dim that will be blank on all sides of the surface.

Returns

Coordinates of the top left point of the color bar. color_bar_dims: Width and height of the color bar.

Return type

color_bar_pos

badcrossbar.plotting.color_bar.draw(ctx, color_bar_pos, color_bar_dims, low, high, **kwargs)[source]#

Draws the color bar together with its labels.

Parameters
  • ctx (Context) – Context.

  • color_bar_pos (tuple[float, float]) – Coordinates of the top left point of the color bar.

  • color_bar_dims (tuple[float, float]) – Width and height of the color bar.

  • low (float) – Lower limit of the linear range.

  • high (float) – Upper limit of the linear range.

  • **axis_label – Axis label of the color bar.

badcrossbar.plotting.color_bar.rectangle(ctx, color_bar_pos, color_bar_dims, low, high, **kwargs)[source]#

Draws rectangle with color gradient.

Parameters
  • ctx (Context) – Context.

  • color_bar_pos (tuple[float, float]) – Coordinates of the top left point of the color bar.

  • color_bar_dims (tuple[float, float]) – Width and height of the color bar.

  • low (float) – Lower limit of the linear range.

  • high (float) – Upper limit of the linear range.

  • **low_rgb – Normalized RGB value associated with the lower limit.

  • **zero_rgb – Normalized RGB value associated with value of zero.

  • **high_rgb – Normalized RGB value associated with the upper limit.

Return type

bool

Returns

If False, only two colors were used for the gradient.

badcrossbar.plotting.color_bar.rgb(low, high, low_rgb, zero_rgb, high_rgb)[source]#

Extracts RGB values for the color bar gradient.

Parameters
  • low (float) – Lower limit of the linear range.

  • high (float) – Upper limit of the linear range.

  • low_rgb (tuple[float, float, float]) – Normalized RGB value associated with the lower limit.

  • zero_rgb (tuple[float, float, float]) – Normalized RGB value associated with the value of zero.

  • high_rgb (tuple[float, float, float]) – Normalized RGB value associated with the upper limit.

Return type

tuple[tuple[float, float, float], tuple[float, float, float], tuple[float, float, float]]

Returns

RGB values for the bottom, middle and top parts of the color map gradient. If only two colors are used, middle_rgb is returned as None.

badcrossbar.plotting.color_bar.tick_labels(ctx, middle, low, high, color_bar_pos, color_bar_dims)[source]#

Draws tick labels of the color bar.

Parameters
  • ctx (Context) – Context.

  • middle (bool) – If False, only two colors were used for the gradient.

  • low (float) – Lower limit of the linear range.

  • high (float) – Upper limit of the linear range.

  • color_bar_pos (tuple[float, float]) – Coordinates of the top left point of the color bar.

  • color_bar_dims (tuple[float, float]) – Width and height of the color bar.

badcrossbar.plotting.crossbar module#

badcrossbar.plotting.crossbar.bit_lines(ctx, bit_line_vals, diagram_pos, low, high, segment_length=120, crossbar_shape=(128, 64), **kwargs)[source]#

Draws bit lines.

Parameters
  • ctx (Context) – Context.

  • bit_line_vals (ndarray[Any, dtype[TypeVar(ScalarType, bound= generic, covariant=True)]]) – Values associated with the interconnect segments along the bit lines.

  • diagram_pos (tuple[float, float]) – Coordinates of the top left point of the diagram.

  • low (float) – Lower limit of the linear range.

  • high (float) – Upper limit of the linear range.

  • segment_length (float) – The length of each segment.

  • crossbar_shape (tuple[int, int]) – Shape of the crossbar array. Used when bit_line_vals is None.

  • **default_color – Normalized RGB values of the bit lines if their values are not provided.

badcrossbar.plotting.crossbar.devices(ctx, device_vals, diagram_pos, low, high, segment_length=120, crossbar_shape=(128, 64), **kwargs)[source]#

Draws crossbar devices.

Parameters
  • ctx (Context) – Context.

  • device_vals (ndarray[Any, dtype[TypeVar(ScalarType, bound= generic, covariant=True)]]) – Values associated with crossbar devices.

  • diagram_pos (tuple[float, float]) – Coordinates of the top left point of the diagram.

  • low (float) – Lower limit of the linear range.

  • high (float) – Upper limit of the linear range.

  • segment_length (float) – The length of each segment.

  • crossbar_shape (tuple[int, int]) – Shape of the crossbar array. Used when device_vals is None.

  • **default_color – Normalized RGB values of the crossbar devices if their values are not provided.

badcrossbar.plotting.crossbar.dimensions(shape, width_mm=210, color_bar_fraction=(0.5, 0.15), border_fraction=0.05)[source]#

Extracts dimensions of the surface.

Parameters
  • shape (tuple[int, int]) – Shape of the crossbar array (num_word_lines, num_bit_lines).

  • max_dim_mm – Width of the diagram in millimeters.

  • color_bar_fraction (tuple[float, float]) – The fraction of the surface that the color bar region will take on the right (vertically and horizontally.

  • border_fraction (float) – Fraction of the max_dim that will be blank on all sides of the surface.

Returns

Dimensions of the surface. diagram_pos: Coordinates of the top left point of the diagram. segment_length: The length of each segment. color_bar_pos: Coordinates of the top left point of the color bar. color_bar_dims: Width and height of the color bar.

Return type

surface_dims

badcrossbar.plotting.crossbar.draw_bit_line(ctx, colors, segment_length=100, scaling_factor=1)[source]#

Draws a bit line of a crossbar array.

Parameters
  • ctx (Context) – Context.

  • colors (list[tuple[float, float, float]]) – Normalized RGB values of the bit line segments.

  • segment_length (float) – The length of each segment.

  • scaling_factor (float) – Scaling factor for the width.

badcrossbar.plotting.crossbar.draw_device_row(ctx, colors, segment_length=100, scaling_factor=1, device='memristor')[source]#

Draws a row of crossbar devices.

Parameters
  • ctx (Context) – Context.

  • colors (list[tuple[float, float, float]]) – Normalized RGB values of the crossbar devices.

  • segment_length (float) – The length of each segment.

  • scaling_factor (float) – Scaling factor for the width.

  • device (str) – Device type to be drawn. One of {‘memristor’, ‘memristor_2’, ‘resistor_usa’, ‘resistor_europe’}.

badcrossbar.plotting.crossbar.draw_node_row(ctx, colors, segment_length=100, bit_line_nodes=True, scaling_factor=1, device='memristor')[source]#

Draws a row of nodes.

Parameters
  • ctx (Context) – Context.

  • colors (list[tuple[float, float, float]]) – Normalized RGB values of the nodes.

  • segment_length (float) – The length of each segment.

  • bit_line_nodes (bool) – If True, draws nodes on the bit lines.

  • scaling_factor (float) – Scaling factor for the diameter.

  • device (str) – Device type to be drawn (affects node diameter). One of {‘memristor’, ‘memristor_2’, ‘resistor_usa’, ‘resistor_europe’}.

badcrossbar.plotting.crossbar.draw_word_line(ctx, colors, segment_length=100, round_middle=False, scaling_factor=1)[source]#

Draws a word line of a crossbar array.

Parameters
  • ctx (Context) – Context.

  • colors (list[tuple[float, float, float]]) – Normalized RGB values of the word line segments.

  • segment_length (float) – The length of each segment.

  • round_middle (bool) – If True, draws a semicircle midway between each two neighbouring nodes, instead of a straight line.

  • scaling_factor (float) – Scaling factor for the width.

badcrossbar.plotting.crossbar.nodes(ctx, node_vals, diagram_pos, low, high, segment_length=120, crossbar_shape=(128, 64), bit_line=False, **kwargs)[source]#

Draws nodes.

Parameters
  • ctx (Context) – Context.

  • node_vals (ndarray[Any, dtype[TypeVar(ScalarType, bound= generic, covariant=True)]]) – Values associated with the nodes.

  • diagram_pos (tuple[float, float]) – Coordinates of the top left point of the diagram.

  • low (float) – Lower limit of the linear range.

  • high (float) – Upper limit of the linear range.

  • segment_length (float) – The length of each segment.

  • crossbar_shape (tuple[int, int]) – Shape of the crossbar array. Used when node_vals is None.

  • bit_line (bool) – If True, draws nodes on the bit lines.

  • **device_scaling_factor – Scaling factor for the width of the devices. Also scales the nodes.

  • **node_scaling_factor – Scaling factor for the diameter of the nodes which is combined with device_scaling_factor. For example, if one wanted to only scale the device width by a factor of 2, but keep the node diameter the same, arguments device_scaling_factor = 2 and node_scaling_factor = 1/2 would have to be passed.

badcrossbar.plotting.crossbar.word_lines(ctx, word_line_vals, diagram_pos, low, high, segment_length=120, crossbar_shape=(128, 64), **kwargs)[source]#

Draws word lines.

Parameters
  • ctx (Context) – Context.

  • word_line_vals (ndarray[Any, dtype[TypeVar(ScalarType, bound= generic, covariant=True)]]) – Values associated with the interconnect segments along the word lines.

  • diagram_pos (tuple[float, float]) – Coordinates of the top left point of the diagram.

  • low (float) – Lower limit of the linear range.

  • high (float) – Upper limit of the linear range.

  • segment_length (float) – The length of each segment.

  • crossbar_shape (tuple[int, int]) – Shape of the crossbar array. Used when word_line_vals is None.

  • **default_color – Normalized RGB values of the word lines if their values are not provided.

badcrossbar.plotting.devices module#

badcrossbar.plotting.devices.memristor(ctx, length=100, angle=0, width=1, rgb=(0, 0, 0))[source]#

Draws a memristor.

Parameters
  • ctx (Context) – Context.

  • length (float) – Total length of the memristor.

  • angle (float) – Angle in radians of the rotation of plane from the positive x axis towards positive y axis.

  • width (float) – Width of the path.

  • rgb (tuple[float, float, float]) – Normalized RGB value of the path.

badcrossbar.plotting.devices.memristor_2(ctx, length=100, angle=0, width=1, rgb=(0, 0, 0))[source]#

Draws a memristor.

Replicated from <https://commons.wikimedia.org/wiki/File:Memristor-Symbol.svg>

Parameters
  • ctx (Context) – Context.

  • length (float) – Total length of the memristor.

  • angle (float) – Angle in radians of the rotation of plane from the positive x axis towards positive y axis.

  • width (float) – Width of the path.

  • rgb (tuple[float, float, float]) – Normalized RGB value of the path.

badcrossbar.plotting.devices.resistor_europe(ctx, length=100, angle=0, width=1, rgb=(0, 0, 0))[source]#

Draws a resistor (European version).

Parameters
  • ctx (Context) – Context.

  • length (float) – Total length of the resistor.

  • angle (float) – Angle in radians of the rotation of plane from the positive x axis towards positive y axis.

  • width (float) – Width of the path.

  • rgb (tuple[float, float, float]) – Normalized RGB value of the path.

badcrossbar.plotting.devices.resistor_usa(ctx, length=100, angle=0, width=1, rgb=(0, 0, 0))[source]#

Draws a resistor (USA version).

Parameters
  • ctx (Context) – Context.

  • length (float) – Total length of the resistor.

  • angle (float) – Angle in radians of the rotation of plane from the positive x axis towards positive y axis.

  • width (float) – Width of the path.

  • rgb (tuple[float, float, float]) – Normalized RGB value of the path.

badcrossbar.plotting.shapes module#

badcrossbar.plotting.shapes.line(ctx, length, angle=0)[source]#

Draws a line at a specified angle.

Parameters
  • ctx (Context) – Context.

  • length (float) – Length of the line.

  • angle (float) – Angle in radians of the rotation of plane from the positive x axis towards positive y axis.

badcrossbar.plotting.shapes.rectangle(ctx, width, height, angle=0)[source]#

Draws a rectangle at a specified angle.

Parameters
  • ctx (Context) – Context.

  • width (float) – Width of the rectangle.

  • height (float) – Height of the rectangle.

  • angle (float) – Angle in radians of the rotation of plane from the positive x axis towards positive y axis.

badcrossbar.plotting.shapes.semicircle(ctx, diameter, angle=0)[source]#

Draws a semicircle at a specified angle.

Parameters
  • ctx (Context) – Context.

  • diameter (float) – Diameter of the semicircle.

  • angle (float) – Angle in radians of the rotation of plane from the positive x axis towards positive y axis.

badcrossbar.plotting.utils module#

badcrossbar.plotting.utils.arrays_range(*arrays, sf=2)[source]#

Finds the color bar range from arbitrary number of arrays.

Parameters
  • arrays (list[ndarray]) – Arrays.

  • sf (int) – Number of significant figures.

Return type

tuple[float, float]

Returns

Minimum and maximum values in the color bar.

badcrossbar.plotting.utils.complete_fill(ctx, rgb=(0, 0, 0))[source]#

Completes the current fill.

Parameters
  • ctx (Context) – Context.

  • rgb (tuple[float, float, float]) – Normalized RGB value of the path.

badcrossbar.plotting.utils.complete_path(ctx, rgb=(0, 0, 0), width=1)[source]#

Completes the current path.

Parameters
  • ctx (Context) – Context.

  • width (float) – Width of the path.

  • rgb (tuple[float, float, float]) – Normalized RGB value of the path.

badcrossbar.plotting.utils.get_filepath(filename, allow_overwrite)[source]#

Constructs filepath of the diagram.

Parameters
  • filename (str) – Filename (without the extension).

  • allow_overwrite (bool) – If True, can overwrite existing PDF files with the same name.

Returns

Filepath of the diagram.

badcrossbar.plotting.utils.rgb_interpolation(array, low=0, high=1, low_rgb=(0.8352941176470589, 0.3686274509803922, 0.0), zero_rgb=(0.9215686274509803, 0.9215686274509803, 0.9215686274509803), high_rgb=(0.0, 0.4470588235294118, 0.6980392156862745))[source]#

Linearly interpolates RGB colors for an array in a specified range.

Parameters
  • array (ndarray[Any, dtype[TypeVar(ScalarType, bound= generic, covariant=True)]]) – Array of values.

  • low (float) – Lower limit of the linear range.

  • high (float) – Upper limit of the linear range.

  • low_rgb (tuple[float, float, float]) – Colour (in RGB) associated with the lower limit.

  • zero_rgb (tuple[float, float, float]) – Colour (in RGB) associated with value of zero.

  • high_rgb (tuple[float, float, float]) – Colour (in RGB) associated with the upper limit.

Return type

ndarray[Any, dtype[tuple[float, float, float]]]

Returns

RGB values associated with each of the entries in the array.

badcrossbar.plotting.utils.rgb_single_color(shape, color=(0, 0, 0))[source]#

Return array with RGB values of a single color.

Parameters
  • shape (tuple[int, int]) – Shape of the array.

  • color (tuple[float, float, float]) – RGB (normalized to 1) of the color.

Returns

Array with RGB values.

badcrossbar.plotting.utils.set_defaults(kwargs, branches=True)[source]#

Sets default values for kwargs arguments in badcrossbar.plot functions.

Parameters
  • kwargs – Optional keyword arguments.

  • branches (bool) – Whether branches are being plotted. If False, it is assumed that nodes are being plotted.

Returns

Optional keyword arguments with the default values set.

Module contents#