图上的阴影区域

时间:2020-03-04 22:08:57

标签: matplotlib plot graph highlight curve

我正在尝试缩小我当前从左侧阴影的垂直e max线的面积。但是,我还不太清楚如何到达那里……无论如何,我可以指定要填充该区域的X轴范围吗?我唯一想到的是创建另一个点阵列以绘制e max曲线,但我希望可以有一种更简单的方法来实现这一点。

谢谢!

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

def find_roots(x,y):
    s = np.abs(np.diff(np.sign(y))).astype(bool)
    return x[:-1][s] + np.diff(x)[s]/(np.abs(y[1:][s]/y[:-1][s])+1)

#global values
sigma_ct_inf = 0
sigma_ct_0 = 0
sigma_c_inf = 30
sigma_c_0 = 12
beta = 0.8

Size = 'T90'

if Size == 'T90':
    #values T 90
    A = 431000
    Wb = 65563267.03
    Wt = 105724769.88
    Mmin = 841.80
    Mmax = 1119.14

    #Magnel Diagram
    e = np.arange(-200, 1001)
    emax = (900 - 344.49 - 100)

    t70_top_0 = pd.Series({'y': ((e - (Wt / A)) / ((Mmin * 10 ** 6) + sigma_ct_0 * Wt)) * 10 ** 6})
    t70_bot_0 = pd.Series({'y': ((e + (Wb / A)) / ((Mmin * 10 ** 6) + sigma_c_0 * Wb)) * 10 ** 6})
    t70_top_inf = pd.Series({'y': (((e - (Wt / A)) * beta) / ((Mmax * 10 ** 6) - sigma_c_inf * Wt)) * 10 ** 6})
    t70_bot_inf = pd.Series({'y': (((e + (Wb / A)) * beta) / ((Mmax * 10 ** 6) - sigma_ct_inf * Wb)) * 10 ** 6})


    bot = np.min([t70_bot_inf['y']], axis=0)
    top = np.max([t70_top_0['y'], t70_bot_0['y'], t70_top_inf['y']], axis=0)

    fig, ax = plt.subplots()
    ax.set_title('Magnel Diagram, T-90')
    ax.plot(e, t70_top_0['y'], lw=0.5, label='Top, t = 0')
    ax.plot(e, t70_bot_0['y'], lw=0.5, label='Bottom, t = 0')
    ax.plot(e, t70_top_inf['y'], lw=0.5, label='Top, t = \u221E')
    ax.plot(e, t70_bot_inf['y'], lw=0.5, label='Bottom, t = \u221E')

    ax.fill_between(e, top, bot, where= top < bot, color='r', alpha=0.4)

    xlim = [e[0], e[1200]]
    ax.set_xlim(xlim)
    ax.set_ylim([-0.2, 1])


    e_star = find_roots(e, t70_bot_inf['y'] - t70_top_0['y'])

    ax.axvline(x = e_star, ymax = 1-(1/e_star), color = 'k', lw = 0.8, linestyle = '--')
    ax.annotate('e* = ' + str(np.round(e_star, 2)), (e_star + 2, 0))
    x = np.interp(e_star, e, t70_top_0['y'])
    ax.axhline(y = x, xmax = (-xlim[0] + e_star), color = 'k', lw = 0.8, linestyle = '--')
    ax.annotate('(1/P0) max = '  + str(np.round(x, 2)), (0, x + 0.02))
    ax.axvline(x = emax, color = 'k', lw = 1)
    ax.annotate('emax = ' + str(emax), (emax + 2, 0.1))

ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
plt.ylabel('1/P0 [1/MN]')
plt.xlabel('Eccentricity [mm]')
ax.grid()
plt.legend()
plt.show()

0 个答案:

没有答案