沿图的X轴自由移动峰的公式

问题描述

我绘制了一个指数图,现在我想沿X轴自由移动峰。
中心应该像铃铛,右边应该像我当前的图表,但完全相反。
我该怎么做?

import matplotlib
import math
import numpy as np
matplotlib.use('Agg')
import matplotlib.pyplot as plt

arr_name=[]
arr_value=[]
k=-0.01
for l in range(0,100):
    x=pow(k,2)*np.exp(-k*1.8);
    if (l%10)==0:
        arr_name.append(l/10)
    else:
        arr_name.append("")
    arr_value.append(x)
    k=k+0.05
    print x

y_pos = np.arange(len(arr_name))
plt.figure(figsize=(8,4))
plt.rcParams.update({'font.size': 8})
plt.subplot(1,1,1)
plt.plot(y_pos,arr_value,'-r')
plt.xticks(y_pos,arr_name)
plt.savefig('/var/www/html/bar/img/test_chart.png')

exponential chart

更新
可能的解决方案是在图表中心绘制峰值:

for l in range(0,5)*np.exp(-k*1.96);
    if (l%10)==0:
        arr_name.append(l/10)
    else:
        arr_name.append("")
    arr_value.append(x)
    if l>50:
        k=k-0.05
    else:
        k=k+0.05
    print x

enter image description here

增加可逆性:

arr_value.reverse()

enter image description here

解决方法

您可以在没有四环的情况下更轻松地进行绘制。改变指数内部的系数会移动峰的值和位置。

import matplotlib.pyplot as plt
import numpy as np

def f(x,s):
   x**2 * np.exp(-s*x)

x = np.linspace(0,10,100)
y1 = f(x,1.8)
y2 = f(x,0.8)

plt.plot(x,y1,label='s=1.8')
plt.plot(x,y2,label='s=0.8')
plt.legend()
plt.show()

enter image description here