Select Version: Latest Release (v0.2.1) v0.1.9
This library is designed to provide a set of functions for drawing various types of plots, arrows, segments, and shapes using Matplotlib. These functions allow for customized plotting and annotation of graphical elements.
General
blank_canvas
[Source]
blank_canvas ( width = 800 , height = 600 , color = "white" )
Description:
Creates a blank image with specified width and height, displaying a grid.
Arguments:
Argument Type Description widthint (optional)The width of the image in pixels. (Default is 800) heightint (optional)The height of the image in pixels. (Default is 600) colorstr (optional)The background color of the image. (Default is 'white')
Returns:
Return Type Description plt.AxesThe Axes object of the created blank image.
Example:
import matplotlib . pyplot as plt import mecsimcalc as msc import mecsimcalc . plot_draw as plot_draw def main ( inputs ) : ax = plot_draw . blank_canvas ( ) plot = msc . print_plot ( plt ) return { 'plot' : plot }
lines and arrows
draw_line
[Source]
draw_line ( start , end , color = "black" , line_width = None , ax = None )
Description:
Draws a segment between two points with a specified line width and color.
Arguments:
Argument Type Description starttuple The coordinates of the starting point (x, y). endtuple The coordinates of the final point (x, y). colorstr (optional)The color of the segment. (Default is 'black') line_widthfloat (optional)The width of the segment. (Default is None) axplt.Axes (optional)The Axes object to draw the segment on. (Default is None)
Example:
import matplotlib . pyplot as plt import mecsimcalc as msc import mecsimcalc . plot_draw as plot_draw def main ( inputs ) : plot_draw . draw_line ( ( 0 , 0 ) , ( 1 , 1 ) , color = 'blue' , line_width = 0.005 ) plot = msc . print_plot ( plt ) return { 'plot' : plot }
draw_arrow
[Source]
draw_arrow ( start , end , thickness = 5 , color = "black" , text = "" , text_offset = 0.1 , head_width = 0.08 , head_length = 0.08 , fontsize = 12 , ax = None )
Description:
Draws an arrow between two points on a plot.
Arguments:
Argument Type Description startTuple[float, float] The starting point of the arrow (x, y). endTuple[float, float] The ending point of the arrow (x, y). thicknessfloat (optional)The thickness of the arrow line. (Default is 5) colorstr (optional)The color of the arrow. (Default is 'black') textstr (optional)Text to display near the arrow. (Default is None) text_offsetfloat (optional)Distance from the arrow end point where the text will be placed. (Default is 0.5) head_widthfloat (optional)Width of the arrow head. (Default is 0.08) head_lengthfloat (optional)Length of the arrow head. (Default is 0.08) fontsizefloat (optional)Font size of the text. (Default is 12) axplt.Axes (optional)The Axes object to draw the arrow on. (Default is None)
Example:
import matplotlib . pyplot as plt import mecsimcalc as msc import mecsimcalc . plot_draw as plot_draw def main ( inputs ) : plot_draw . draw_arrow ( ( 0 , 0 ) , ( 1 , 1 ) , color = 'red' , text = 'Arrow' ) plt . xlim ( - 1 , 2 ) plt . ylim ( - 1 , 2 ) plot = msc . print_plot ( plt ) return { 'plot' : plot }
Output:
draw_double_arrowhead
[Source]
draw_double_arrowhead ( start , end , color = "black" , line_thickness = 1 , ax = None )
Description:
Draws a double arrowhead between two points.
Arguments:
Argument Type Description starttuple Coordinates of the start point (x, y). endtuple Coordinates of the end point (x, y). colorstr (optional)Color of the arrow and line. (Default is 'black') line_thicknessfloat (optional)Thickness of the line. (Default is 1) axplt.Axes (optional)The Axes object to draw the arrow on.
Example:
import matplotlib . pyplot as plt import mecsimcalc as msc import mecsimcalc . plot_draw as plot_draw def main ( inputs ) : plot_draw . draw_double_arrowhead ( start = ( 0 , 0 ) , end = ( 1 , 1 ) ) plot = msc . print_plot ( plt ) return { 'plot' : plot }
vertical_arrow_rain
[Source]
vertical_arrow_rain ( quantity , start , end , y_origin = 0 , arrow_color = "blue" , head_width = 0.05 , head_length = 0.1 , ax = None )
Description:
Draws a specific quantity of arrows from equidistant points on a segment that extends from start to end, with all arrows pointing to y_origin.
Arguments:
Argument Type Description quantityint Number of arrows to draw. starttuple Tuple (x, y) representing the starting point of the segment. endtuple Tuple (x, y) representing the final point of the segment. y_originfloat y-coordinate to which all arrows should point. (Default is 0) arrow_colorstr Color of the arrows. (Default is 'blue') head_widthfloat Width of the arrow head. (Default is 0.05) head_lengthfloat Length of the arrow head. (Default is 0.1) axplt.Axes The Axes object to draw the arrows on.
Example:
import matplotlib . pyplot as plt import mecsimcalc as msc import mecsimcalc . plot_draw as plot_draw def main ( inputs ) : plot_draw . vertical_arrow_rain ( quantity = 5 , start = ( 0 , 1 ) , end = ( 1 , 1 ) , y_origin = 0 ) plot = msc . print_plot ( plt ) return { 'plot' : plot }
horizontal_arrow_rain
[Source]
horizontal_arrow_rain ( quantity , start , end , x_origin = 0 , arrow_color = "blue" , head_width = 0.05 , head_length = 0.1 , ax = None )
Description:
Draws a specific quantity of arrows from a vertical line at x_origin to equidistant points on a segment that extends from start to end.
Arguments:
Argument Type Description quantityint Number of arrows to draw. starttuple Tuple (x, y) representing the starting point of the segment. endtuple Tuple (x, y) representing the final point of the segment. x_originfloat x-coordinate from which all arrows originate. (Default is 0) arrow_colorstr Color of the arrows. (Default is 'blue') head_widthfloat Width of the arrow head. (Default is 0.05) head_lengthfloat Length of the arrow head. (Default is 0.1) axplt.Axes The Axes object to draw the arrows on. (Default is None)
Example:
import matplotlib . pyplot as plt import mecsimcalc as msc import mecsimcalc . plot_draw as plot_draw def main ( inputs ) : plot_draw . horizontal_arrow_rain ( quantity = 5 , start = ( 1 , 1 ) , end = ( 1 , 0 ) , x_origin = 0 ) plot = msc . print_plot ( plt ) return { 'plot' : plot }
Shapes
draw_circle
[Source]
draw_circle ( center = ( 0 , 0 ) , radius = 10 , color = "black" , ax = None )
Description:
Draws a custom circle on a given axis.
Arguments:
Argument Type Description centertuple (optional)The center point of the circle (x, y). (Default is (0, 0)) radiusfloat (optional)The size of the circle. (Default is 100) colorstr (optional)The color of the circle. (Default is 'black') axplt.Axes (optional)The Axes object to draw the circle on. (Default is None)
Example:
import matplotlib . pyplot as plt import mecsimcalc as msc import mecsimcalc . plot_draw as plot_draw def main ( inputs ) : plot_draw . draw_circle ( ( 100 , 100 ) , radius = 20 , color = 'red' ) plot = msc . print_plot ( plt ) return { 'plot' : plot }
draw_arc
[Source]
draw_arc ( radius , start_angle , end_angle , center = ( 0 , 0 ) , degrees = False , color = "red" , text = "" , text_offset = 0.1 , fontsize = 12 , ax = None , )
Description:
Draws an arc of a circumference with a given radius between two angles.
Arguments:
Argument Type Description radiusfloat The radius of the circumference. start_anglefloat The starting angle of the arc in radians. end_anglefloat The ending angle of the arc in radians. centertuple (optional)The center of the circumference. (Default is (0, 0)) degreesbool (optional)Whether the angles are. (Default is False) colorstr (optional)The color of the arc. (Default is 'red') textstr (optional)Text to display near the arc. (Default is None) text_offsetfloat (optional)Distance from the arc end point where the text will be placed. (Default is 0.1) fontsizefloat (optional)Font size of the text. (Default is 12) axplt.Axes (optional)The Axes object to draw the arc on. (Default is None)
Example:
import matplotlib . pyplot as plt import mecsimcalc as msc import mecsimcalc . plot_draw as plot_draw def main ( inputs ) : plot_draw . draw_arc ( 5 , 0 , 90 , degrees = True ) plot = msc . print_plot ( plt ) return { 'plot' : plot } .
draw_rounded_rectangle
[Source]
draw_rounded_rectangle ( width , height , center = ( 0 , 0 ) , corner_radius = 0.5 , color = "black" , ax = None )
Description:
Draws a rounded rectangle with specified properties.
Arguments:
Argument Type Description widthfloat The width of the rounded rectangle. heightfloat The height of the rounded rectangle. centertuple (optional)The middle point of the top side of the rounded rectangle (x, y). (Default is (0, 0)) corner_radiusfloat (optional)The radius of the corners. (Default is 0.5) colorstr (optional)The color of the rectangle. (Default is 'black') axplt.Axes (optional)The Axes object to draw the rectangle on. (Default is None)
Example:
import matplotlib . pyplot as plt import mecsimcalc as msc import mecsimcalc . plot_draw as plot_draw def main ( inputs ) : plot_draw . draw_rounded_rectangle ( 4 , 2 , center = ( 0 , 0 ) , corner_radius = 0.5 , color = 'blue' ) plot = msc . print_plot ( plt ) return { 'plot' : plot }
Axes
draw_two_axes
[Source]
draw_two_axes ( arrow_length , line_thickness = 1.5 , text_offset = 0.1 , negative_y = False , negative_x = False , ax = None )
Description:
Draws two axes representing the x and y directions.
Arguments:
Argument Type Description arrow_lengthfloat Length of the arrows representing the axes. line_thicknessfloat Thickness of the arrows representing the axes. (Default is 1.5) text_offsetfloat Offset for the axis labels. (Default is 0.1) negative_ybool Draws negative y-axis if True. (Default is False) negative_xbool Draws negative x-axis if True. (Default is False) axplt.Axes The Axes object to draw the axes on.
Returns:
Return Type Description plt.AxesAxes object.
Example:
import matplotlib . pyplot as plt import mecsimcalc as msc import mecsimcalc . plot_draw as plot_draw def main ( inputs ) : ax = plot_draw . draw_two_axes ( arrow_length = 1.0 , negative_y = True , negative_x = True ) plot = msc . print_plot ( plt ) return { 'plot' : plot }
draw_two_inclined_axes
[Source]
draw_two_inclined_axes ( arrow_length , arrow_thickness = 2 , text_offset = 0.1 , negative_y = False , negative_x = False , ax = None )
Description:
Draws two inclined axes (x and y) with optional negative directions.
Arguments:
Argument Type Description arrow_lengthfloat The length of the arrows representing the axes. arrow_thicknessfloat (optional)The thickness of the arrows. (Default is 2) text_offsetfloat (optional)The distance between the end of the arrow and the label text. (Default is 0.1) negative_ybool (optional)Draws negative y-axis if True. (Default is False) negative_xbool (optional)Draws negative x-axis if True. (Default is False) axplt.Axes (optional)The Axes object to draw the axes on. (Default is None)
Returns:
Return Type Description plt.AxesThe Axes object with the drawn axes.
Example:
import matplotlib . pyplot as plt import mecsimcalc as msc import mecsimcalc . plot_draw as plot_draw def main ( inputs ) : ax = plot_draw . draw_two_inclined_axes ( arrow_length = 1 , negative_y = True , negative_x = True ) plot = msc . print_plot ( plt ) return { 'plot' : plot }
draw_three_axes
[Source]
draw_three_axes ( arrow_length , arrow_thickness = 2 , text_offset = 0.1 , negative_y = False , negative_x = False , ax = None )
Description:
Draws a set of three axes (x, y, z) with optional negative directions for x and y.
Arguments:
Argument Type Description arrow_lengthfloat The length of the arrows representing the axes. arrow_thicknessfloat (optional)The thickness of the arrows. (Default is 2) text_offsetfloat (optional)The distance between the end of the arrow and the label text. (Default is 0.1) negative_ybool (optional)Draws negative y-axis if True. (Default is False) negative_xbool (optional)draws negative x-axis if True. (Default is False) axplt.Axes (optional)The Axes object to draw the axes on. (Default is None)
Example:
import matplotlib . pyplot as plt import mecsimcalc as msc import mecimcalc . plot_draw as plot_draw def main ( inputs ) : plot_draw . draw_three_axes ( arrow_length = 1 , negative_y = True , negative_x = True ) plot = msc . print_plot ( plt ) return { 'plot' : plot }
draw_three_axes_rotated
[Source]
draw_three_axes_rotated ( arrow_length , line_thickness = 1.5 , text_offset = 0.2 , negative_y = False , negative_x = False , ax = None )
Description:
Draws three rotated axes in a 3D coordinate system.
Arguments:
Argument Type Description arrow_lengthfloat The length of the arrow. line_thicknessfloat The thickness of the line. text_offsetfloat The offset of the text from the arrow. negative_ybool Whether to include negative y-axis (Default is False). negative_xbool Whether to include negative x-axis (Default is False).
Returns:
Return Type Description plt.AxesThe matplotlib Axes object containing the plot.
Example:
import matplotlib . pyplot as plt import mecsimcalc as msc import mecsimcalc . plot_draw as plot_draw def main ( inputs ) : ax = plot_draw . draw_three_axes_rotated ( arrow_length = 1.0 , negative_y = True , negative_x = True ) plot = msc . print_plot ( plt ) return { 'plot' : plot }
Calculations
calculate_midpoint
[Source]
calculate_midpoint ( coord1 , coord2 )
Description:
Calculates the midpoint between two coordinates.
Arguments:
Argument Type Description coord1Tuple[float, float] The first coordinate (x, y). coord2Tuple[float, float] The second coordinate (x, y).
Returns:
Return Type Description (float, float)A tuple containing the coordinates of the midpoint.
Example:
import mecsimcalc . plot_draw as plot_draw def main ( inputs ) : midpoint = plot_draw . calculate_midpoint ( ( 0 , 0 ) , ( 2 , 2 ) ) return { "midpoint" : midpoint }
calculate_intersection_point
[Source]
calculate_intersection_point ( point1 , angle1 , point2 , angle2 , degrees = False )
Description:
Calculates the intersection point of two lines defined by points and angles.
Arguments:
Argument Type Description point1tuple The coordinates of the first point (x, y) through which the first line passes. angle1float The angle of the first line. point2tuple The coordinates of the second point (x, y) through which the second line passes. angle2float The angle of the second line. degreesbool (optional)Whether the angles are. (Default is False)
Returns:
Return Type Description (float, float)The coordinates of the intersection point (x, y).
Example:
import mecsimcalc . plot_draw as plot_draw def main ( inputs ) : intersection = plot_draw . calculate_intersection_point ( ( 0 , 0 ) , 45 , ( 1 , 1 ) , 135 , degrees = True ) return { "intersection" ersection }
calculate_arrow_endpoint
[Source]
calculate_arrow_endpoint ( start , angle , length , degrees = False )
Description:
Calculates the end point of an arrow in pixel coordinates.
Arguments:
Argument Type Description starttuple The starting point of the arrow (x, y) in pixel coordinates. anglefloat The angle of the arrow. lengthfloat The length of the arrow. degreesbool Whether the angle is. (Default is False)
Returns:
Return Type Description (float, float)The end point of the arrow (x, y) in pixel coordinates.
Example:
import mecsimcalc . plot_draw as plot_draw def main ( inputs ) : endpoint = plot_draw . calculate_arrow_endpoint ( ( 100 , 200 ) , 45 , 50 , degrees = True ) return { "endpoint" : endpoint }
calculate_angle
[Source]
calculate_angle ( start : tuple , end : tuple , degrees : bool = False )
Description:
Calculates the angle (in degrees) between two points.
Arguments:
Argument Type Description starttuple Tuple (x, y) representing the starting point. endtuple Tuple (x, y) representing the final point. degreesbool Whether to return the angle in degrees. (Default is False)
Returns:
Return Type Description floatThe angle between the two points.
Example:
import mecsimcalc . plot_draw as plot_draw def main ( inputs ) : angle = plot_draw . calculate_angle ( start = ( 0 , 0 ) , end = ( 1 , 1 ) , degrees = True ) return { "angle" : angle }
get_arc_points
[Source]
get_arc_points ( start_angle , end_angle , radius , center : Union [ tuple , list ] )
Description:
Calculates points along a circular arc defined by a start angle and an end angle.
Arguments:
Argument Type Description start_anglefloat The starting angle of the arc. end_anglefloat The ending angle of the arc. radiusfloat The radius of the arc. centerTuple[float, float] The coordinates of the center of the arc [cx, cy].
Returns:
Return Type Description Tuple[np.ndarray, np.ndarray]The x and y coordinates of the arc points.
Example:
import matplotlib . pyplot as plt import numpy as np import mecsimcalc as msc import mecsimcalc . plot_draw as plot_draw def main ( inputs ) : arc_points_x1 , arc_points_y1 = plot_draw . get_arc_points ( 90 , 240 , 0.25 , ( 0 , - 0.25 ) , degrees = True ) plt . plot ( arc_points_x1 , arc_points_y1 , 'k' ) plot = msc . print_plot ( plt ) return { 'plot' : plot }