Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Move the bottom of a curve without changing both ends

I’m having a curve as follows:

enter image description here

The curve is generated with the following code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import matplotlib.pyplot as plt
import numpy as np

# normalize array
def min_max_scale_array(arr):
    arr = np.array(arr)
    return (arr - arr.min())/(arr.max()-arr.min())

x = np.linspace(-50,48,100)
y = x**2 + 2*x + 2  

x = min_max_scale_array(x)
y = min_max_scale_array(y)

fig, ax = plt.subplots()
ax.plot(x, y)

How can I generate a new curve by moving only the bottom left (or right) and keeping both ends the same like this? Thank you!

enter image description here

Edit: any curve generating algorithm is appreciated, as long as it works!

>Solution :

One way of doing so is defining x,y as before, but applying a shift. The dotted line shows if you just shift it. But now at the top most y we don’t want to shift it, so we’d like to weight the shifted version on the bottom (y=0) by 1 but on the top (y=1) by 0 such that we get a gradual interpolation. We can do this by multiplying the shift by (1-y):

enter image description here

a = 0.25  # how far to shift left
plt.plot(x, y, 'k')
plt.plot(x-a, y, 'k:')
plt.plot(x-a*(1-y), y, 'r')
plt.show()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading