Ask Your Question
1

2 questions : savefig + show

asked 2023-01-02 21:02:06 +0100

ErWinz gravatar image

hello here my code that works

x=var('x')
f(x)=exp(-1/x^2)
p=[]
legendes=[]
for n in range(8):
    dn(x)=diff(f(x), x, n)
    print("f^(",n,")(x)=",dn(x))
    delta=n/2
    p.append(\
        plot(dn(x)/factorial(n),-4+delta,4-delta)\
        +text("n="+str(n),(0,0.1*factorial(n)),color="green",bounding_box={'boxstyle':'round', 'fc':'w'}))
show(p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7])
#save(p[0]+p[1]+p[2]+p[3]+p[4]+p[5]+p[6]+p[7],"~/Desktop/toto.png")

#savefig("~/Desktop/toto.png")

my questions :

a) how can i automatize the show, can i write. For example :

show(p[i] for in in range(8))

dont give the image but a code that says : <πšπšŽπš—πšŽπš›πšŠπšπš˜πš›Β πš˜πš‹πš“πšŽπšŒπšΒ <πšπšŽπš—πšŽπš‘πš™πš›>Β πšŠπšΒ πŸΆπš‘πŸ·πŸΌπŸΎπš‹πŸ·πšπšπŸ»πŸΆ>

b) i can't find the way to save instead of show

in the help, the formulation is something like A.save but i can't get it, dont understand how to write this type of code with mine ?

thanks :-)

edit retag flag offensive close merge delete

2 Answers

Sort by Β» oldest newest most voted
2

answered 2023-01-02 22:54:01 +0100

For (a) you can use show(*[p[i] for i in range(8)]).

For (b), one option is to construct a graphics array:

P = graphics_array([p[i] for i in range(8)], 2, 4)  # 2x4 array of the images
P.save(FILENAME)
edit flag offensive delete link more
0

answered 2023-01-03 00:32:51 +0100

ErWinz gravatar image

thanks very much it works very weel

so if in understand well : these both codes are equivalent, aren't they ?

show(*[p[i] for i in range(8)])

show(graphics_array([p[i] for i in range(8)], 2, 4))

so that * is a sort of shortcut of graphics_array() ?

for the second :

P = graphics_array([p[i] for i in range(8)], 2, 4)
#show(P)
P.save("~/Desktop/toto.png")

gives

[Errno 2] No such file or directory: '~/Desktop/toto.png'

i will try to find it out alone

Vinz

edit flag offensive delete link more

Comments

The use of ~ in filenames is a shell thing, and Python doesn't understand it, or at least this function doesn't understand it. Use the full path: /home/username/toto.png or whatever.

John Palmieri gravatar imageJohn Palmieri ( 2023-01-03 05:54:39 +0100 )edit

* is Python syntax. It passes to show not a single argument, which is a list, but instead passes each of that list's entries as the arguments. So show(*[1,2,3]) is equivalent to show(1,2,3).

John Palmieri gravatar imageJohn Palmieri ( 2023-01-03 05:56:46 +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

Stats

Asked: 2023-01-02 21:02:06 +0100

Seen: 154 times

Last updated: Jan 03 '23