0

I'm new to python and have a question. I've figured out how to graph functions, but how do I plot a point which indicates the max and minimum values? Here is my code, and it graphs properly I believe. Thank you.

    import numpy as np  
    import matplotlib.pyplot as plt  
    def graph(formula, x_range):  
        x = np.array(x_range)  
        y = eval(formula)
        plt.plot(x, y)  
        plt.show()

    graph('-x**4 + 508 * x + 40', range(-10, 200))

enter image description here

2
  • Out of curiosity, why would you be plotting a single point? Is the idea to superimpose it onto another plot? Commented Aug 27, 2015 at 18:42
  • Oh, I'm just trying to learn how to use python, don't really have a purpose yet :) Commented Aug 27, 2015 at 19:30

1 Answer 1

3
n_max = y.argmax()
plt.plot(x[n_max],y[n_max],'o')
n_min = y.argmin()
plt.plot(x[n_min],y[n_min],'x')

something like this?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.