symfem.plotting

Plotting.

Module Contents

Classes

Colors

Class storing colours used in diagrams.

PictureElement

An element in a picture.

Line

A line.

Bezier

A Bezier curve.

Arrow

An arrow.

NCircle

A circle containing a number.

Fill

A filled polygon.

Math

A mathematical symbol.

Picture

A picture.

Functions

tex_font_size(n)

Convert a font size to a TeX size command.

Attributes

PointOrFunction

SetOfPointsOrFunctions

colors

symfem.plotting.PointOrFunction
symfem.plotting.SetOfPointsOrFunctions
symfem.plotting.tex_font_size(n: int)

Convert a font size to a TeX size command.

Parameters:

n – Font size

Returns:

TeX size command

class symfem.plotting.Colors

Class storing colours used in diagrams.

BLACK = '#000000'
WHITE = '#FFFFFF'
ORANGE = '#FF8800'
BLUE = '#44AAFF'
GREEN = '#55FF00'
PURPLE = '#DD2299'
GRAY = '#AAAAAA'
entity(n: int) str

Get the color used for an entity of a given dimension.

Parameters:

n – The dimension of the entity

Returns:

The color used for entities of the given dimension

get_tikz_name(name: str) str

Get the name of the colour to be used in Tikz.

Parameters:

name – HTML name of the color

Returns:

The Tikz name of the color

get_tikz_definitions() str

Get the definitions of colours used in Tikz.

Returns:

Definitions of Tikz colors

symfem.plotting.colors
class symfem.plotting.PictureElement

Bases: abc.ABC

An element in a picture.

abstract property points: symfem.geometry.SetOfPoints

Get set of points used by this element.

Returns:

A set of points

abstract as_svg(map_pt: Callable[[symfem.geometry.PointType], Tuple[float, float]]) str

Return SVG format.

Parameters:

map_pt – A function that adjust the origin and scales the picture

Returns:

An SVG string

abstract as_tikz(map_pt: Callable[[symfem.geometry.PointType], Tuple[float, float]]) str

Return Tikz format.

Parameters:

map_pt – A function that adjust the origin and scales the picture

Returns:

A Tikz string

minx() sympy.core.expr.Expr

Get the minimum x-coordinate.

Returns:

The minimum x-coordinate

miny() sympy.core.expr.Expr

Get the minimum y-coordinate.

Returns:

The minimum y-coordinate

maxx() sympy.core.expr.Expr

Get the maximum x-coordinate.

Returns:

The maximum x-coordinate

maxy() sympy.core.expr.Expr

Get the maximum y-coordinate.

Returns:

The maximum y-coordinate

class symfem.plotting.Line(start: symfem.geometry.PointType, end: symfem.geometry.PointType, color: str, width: float)

Bases: PictureElement

A line.

property points: symfem.geometry.SetOfPoints

Get set of points used by this element.

Returns:

A set of points

as_svg(map_pt: Callable[[symfem.geometry.PointType], Tuple[float, float]]) str

Return SVG format.

Parameters:

map_pt – A function that adjust the origin and scales the picture

Returns:

An SVG string

as_tikz(map_pt: Callable[[symfem.geometry.PointType], Tuple[float, float]]) str

Return Tikz format.

Parameters:

map_pt – A function that adjust the origin and scales the picture

Returns:

A Tikz string

class symfem.plotting.Bezier(start: symfem.geometry.PointType, mid1: symfem.geometry.PointType, mid2: symfem.geometry.PointType, end: symfem.geometry.PointType, color: str, width: float)

Bases: PictureElement

A Bezier curve.

property points: symfem.geometry.SetOfPoints

Get set of points used by this element.

Returns:

A set of points

as_svg(map_pt: Callable[[symfem.geometry.PointType], Tuple[float, float]]) str

Return SVG format.

Parameters:

map_pt – A function that adjust the origin and scales the picture

Returns:

An SVG string

as_tikz(map_pt: Callable[[symfem.geometry.PointType], Tuple[float, float]]) str

Return Tikz format.

