2. Main Module : curlyBrace

Module Name : curlyBrace

Author : 高斯羽 博士 (Dr. GAO, Siyu)

Version : 1.0.2

Last Modified : 2019-04-22

This module is basically an Python implementation of the function written Pål Næverlid Sævik for MATLAB (link in Reference).

The function “curlyBrace” allows you to plot an optionally annotated curly bracket between two points when using matplotlib.

The usual settings for line and fonts in matplotlib also apply.

The function takes the axes scales into account automatically. But when the axes aspect is set to “equal”, the auto switch should be turned off.

2.1. Change Log

  • Notable changes:
    • Version : 1.0.2
      • Added considerations for different scaled axes and log scale
    • Version : 1.0.1
      • First version.

2.3. List of functions

curlyBrace.curlyBrace(fig, ax, p1, p2, k_r=0.1, bool_auto=True, str_text='', int_line_num=2, fontdict={}, **kwargs)[source]

Plot an optionally annotated curly bracket on the given axes of the given figure.

Note that the brackets are anti-clockwise by default. To reverse the text position, swap “p1” and “p2”.

Note that, when the axes aspect is not set to “equal”, the axes coordinates need to be transformed to screen coordinates, otherwise the arcs may not be seeable.

Parameters:
  • fig (matplotlib figure object) – The of the target axes.
  • ax (matplotlib axes object) – The target axes.
  • p1 (two element numeric list) – The coordinates of the starting point.
  • p2 (two element numeric list) – The coordinates of the end point.
  • k_r (float) –

    This is the gain controlling how “curvy” and “pointy” (height) the bracket is.

    Note that, if this gain is too big, the bracket would be very strange.

  • bool_auto (boolean) –

    This is a switch controlling wether to use the auto calculation of axes scales.

    When the two axes do not have the same aspects, i.e., not “equal” scales, this should be turned on, i.e., True.

    When “equal” aspect is used, this should be turned off, i.e., False.

    If you do not set this to False when setting the axes aspect to “equal”, the bracket will be in funny shape.

    Default = True

  • str_text (string) –

    The annotation text of the bracket. It would displayed at the mid point of bracket with the same rotation as the bracket.

    By default, it follows the anti-clockwise convention. To flip it, swap the end point and the starting point.

    The appearance of this string can be set by using “fontdict”, which follows the same syntax as the normal matplotlib syntax for font dictionary.

    Default = empty string (no annotation)

  • int_line_num (int) –

    This argument determines how many lines the string annotation is from the summit of the bracket.

    The distance would be affected by the font size, since it basically just a number of lines appended to the given string.

    Default = 2

  • fontdict (dictionary) –

    This is font dictionary setting the string annotation. It is the same as normal matplotlib font dictionary.

    Default = empty dict

  • **kwargs (matplotlib line setting arguments) – This allows the user to set the line arguments using named arguments that are the same as in matplotlib.
Returns:

  • theta (float) – The bracket angle in radians.
  • summit (list) – The positions of the bracket summit.
  • arc1 (list of lists) – arc1 positions.
  • arc2 (list of lists) – arc2 positions.
  • arc3 (list of lists) – arc3 positions.
  • arc4 (list of lists) – arc4 positions.
  • Reference
  • ———-
  • https (//uk.mathworks.com/matlabcentral/fileexchange/38716-curly-brace-annotation)

curlyBrace.getAxSize(fig, ax)[source]

Get the axes size in pixels.

Parameters:
  • fig (matplotlib figure object) – The of the target axes.
  • ax (matplotlib axes object) – The target axes.
Returns:

  • ax_width (float) – The axes width in pixels.
  • ax_height (float) – The axes height in pixels.
  • Reference
  • ———–
  • https (//stackoverflow.com/questions/19306510/determine-matplotlib-axis-size-in-pixels)