1
To build parables I like to use exponential function, basically his parable is a gaussian function, pq i like exponential function (exp)
? simply because I can control where the parable will be centered beyond controlling the width of the window... to demonstrate I have created a vector (dados)
size 1200
, in some positions added "peaks"
dados = np.zeros(1200)
dados[70] = 0.9
dados[290] = 0.9
dados[505] = 0.9
dados[720] = 0.9
dados[1000] = 0.9
All the rest of the vector is composed of zeros, Plot of the vector dados
:
So now I want to insert a parable into each of these peaks...
created an auxiliary vector to help me find the relative exponential value of the parable:
x= np.linspace(0, 1, len(dados))
the vector is spaced by 1
and has the same size as the input vector, now comes the cool part of the joke, create the parabola in the positions of the peaks of Plot above:
np.exp(-np.power(x - pos, float(2.)) / (2 * np.power(lenKernel, float(2.))))
The above function calculates a Gaussian function (parable):
x=vetor auxiliar
lenKernel=largura da janela
pos=posição onde a parábola será centrada
Now you can add this function to every necessary peak, the output of my code produces the following Plot:
Complete code:
import numpy as np
import matplotlib.pyplot as plt
dados = np.zeros(1200)
dados[70] = 0.9
dados[290] = 0.9
dados[505] = 0.9
dados[720] = 0.9
dados[1000] = 0.9
lenKernel =0.020
y=0;
x= np.linspace(0, 1, len(dados))
for i in [(70), (290), (505), (720), (1000)]:
pos=i/float(len(dados))
y=np.exp(-np.power(x - pos, float(2.)) / (2 * np.power(lenKernel, float(2.)))) + y
plt.plot(dados)
plt.plot(y)
plt.show()
Do you already have the initial code - creating the number series and calling the Plot function? It makes it easier to help you, instead of having to create the whole program - and it’s the norm too - ask for help on punctual elements of a program, rather than "how do you do that?" - leaving all the work for those who want to help you.
– jsbueno
@jsbueno That’s right. I’ll post the whole code and the part I don’t know
– mleas
the part that is missing is more or less what has in the "hello world" of matplotlb - so did not bother so much in this case - but keep in mind for the next issues.
– jsbueno