Parameters:

map_pt – A function that adjust the origin and scales the picture

Returns:

A Tikz string

class symfem.plotting.Arrow(start: symfem.geometry.PointType, end: symfem.geometry.PointType, color: str, width: float)

Bases: PictureElement

An arrow.

property points: symfem.geometry.SetOfPoints

Get set of points used by this element.

Returns:

A set of points

as_svg(map_pt: Callable[[symfem.geometry.PointType], Tuple[float, float]]) str

Return SVG format.

Parameters:

map_pt – A function that adjust the origin and scales the picture

Returns:

An SVG string

as_tikz(map_pt: Callable[[symfem.geometry.PointType], Tuple[float, float]]) str

Return Tikz format.

Parameters:

map_pt – A function that adjust the origin and scales the picture

Returns:

A Tikz string

class symfem.plotting.NCircle(centre: symfem.geometry.PointType, number: int, color: str, text_color: str, fill_color: str, radius: float, font_size: int | None, width: float, font: str)

Bases: PictureElement

A circle containing a number.

property points: symfem.geometry.SetOfPoints

Get set of points used by this element.

Returns:

A set of points

as_svg(map_pt: Callable[[symfem.geometry.PointType], Tuple[float, float]]) str

Return SVG format.

Parameters:

map_pt – A function that adjust the origin and scales the picture

Returns:

An SVG string

as_tikz(map_pt: Callable[[symfem.geometry.PointType], Tuple[float, float]]) str

Return Tikz format.

Parameters:

map_pt – A function that adjust the origin and scales the picture

Returns:

A Tikz string

class symfem.plotting.Fill(vertices: symfem.geometry.SetOfPoints, color: str, opacity: float)

Bases: PictureElement

A filled polygon.

property points: symfem.geometry.SetOfPoints

Get set of points used by this element.

Returns:

A set of points

as_svg(map_pt: Callable[[symfem.geometry.PointType], Tuple[float, float]]) str

Return SVG format.

Parameters:

map_pt – A function that adjust the origin and scales the picture

Returns:

An SVG string

as_tikz(map_pt: Callable[[symfem.geometry.PointType], Tuple[float, float]]) str

Return Tikz format.

Parameters:

map_pt – A function that adjust the origin and scales the picture

Returns:

A Tikz string

class symfem.plotting.Math(point: symfem.geometry.PointType, math: str, color: str, font_size: int, anchor: str)

Bases: PictureElement

A mathematical symbol.

property points: symfem.geometry.SetOfPoints

Get set of points used by this element.

Returns:

A set of points

as_svg(map_pt: Callable[[symfem.geometry.PointType], Tuple[float, float]]) str

Return SVG format.

Parameters:

map_pt – A function that adjust the origin and scales the picture

Returns:

An SVG string

as_tikz(map_pt: Callable[[symfem.geometry.PointType], Tuple[float, float]]) str

Return Tikz format.

Parameters:

map_pt – A function that adjust the origin and scales the picture

Returns:

A Tikz string

class symfem.plotting.Picture(padding: sympy.core.expr.Expr = sympy.Integer(25), scale: int | None = None, width: int | None = None, height: int | None = None, axes_3d: symfem.geometry.SetOfPointsInput | None = None, dof_arrow_size: int | sympy.core.expr.Expr = 1, title: str | None = None, desc: str | None = None, svg_metadata: str | None = None, tex_comment: str | None = None)

A picture.

axes_3d: symfem.geometry.SetOfPoints
z(p_in: PointOrFunction) sympy.core.expr.Expr

Get the into/out-of-the-page component of a point.

Parameters:

p_in – The point

Returns:

The into/out-of-the-page component of the point

to_2d(p: symfem.geometry.PointType) symfem.geometry.PointType

Map a point to 2D.

Parameters:

p – The point

Returns:

The projection of the point into 2 dimensions

parse_point(p: PointOrFunction) symfem.geometry.PointType

Parse an input point.

Parameters:

p – a point or a function

Returns:

The point as a tuple of Sympy expressions

add_line(start: PointOrFunction, end: PointOrFunction, color: str = colors.BLACK, width: float = 4.0)

Add a line to the picture.

Parameters:
  • start – The start point of the line

  • end – The end point of the line

  • color – The color of the line

  • width – The width of the line

add_bezier(start: PointOrFunction, mid1: PointOrFunction, mid2: PointOrFunction, end: PointOrFunction, color: str = colors.BLACK, width: float = 4.0)

Add a Bezier curve to the picture.

Parameters:
  • start – The start point of the Bezier curve

  • mid1 – The first control point

  • mid2 – The second control point

  • end – The end point of the Bezier curve

  • color – The color of the Bezier curve

  • width – The width of the Bezier curve

add_arrow(start: PointOrFunction, end: PointOrFunction, color: str = colors.BLACK, width: float = 4.0)

Add an arrow to the picture.

Parameters:
  • start – The start point of the arrow

  • end – The end point of the arrow

  • color – The color of the arrow

  • width – The width of the arrow

add_dof_marker(point: PointOrFunction, number: int, color: str, bold: bool = True)

Add a DOF marker.

Parameters:
  • point – The point

  • number – The number to put in the marker

  • color – The color of the marker

  • bold – Should the marker be bold?

add_dof_arrow(point: PointOrFunction, direction: PointOrFunction, number: int, color: str = colors.PURPLE, shifted: bool = False, bold: bool = True)

Add a DOF arrow.

Parameters:
  • point – The point

  • direction – The direction of the arrow

  • number – The number to put in the marker

  • color – The color of the marker

  • shifted – Should the marker be shifted?

  • bold – Should the marker be bold?

add_ncircle(centre: PointOrFunction, number: int, color: str = 'red', text_color: str = colors.BLACK, fill_color: str = colors.WHITE, radius: float = 20.0, font_size: int | None = None, width: float = 4.0, font: str = "'Varela Round',sans-serif")

Add a numbered circle to the picture.

Parameters:
  • centre – The centre points

  • number – The number in the circle

  • color – The color of the outline

  • text_color – The color of the test

  • fill_color – The colour of the background fill

  • radius – The radius of the circle

  • font_size – The font size

  • width – The width of the line

  • font – The font

add_math(point: symfem.geometry.PointTypeInput, math: str, color: str = colors.BLACK, font_size: int = 35, anchor='center')

Create mathematical symbol.

Parameters:
  • point – The point to put the math

  • math – The math

  • color – The color of the math

  • font_size – The font size

  • anchor – The point on the equation to anchor to

add_fill(vertices: SetOfPointsOrFunctions, color: str = 'red', opacity: float = 1.0)

Add a filled polygon to the picture.

Parameters:
  • vertices – The vertices of the polygon

  • color – The color of the polygon

  • opacity – The opacity of the polygon

compute_scale(unit: str = 'px', reverse_y: bool = True) Tuple[sympy.core.expr.Expr, sympy.core.expr.Expr, sympy.core.expr.Expr, Callable[[symfem.geometry.PointType], Tuple[float, float]]]

Compute the scale and size of the picture.

Parameters:
  • unit – The unit to use. Accepted values: px, cm, mm

  • reverse_y – Should the y-axis be reversed?

Returns:

The scale, height, and width of the image, and a mapping function

as_svg(filename: str | None = None) str

Convert to an SVG.

Parameters:

filename – The file name

Returns:

The image as an SVG string

as_png(filename: str, png_scale: float | None = None, png_width: int | None = None, png_height: int | None = None)

Convert to a PNG.

Parameters:
  • filename – The file name

  • png_scale – The scale of the png

  • png_width – The width of the png

  • png_height – The height of the png

as_tikz(filename: str | None = None) str

Convert to tikz.

Parameters:

filename – The file name

Returns:

The image as a Tikz string

save(filename: str | List[str], plot_options: Dict[str, Any] = {})

Save the picture as a file.

Parameters:
  • filename – The file name

  • plot_options – The plotting options