Unable to center plot in zero due to infinite result in function: y = math.exp(-(1/(x**2)))

37 Views Asked by At

The plot is not centered in zero because as there is an infinite result when x takes the value = 0. How can I solve this issue and have the graphic centered in zero?

import math
import numpy as np
import matplotlib.pyplot as plt

def f(start, stop, step):
    
    values = []
    for x in np.arange(start, stop, step):
        y = math.exp(-(1/(x**2)))
        values.append(y)
    return values

# usage
start = -5
stop = 5
step = 1
values = f(start, stop, step)
print(values)

# Plot the function
plt.plot(values)
plt.grid(axis = 'x')
plt.grid(axis = 'y')

# title and axis labels
plt.title("e**-(1/(x**2))")
plt.xlabel("x")
plt.ylabel("y")

# Show the plot
plt.show()

I have tried to prevent the variable x to take the zero value but the result is the same.

0

There are 0 best solutions below