How do you restrict the scaling of the sine wave upto certain value
<p>I am using the below codes so as to scale up the amplitude of the sine wave after the limit value 20.Here I am not able to restrict the amplitude of the sine wave.Please refer the figure below.I need the output as mentioned in figure in single plot window[not via subplot]. I need only amplitude scaling not the frequency scaling.Could any one help me in this.</p>

<pre><code>import matplotlib.pyplot as plt
import numpy as np

Limit=20

x=np.linspace(-20,20,400)
y=np.sin(x)
plt.plot(x,y)

y[(y&lt;=Limit)] = y*0.5
plt.plot(x,y)

plt.grid()
plt.show()
</code></pre>

<p><a href="http://i.stack.imgur.com/ODimr.png" rel="nofollow"><img src="http://i.stack.imgur.com/ODimr.png" alt="enter image description here"></a></p>

<p>It can be done relatively straightforward as follows:</p>

<pre><code>import matplotlib.pyplot as plt
import numpy as np

Limit=20

x=np.linspace(-20,20,4000)
y=np.sin(x)
plt.plot(x[x&lt;0],y[x&lt;0], lw=2, color='k')

y[(y&lt;=Limit)] = y*0.5
plt.plot(x[x&gt;0],y[x&gt;0], lw=2, color='k')

plt.grid()
plt.show()
</code></pre>

<p>which produces:</p>

<p><a href="http://i.stack.imgur.com/Sth8e.png" rel="nofollow"><img src="http://i.stack.imgur.com/Sth8e.png" alt="Output from the example code"></a></p>

python numpy matplotlib