# 2 questions : savefig + show 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,p,p,p,p,p,p,p)
#save(p+p+p+p+p+p+p+p,"~/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 close merge delete

Sort by » oldest newest most voted 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)

more 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

more

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.

* 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).