pyhelpers.geom.sketch_square(ctr_x, ctr_y, side_length, rotation_theta=0, annotation=False, annot_font_size=12, fig_size=(6.4, 4.8), ret_vertices=False, **kwargs)

Sketch a square given its centre point, four vertices and rotation angle (in degree).

  • ctr_x (int or float) – x coordinate of a square centre

  • ctr_y (int or float) – y coordinate of a square centre

  • side_length (int or float) – side length of a square

  • rotation_theta (int or float) – rotate (anticlockwise) the square by rotation_theta (in degree), defaults to 0

  • annotation (bool) – whether to annotate vertices of the square, defaults to True

  • annot_font_size (int) – font size annotation texts, defaults to 12

  • fig_size (tuple or list) – figure size, defaults to (6.4, 4.8)

  • ret_vertices (bool) – whether to return the vertices of the square, defaults to False

  • kwargs – [optional] parameters of matplotlib.axes.Axes.annotate


vertices of the square as an array([ll, ul, ur, lr])

Return type



>>> from pyhelpers.geom import sketch_square
>>> from pyhelpers.settings import mpl_preferences
>>> import matplotlib.pyplot as plt

>>> mpl_preferences()

>>> c1, c2 = 1, 1
>>> side_len = 2

>>> sketch_square(c1, c2, side_len, rotation_theta=0, annotation=True, fig_size=(5, 5))

The above exmaple is illustrated in Fig. 12:


Fig. 12 An example of a sketch of a square, created by the function sketch_square().

>>> sketch_square(c1, c2, side_len, rotation_theta=75, annotation=True, fig_size=(5, 5))

This second example is illustrated in Fig. 13:


Fig. 13 An example of a sketch of a square rotated 75 degrees anticlockwise about the centre.