Skip to content

general_steel_plotter

structural_sections.steel.profile_definitions.plotters.general_steel_plotter

Defines a general steel plotter for profiles and its characteristics.

structural_sections.steel.profile_definitions.plotters.general_steel_plotter.plot_shapes

plot_shapes(
    profile: Profile,
    figsize: tuple[float, float] = (15.0, 8.0),
    title: str = "",
    font_size_title: float = 18.0,
    font_size_legend: float = 10.0,
    show: bool = False,
    include_moment_of_inertia: bool = False,
) -> Figure

Plot the given shapes.

Parameters:

  • profile (Profile) –

    The profile to plot.

  • figsize (tuple[float, float], default: (15.0, 8.0) ) –

    The size of the figure in inches. Default is (15.0, 8.0).

  • title (str, default: '' ) –

    The title of the plot. Default is "".

  • font_size_title (float, default: 18.0 ) –

    The font size of the title. Default is 18.0.

  • font_size_legend (float, default: 10.0 ) –

    The font size of the legend. Default is 10.0.

  • show (bool, default: False ) –

    Whether to show the plot. Default is False.

  • include_moment_of_inertia (bool, default: False ) –

    Whether to include the moment of inertia in the legend. Default is False.

Source code in blueprints/structural_sections/steel/profile_definitions/plotters/general_steel_plotter.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
def plot_shapes(
    profile: Profile,
    figsize: tuple[float, float] = (15.0, 8.0),
    title: str = "",
    font_size_title: float = 18.0,
    font_size_legend: float = 10.0,
    show: bool = False,
    include_moment_of_inertia: bool = False,
) -> plt.Figure:
    """
    Plot the given shapes.

    Parameters
    ----------
    profile : Profile
        The profile to plot.
    figsize : tuple[float, float], optional
        The size of the figure in inches. Default is (15.0, 8.0).
    title : str, optional
        The title of the plot. Default is "".
    font_size_title : float, optional
        The font size of the title. Default is 18.0.
    font_size_legend : float, optional
        The font size of the legend. Default is 10.0.
    show : bool, optional
        Whether to show the plot. Default is False.
    include_moment_of_inertia : bool, optional
        Whether to include the moment of inertia in the legend. Default is False.
    """
    fig, ax = plt.subplots(figsize=figsize)

    # Plot the exterior polygon
    coords = profile.polygon.exterior.coords
    patch = MplPolygon(xy=coords, lw=1, fill=True, facecolor=STEEL_COLOR, edgecolor=STEEL_COLOR)
    ax.add_patch(patch)

    # Plot the interior polygons (holes) if any
    for interior in profile.polygon.interiors:
        coords = interior.coords
        patch = MplPolygon(xy=coords, lw=0, fill=True, facecolor="white")
        ax.add_patch(patch)

    # Add dimension lines and centroid
    _add_dimension_lines(ax=ax, profile=profile, centroid=profile.centroid)
    ax.plot(profile.centroid.x, profile.centroid.y, "o", color="black")

    # Add legend text
    legend_text = f"""
    {profile.name}\n
    Area: {profile.area:.1f} mm²"""

    if include_moment_of_inertia:
        profile_section_properties = profile.section_properties(plastic=False, warping=False)
        legend_text += f"""
    Moment of inertia about x: {profile_section_properties.ixx_c:.0f} mm⁴
    Moment of inertia about y: {profile_section_properties.iyy_c:.0f} mm⁴
    """

    # Get the boundaries of the plot
    _, min_y, max_x, _ = profile.polygon.bounds
    offset = profile.profile_width / 20

    # Add the legend text to the plot
    ax.annotate(
        xy=(max_x + offset, min_y),
        text=legend_text,
        transform=ax.transAxes,
        fontsize=font_size_legend,
    )

    ax.set_xlabel("X")
    ax.set_ylabel("Y")
    ax.set_title(title, fontsize=font_size_title)
    ax.grid(True)
    ax.axis("equal")
    ax.axis("off")
    ax.set_xlim(profile.polygon.bounds[0] - offset, profile.polygon.bounds[2] + offset)

    if show:
        plt.show()  # pragma: no cover

    assert fig is not None

    return fig