1

I would like to plot x^c for different values of c on the same graph using just for loop and matplotlib library, with different colors for each function . When I try using for loop, the output just shows one graph.

****CODE****

import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
plt.figure()
x = np.linspace(0,1,100)
for i in range(-10,10,21):
    if i<0:
        plt.plot(x,x**(abs(1/i)))
    elif i>0:
        plt.plot(x,x**i)
plt.show()

1 Answer 1

1

Your range() function right now produces only a single value of -10. May be you need

for i in range(-10,10,1):

which produces

enter image description here

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

2 Comments

But what if i want continuous rainbow colors from the first function to the last
@AthulDev : That would be a different question.

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.