'How to mark the maximum value and location of 4 equations in one plot (shear diagram - portal frame)?

I´m an mechanical engineering student and I'm trying to make a shear diagram of a portal frame.

In the code below I want to identify for each equation (4 in total) the maximum value and correspondent position on the plot. How can I do that? Is it possible to mark the location with a "x"?

The equations are vpilar 1, vpilar 2, vasna1 and vasna2.

Code:

import math as mt
import numpy as np
import matplotlib.pyplot as plt
  
v = 20 #(Vão em metros)
h = 6 #("Altura do pilar em metros:")
ht = 8 #("Altura total metros:")
alfa_rad = mt.atan((int(ht)-int(h))/(int(v)/2))
alfa_deg = alfa_rad*180/mt.pi
lasna = ((v/2) ** 2 + (ht-h) ** 2) ** 0.5

alfa = (mt.atan((int(ht)-int(h))/(int(v)/2)))*180/((mt.pi))
print("Ângulo da vertente:", round(alfa, 1), "º")


h1 = np.arange(0, h+1, 1)
ha1 = np.arange(0, lasna, 0.1)
ha2 = np.arange(0, lasna, 0.1)
hp2 = np.arange(0, h+1, 1)

R = lambda x, y, theta: np.array([
    [np.cos(theta), np.sin(theta), x],
    [-np.sin(theta), np.cos(theta), y],
    [0, 0, 1],
])
Vx = np.array([
    [1, 0, 0], [0, -1, 0], [0, 0, 1]
])
Vy = np.array([
    [-1, 0, 0], [0, 1, 0], [0, 0, 1]
])
vpilar1 = (1000 * h1 ** 2 + 50)/ 1000
vasna1 = (50 *ha1 ** 2 + 5) / 1000
vasna2 = (100 * ha2 ** 2 + 7) / 1000
vpilar2 = (150 * hp2 ** 2 + 5) / 1000

def draw_line():

    x_number_list = [0, 0, (v/2), v, v]
    y_number_list = [0, h, ht, h, 0]
    plt.plot(x_number_list, y_number_list, linewidth=3)
    
    points1 = np.stack([h1, vpilar1 / max(abs(vpilar1)), np.ones_like(h1)])
    points1 = np.matmul(R(0, 0, -np.pi/2), points1)
    plt.plot(points1[0, :], points1[1, :], label="Vpilar1")
    
    points2 = np.stack([h1, vpilar2 / max(abs(vpilar2)), np.ones_like(h1)])
    points2 = np.matmul(R(v, 0, -np.pi/2), points2)
    plt.plot(points2[0, :], points2[1, :], label="Vpilar2")
    
    points3 = np.stack([ha1, vasna1 / max(abs(vasna1)), np.ones_like(ha1)])
    points3 = np.matmul(R(0, h, -alfa_rad), points3)
    plt.plot(points3[0, :], points3[1, :], label="Vasna1")
    
    points4 = np.stack([ha1, vasna2 / max(abs(vasna2)), np.ones_like(ha1)])
    points4 = np.matmul(np.matmul(R(v, h, alfa_rad), Vy), points4)
    plt.plot(points4[0, :], points4[1, :], label="Vasna2")
    
    plt.title("Esforço de Corte", fontsize=15)
    plt.show()

draw_line()


Solution 1:[1]

With np.argmax you find the index of the maximum of an array. Then extract the coordinates of that position, and apply the same transformation matrix you previously applied to the moments. Finally, your mark this new position on the chart:

import math as mt
import numpy as np
import matplotlib.pyplot as plt
  
v = 20 #(Vão em metros)
h = 6 #("Altura do pilar em metros:")
ht = 8 #("Altura total metros:")
alfa_rad = mt.atan((int(ht)-int(h))/(int(v)/2))
alfa_deg = alfa_rad*180/mt.pi
lasna = ((v/2) ** 2 + (ht-h) ** 2) ** 0.5

alfa = (mt.atan((int(ht)-int(h))/(int(v)/2)))*180/((mt.pi))
print("Ângulo da vertente:", round(alfa, 1), "º")


h1 = np.arange(0, h+1, 1)
ha1 = np.arange(0, lasna, 0.1)
ha2 = np.arange(0, lasna, 0.1)
hp2 = np.arange(0, h+1, 1)

R = lambda x, y, theta: np.array([
    [np.cos(theta), np.sin(theta), x],
    [-np.sin(theta), np.cos(theta), y],
    [0, 0, 1],
])
Vx = np.array([
    [1, 0, 0], [0, -1, 0], [0, 0, 1]
])
Vy = np.array([
    [-1, 0, 0], [0, 1, 0], [0, 0, 1]
])
vpilar1 = (1000 * h1 ** 2 + 50)/ 1000
vasna1 = (50 *ha1 ** 2 + 5) / 1000
vasna2 = (100 * ha2 ** 2 + 7) / 1000
vpilar2 = (150 * hp2 ** 2 + 5) / 1000

def draw_line():
    plt.figure()
    
    x_number_list = [0, 0, (v/2), v, v]
    y_number_list = [0, h, ht, h, 0]
    plt.plot(x_number_list, y_number_list, linewidth=3)
    
    points1 = np.stack([h1, vpilar1 / max(abs(vpilar1)), np.ones_like(h1)])
    points1 = np.matmul(R(0, 0, -np.pi/2), points1)
    plt.plot(points1[0, :], points1[1, :], label="Vpilar1")
    idx = np.argmax(vpilar1)
    max_p = np.array([[h1[idx], (vpilar1 / max(abs(vpilar1)))[idx], 1]]).T
    max_p_tranformed = np.matmul(R(0, 0, -np.pi/2), max_p)
    plt.scatter(*max_p_tranformed[:-1], marker="x", color="k")
    
    points2 = np.stack([h1, vpilar2 / max(abs(vpilar2)), np.ones_like(h1)])
    points2 = np.matmul(R(v, 0, -np.pi/2), points2)
    plt.plot(points2[0, :], points2[1, :], label="Vpilar2")
    idx = np.argmax(vpilar2)
    max_p = np.array([[h1[idx], (vpilar2 / max(abs(vpilar2)))[idx], 1]]).T
    max_p_tranformed = np.matmul(R(v, 0, -np.pi/2),  max_p)
    plt.scatter(*max_p_tranformed[:-1], marker="x", color="k")
    
    points3 = np.stack([ha1, vasna1 / max(abs(vasna1)), np.ones_like(ha1)])
    points3 = np.matmul(R(0, h, -alfa_rad), points3)
    plt.plot(points3[0, :], points3[1, :], label="Vasna1")
    idx = np.argmax(vasna1)
    max_p = np.array([[ha1[idx], (vasna1 / max(abs(vasna1)))[idx], 1]]).T
    max_p_tranformed = np.matmul(R(0, h, -alfa_rad), max_p)
    plt.scatter(*max_p_tranformed[:-1], marker="x", color="k")
    
    points4 = np.stack([ha1, vasna2 / max(abs(vasna2)), np.ones_like(ha1)])
    points4 = np.matmul(np.matmul(R(v, h, alfa_rad), Vy), points4)
    plt.plot(points4[0, :], points4[1, :], label="Vasna2")
    idx = np.argmax(vasna2)
    max_p = np.array([[ha1[idx], (vasna2 / max(abs(vasna2)))[idx], 1]]).T
    max_p_tranformed = np.matmul(np.matmul(R(v, h, alfa_rad), Vy), max_p)
    plt.scatter(*max_p_tranformed[:-1], marker="x", color="k")
    
    plt.title("Esforço de Corte", fontsize=15)
    plt.show()

draw_line()

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Davide_sd