Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
legend/color
#1
The following code is running as it should, however, when it comes to plot the graph,
the command cm.rainbow is printing the same color, and I'd like the legend to have all
values of the iteration according to the range, but I cannot manage to obtain this outcome,
instead it prints exactly whatever I write in the curly brackets.
I am not sure how should I correct my code.

def applog(n,x):
    a0=(1+x)/2
    b0=sqrt(x)
   
    for i in range(n):
        a0=(a0+b0)/2
        b0=sqrt((a0)*b0)
      
        
    return (x-1)/a0

print("the log approximation is: " , ((applog(4,4)))) 
print("log value-------------------:" , (np.log(4)) )
                   
error=(abs( applog(4,4)- (np.log(4))   ) )                    
print("the error is : ", error)
  
x = np.linspace(10, 500, 100)
nn=range(1,6)
colors = mpl.cm.rainbow(np.linspace(0, 1, len(nn)))


for c,n in zip(colors,nn):
    plt.plot(x, (applog(n,x)),color='c', label='${n}$') 
plt.plot(x, np.log(x), color='red', label='ln(x)') 
plt.legend(loc='upper left')
plt.show()          
plt.plot(x,abs(np.log(x)-applog(n,x)) )
plt.show()         
Reply


Messages In This Thread
legend/color - by mcgrim - Apr-15-2019, 12:03 PM
RE: legend/color - by Larz60+ - Apr-15-2019, 06:52 PM
RE: legend/color - by mcgrim - Apr-16-2019, 10:17 AM
RE: legend/color - by mcgrim - Apr-17-2019, 07:33 AM
RE: legend/color - by Larz60+ - Apr-17-2019, 08:21 AM
RE: legend/color - by mcgrim - Apr-17-2019, 08:27 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Turtle Star Fill Color Yellow-White Interchanging Color Effect codelab 9 1,223 Oct-25-2023, 09:09 AM
Last Post: codelab
  Unique Legend Image and Line nettesheim2 1 17,443 Sep-30-2016, 11:36 PM
Last Post: Exponential_Sinusoid

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020