Ask Your Question
0

Plot in a function

asked 2015-12-23 13:54:43 +0100

Neabfi gravatar image

updated 2015-12-23 15:46:32 +0100

Hello,

Is it normal that i can't plot in a function ?

Without a function:

plot(point([1, 1]))

image description

With a function:

def toto():
    plot(point([1, 1]))
toto()

image description

Thanks in advance !

edit retag flag offensive close merge delete

Comments

Can you provide the code you used?

vdelecroix gravatar imagevdelecroix ( 2015-12-23 15:31:12 +0100 )edit

All the code is in the pictures. :(

Neabfi gravatar imageNeabfi ( 2015-12-23 15:37:31 +0100 )edit

It is better to write the code instead of providing picture. If I want to try the code it is simpler for me to do a copy paste... that is not possible with pictures.

vdelecroix gravatar imagevdelecroix ( 2015-12-23 15:41:03 +0100 )edit

Sorry, I have edited my post.

Neabfi gravatar imageNeabfi ( 2015-12-23 15:47:00 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-12-23 15:44:51 +0100

vdelecroix gravatar image

First of all in your code you can replace plot(point([1,1])) by point([1,1]).

And the answer is yes. All plot functions return a graphic objects that can be further manipulated. In your function you are creating a graphic but not using it at all. The following code shows what is a graphic

sage: G = point([1,1])
sage: type(G)
<class 'sage.plot.graphics.Graphics'>
sage: G    # will show the graphics

If you want that your function shows the graphic you can do

def my_graphic():
    G = point([1,1])
    G.show()

If you want that your function returns a graphic you can do

def my_graphic():
    G = point([1,1])
    return G
edit flag offensive delete link more

Comments

Thanks ! If I call several times the function, how can I concatenate the graphics to show them in one graph ?

Neabfi gravatar imageNeabfi ( 2015-12-23 15:53:45 +0100 )edit

Just use addition

sage: point([1,1]) + point([3,2])
vdelecroix gravatar imagevdelecroix ( 2015-12-23 15:56:03 +0100 )edit

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: 2015-12-23 13:54:43 +0100

Seen: 772 times

Last updated: Dec 23 '15