Ask Your Question
1

plot() command in load .sage script

asked 2013-05-20 17:39:17 +0200

mresimulator gravatar image

updated 2015-01-14 09:39:45 +0200

FrédéricC gravatar image

Hi experts!!

When i save a .sage script (like 'lalala.sage') with the next text:

var('x')
f(x)=4*sin(x)
plot(f,(x,-3,3))

and then, in SAGE, i put

load('lalala.sage')

there doesn't appears the graph of the f(x), but if i put in SAGE (after load 'lalala.sage'):

plot(f,(x,-3,3))

then the graph of f(x) appears

The question is: Why doesn't appears the graph of f(x) when i load the scipt 'lalala.sage'?

Thanks so much!!

Best regards

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2013-05-20 17:59:08 +0200

tmonteil gravatar image

updated 2013-05-20 18:02:53 +0200

plot(f,(x,-3,3)) defines a graphical object. From a .sage script, this is just the object.

When you call an object from the command line, it wants to be represented, by calling the hidden .__repr__() method. For a plot object, the .__repr__() method just calls the .show() method.

Hence, if you want your .sage script to show the graphical object you defined with the command plot, you should tell it explicitely, by writing:

plot(f,(x,-3,3)).show()

instead of just

plot(f,(x,-3,3))

As a comparison, it is the same difference between

2

and

print(2)

Both will output 2 in the command line, but only the second will write something when called from a .sage script.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2013-05-20 17:39:17 +0200

Seen: 657 times

Last updated: May 20 '13