user6830309
user6830309

Reputation:

How to get the x and y intercept in matplotlib?

I have scoured the internet and can't find a python command to find the x and y intercepts of a curve on matplotlib. Is there a command that exists? or is there a much easier way that is going over my head? Any help would be appreciated. Thanks,

Nimrodian.

Upvotes: 2

Views: 15239

Answers (2)

A.Kot
A.Kot

Reputation: 7913

Use this. Much faster:

slope, intercept = np.polyfit(x, y, 1)

x and y are arrays (or lists) of your coordinates. The third parameter sets the degree of the fitting polynomial. In the case of a first degree polynomial here, it will find coefficients to fit the following function: y = Ax + b. The parameters A and B are the slope and y-intercept, respectively.

See more details on this routine here: https://numpy.org/doc/stable/reference/generated/numpy.polyfit.html

Upvotes: 6

sytech
sytech

Reputation: 41051

for x, y in zip(x_values, y_values):
    if x == 0 or y == 0:
        print(x, y)

Upvotes: 0

Related Questions