convert linear graph to exponential graph based on the values

1.1k views Asked by At

I want to convert the linear graph to exponential graph. There are 2 values generated on x-axis value of SCORE which ranges from [-1,-0.9,-0.8,..0,0.1,0.2,....1] and y-axis value range from [0,255]

The linear graph generated is

enter image description here

And I want the exponential graph as given in the below image to be generated

enter image description here

I want to scale the y-values in such a way they have an exponential shape and their maximum value is 255.

1

There are 1 answers

3
Pablo C On BEST ANSWER

You only need to scale the values for the y-axis, but first you need to do some simple math. As you want your largest y-value to be 255, you need to solve:

eq1

which results in:

eq2

So, you have to scale by this number. Now let's see the code

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(-1,1,21)
y = np.linspace(0,255,21)

#scaling here
y = (np.e**(np.log(255)/255))**y

plt.xlabel("Score")
plt.ylabel("Pixel")
plt.plot(x,y)
plt.show()

enter image description here