Skip to content

TikzPicture

TikzPicture

Bases: TikzEnvironment

A class for managing a Tikzpicture environment and associated tex files with tikz code.

The TikzPicture class acts a canvas in which users can append drawings to. In the background, the TikzPicture manages the creation of the tikz code.

Parameters:

Name Type Description Default
center bool

True/False if one wants to center their Tikz code

False
options str

A list of options for the Tikz picture

''

add_command

add_command(tikz_statement: str) -> TikzCommand

Add a string of valid Tikz code into the Tikz environment.

add_option

add_option(option: str) -> None

Add an option to the set of options.

add_styles

add_styles(*styles: List[TikzStyle]) -> None

Add a TikzStyle object to the environment.

arc

arc(
    position: Union[Tuple[float, float], Point],
    start_angle: float,
    end_angle: float,
    radius: float = None,
    x_radius: float = None,
    y_radius: float = None,
    options: str = "",
    radians: bool = False,
    draw_from_start: bool = True,
    action: str = "draw",
) -> Arc

Draws an arc by creating an instance of the Arc class.

circle

circle(
    center: Union[Tuple[float, float], Point],
    radius: float,
    options: str = "",
    action: str = "draw",
) -> Circle

Draws a circle by creating an instance of the Circle class.

code

code() -> str

Returns a string contaning the generated Tikz code.

compile

compile(
    pdf_destination: Optional[str] = None,
    quiet: bool = True,
) -> Path

Compiles the Tikz code and returns a Path to the final PDF. If no file path is provided, a default value of "tex_file.pdf" will be used.

Parameters:

Name Type Description Default
pdf_destination str

The file path of the compiled pdf.

None
quiet bool

Parameter to silence latexmk.

True

connect_circle_edges

connect_circle_edges(circle_a, circle_b) -> Circle

Draws a line connecting the edges of two circles. This is useful for drawing graphs, diagrams, neural networks, etc.

draw

draw(*args: List[DrawingObject]) -> None

Add an arbitrary sequence of drawing objects.

ellipse

ellipse(
    center: Union[Tuple[float, float], Point],
    x_axis: float,
    y_axis: float,
    options: str = "",
    action: str = "draw",
) -> Ellipse

Draws an ellipse by creating an instance of the Ellipse class.

line

line(
    start: Union[Tuple[float, float], Point],
    end: Union[Tuple[float, float], Point],
    options: str = "",
    to_options: str = "",
    control_pts: list = [],
    action: str = "draw",
) -> Line

Draws a line by creating an instance of the Line class.

node

node(
    position: Union[Tuple[float, float], Point],
    options: str = "",
    text: str = "",
) -> Node

Draws a node by creating an instance of the Node class.

plot_coordinates

plot_coordinates(
    points: Union[List[tuple], List[Point]],
    options: str = "",
    plot_options: str = "",
    action: str = "draw",
) -> PlotCoordinates

Draws a plot coordinates statement by creating an instance of the PlotCoordinates class.

plot_relative_coordinates

plot_relative_coordinates(
    points: Union[List[tuple], List[Point]],
    options: str = "",
    plot_options: str = "",
    action: str = "draw",
) -> PlotCoordinates

Draws a (relative) plot coordinates statement by creating an instance of the PlotCoordinates class.

rectangle

rectangle(
    left_corner: Union[Tuple[float, float], Point],
    width: float = 0,
    height: float = 0,
    options: str = "",
    action: str = "draw",
) -> Rectangle

Draws a rectangle by creating an instance of the Rectangle class.

rectangle_from_east

rectangle_from_east(
    east_point: Union[Tuple[float, float], Point],
    width: float = 0,
    height: float = 0,
    options: str = "",
    action: str = "draw",
) -> Rectangle

Creates and draws a rectangle using the east point as a reference.

This method allows for the creation of a rectangle by specifying its east point, width, and height.

Parameters:

Name Type Description Default
east_point Union[Tuple[float, float], Point]

The east point of the rectangle. This can be a tuple of floats representing the coordinates, or a Point object.

required
width float

The width of the rectangle. Defaults to 0.

0
height float

The height of the rectangle. Defaults to 0.

0
options str

A string representing additional options for the rectangle's creation or manipulation. Defaults to an empty string.

''
action str

Specifies the TikZ action to be taken with the rectangle once created. Defaults to "draw".

'draw'

rectangle_from_north

rectangle_from_north(
    north_point: Union[Tuple[float, float], Point],
    width: float = 0,
    height: float = 0,
    options: str = "",
    action: str = "draw",
) -> Rectangle

Creates and draws a rectangle using the northernmost point as a reference.

This method allows for the creation of a rectangle by specifying its north point, width, and height.

Parameters:

Name Type Description Default
north_point Union[Tuple[float, float], Point]

The northernmost point of the rectangle. This can be a tuple of floats representing the coordinates, or a Point object.

required
width float

The width of the rectangle. Defaults to 0.

0
height float

The height of the rectangle. Defaults to 0.

0
options str

A string representing additional options for the rectangle's creation or manipulation. Defaults to an empty string.

''
action str

Specifies the TikZ action to be taken with the rectangle once created. Defaults to "draw".

'draw'

rectangle_from_south

rectangle_from_south(
    south_point: Union[Tuple[float, float], Point],
    width: float = 0,
    height: float = 0,
    options: str = "",
    action: str = "draw",
) -> Rectangle

Creates and draws a rectangle using the south point as a reference.

This method allows for the creation of a rectangle by specifying its south point, width, and height.

Parameters:

Name Type Description Default
south_point Union[Tuple[float, float], Point]

The south point of the rectangle. This can be a tuple of floats representing the coordinates, or a Point object.

required
width float

The width of the rectangle. Defaults to 0.

0
height float

The height of the rectangle. Defaults to 0.

0
options str

A string representing additional options for the rectangle's creation or manipulation. Defaults to an empty string.

''
action str

Specifies the TikZ action to be taken with the rectangle once created. Defaults to "draw".

'draw'

rectangle_from_west

rectangle_from_west(
    west_point: Union[Tuple[float, float], Point],
    width: float = 0,
    height: float = 0,
    options: str = "",
    action: str = "draw",
) -> Rectangle

Creates and draws a rectangle using the west point as a reference.

This method allows for the creation of a rectangle by specifying its west point, width, and height.

Parameters:

Name Type Description Default
west_point Union[Tuple[float, float], Point]

The west point of the rectangle. This can be a tuple of floats representing the coordinates, or a Point object.

required
width float

The width of the rectangle. Defaults to 0.

0
height float

The height of the rectangle. Defaults to 0.

0
options str

A string representing additional options for the rectangle's creation or manipulation. Defaults to an empty string.

''
action str

Specifies the TikZ action to be taken with the rectangle once created. Defaults to "draw".

'draw'

set_tdplotsetmaincoords

set_tdplotsetmaincoords(theta: float, phi: float) -> None

Specify the viewing angle for 3D.

theta: The angle (in degrees) through which the coordinate frame is rotated about the x axis. phi: The angle (in degrees) through which the coordinate frame is rotated about the z axis.

show

show(quiet: bool = False) -> None

Compiles the Tikz code and displays the pdf to the user. Set quiet=True to shut up latexmk. This should either open the PDF viewer on the user's computer with the graphic, or open the PDF in the user's browser.

tikzset

tikzset(
    style_name: str, style_rules: TikzStyle
) -> TikzStyle

Create and add a TikzStyle object with name "style_name" and tikzset syntax "style_rules"