Customisation#

squap.get_font(
font_name='Segoe UI',
font_size=None,
bold=False,
italic=False,
underline=False,
strikethrough=False,
overline=False,
kerning=False,
stretch=100,
letter_spacing=0.0,
word_spacing=0.0,
**kwargs,
)[source]#

Creates and returns a font object. Usually font names are allowed when a function requires a font as an argument, but this function creates more complex fonts.

Parameters:
  • font_name (str) – Name of the font. Can be any font on your computer. Defaults to "Segoe UI". Aliases: font, fn.

  • font_size (int) – Font size. Defaults to None. This usually means the font_size is 12 todo: check Aliases: size, fs.

  • bold (bool) – Whether to make the font bold. Defaults to False.

  • italic (bool) – Whether to make the font italic. Defaults to False.

  • underline (bool) – Whether to give the font underline. Defaults to False.

  • strikethrough (bool) – Whether to make the font strikethrough. Defaults to False. Alias: strikeout.

  • overline (bool) – Whether to give the font overline. Defaults to False.

  • kerning (bool) – Whether to draw the font with kerning. If kerning is enabled the text is drawn a bit more compactly. Defaults to False.

  • stretch (int) – Stretch factor as percentage. Eg. 100 is normal, 200 is twice as wide. Default is 100.

  • letter_spacing (float) – Extra spacing between letters in pixels. Defaults to 0.0. Alias: ls.

  • word_spacing (float) – Extra spacing between words in pixels. Defaults to 0.0. Alias: ws.

  • **kwargs – Aliases. See argument description for allowed aliases.

  • todo – setFixedPitch?, setLetterSpacing?, setWordSpacing?

Return type:

Font

squap.get_gradient(
cmap,
style='horizontal',
position=None,
extend='pad',
resolution=256,
)[source]#

Obtain a gradient. Gradients can sometimes be used instead of normal colors.

The gradient can be seen as a 2D image of a gradient placed depending on position. Only the parts are shown at each pixel that is drawn by eg. a plot line. When style of the gradient is set to "horizontal" or "vertical", or "radial" without providing position, the bounds of the gradient will be automatically determined when curve.set_data is called. Specify position for optimal performance.

Parameters:
  • cmap (str, dict, list or Colormap) –

    The colormap used as gradient. Can either be a string, a dictionary, a list of colors or an instance of matplotlib.colors.Colormap:

    • str: Any matplotlib colormap name. When a colormap exists in both matplotlib and cmasher, matplotlib takes priority. Prefix with "mpl_" or "cmasher_" to select explicitly.

    • dict: Maps positions (0–1) to colors. cmap[0] and cmap[1] are the start and end, with linear interpolation between any intermediate points.

    • list: Colors equally spaced between 0 and 1, with linear interpolation between them.

    • Colormap: Used directly.

  • style (str) –

    The style of the gradient.

    • "horizontal": Simple left-to-right gradient.

    • "vertical": Simple top-to-bottom gradient.

    • "linear": Gradient along a line from position[0] (tuple) to position[1] (tuple).

    • "radial": Radial gradient with centre position[0] (tuple) and radius position[1] (float).

    • "conical": Constant along the radius, varying with angle. position[0] (tuple) is the centre, position[1] (float) is the starting angle in degrees from the positive y-axis, defaulting to 0. For "linear", "radial", and "conical", position is determined automatically if not specified.

    Defaults to "horizontal".

  • position (tuple) – See style.

  • extend (str) – How the gradient behaves outside the range specified in position. Can be "pad", "repeat" or "reflect" (only applies when style is "linear" or "radial" and position is specified). Defaults to "pad".

  • resolution (int) – The resolution of the gradient, when it is a matplotlib (or cmasher) cmap. Does not do anything when the cmap is a dict or a list. Defaults to 256.

Returns:

A gradient object.

Return type:

QGradient

squap.get_cmap(data, source='matplotlib')[source]#

Tool for getting cmap from different sources. Returns a function that takes a value between 0 and 1 and returns a color based on the data argument.

If data is of type str, source decides from which library the cmap is obtained.

Parameters:
  • data (str, list of ColorType or dict of float to ColorType) –

    Has different behaviour depending on type:

    • str: Name of the cmap. source specifies from which library the cmap is obtained.

    • dict: data[x] is the cmap color at x, where the cmap is defined from x=0 to x=1. Every value not in data is interpolated. So e.g. data can be {0.0: "green", 0.25: "red", 1.0: "blue"}, which would mean a cmap going from green to red rather quickly, and then slowly turning blue.

    • list: similar to dict, but equally spaced colors in order.

  • source (str) – Library to obtain cmap from if it is a string. Currently, you can choose from matplotlib and colorcet. Feel free to request more.

Returns:

A function that interpolates to find the best approximation of the color at location i: a value between 0 and 1.

Return type:

callable

squap.cmap_to_colors(cmap, N_points)[source]#

Transform a cmap into N equally spaced colors.

Parameters:
  • ( (cmap) – term:callable): the used colormap (from squap.get_cmap())

  • N_points (int) – the number of points to retrieve

Returns:

A shape (N_points, 4) ndarray where result[i] is cmap(i/N_points-1).

Return type:

np.ndarray