Ask Your Question
0

Label function automaticaly, 2d plot

asked 7 years ago

thetha gravatar image

updated 7 years ago

kcrisman gravatar image

Function:

def random_between(j,k):
    a=int(random()*(k-j+1))+j
    return a 

t = var('t')

m1=random_between(-5,5)
b1=random_between(-5,5)
y1=m1*t+b1

m2=random_between(-5,5)
b2=random_between(-5,5)
y2=m2*t+b2

m3=random_between(-5,5)
b3=random_between(-5,5)
y3=m3*t+b3

m4=random_between(-5,5)
b4=random_between(-5,5)
y4=m4*t+b4

p1=plot(y1, (t,-5,5), gridlines=True,color='red')
p2=plot(y2, (t,-5,5), gridlines=True,color='green')
p3=plot(y3, (t,-5,5), gridlines=True,color='orange')
p4=plot(y4, (t,-5,5), gridlines=True,color='pink')
p=p1+p2+p3+p4
show(p)

Well, I would like to view full grid, and auto lable functions, is this possible, i have here 3 Books, do i have to look somewhere else?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
3

answered 7 years ago

kcrisman gravatar image

The secret sauce is that you can ask legend_label to use the LaTeX representation of the function like so:

p1=plot(y1, (t,-5,5), gridlines=True,color='red', legend_label='$'+latex(y1)+'$')

See this live example.

Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 7 years ago

Seen: 349 times

Last updated: Mar 11 '18