is there any alternative to savefig?

K

kiwanuka

Hi all,

I wonder if anyone knows any alternative function in pylab (or
otherwise) that could be used to save an image. My problem is as
follows:

---------------
from pylab import *
....

figure(1)
fig1 = gca()
figure(2)
fig2 = gca()
figure(3)
fig3 = gca()

for i,data_file in enumerate(data_file_list):
time,x, y,x2, y2 = read_csv_file_4(open
(data_file),elements=num_of_elements)
fig1.plot(-x,-y,color=colours,label=labellist)
fig2.plot(time,-y,color=colours,label=labellist)
fig3.plot(time,-x,color=colours,label=labellist)

fig1.legend(loc='best')
fig1.set_title("y1 - x1")
fig1.set_ylabel("y1")
fig1.set_xlabel("x1")
#savefig("y1-x1.png")

fig2.legend(loc='best')
fig2.set_title("y1 - time")
fig2.set_ylabel("y1")
fig2.set_xlabel("time")
#savefig("y1-time.png")

fig3.legend(loc='best')
fig3.set_title("x1 - time")
fig3.set_ylabel("x1")
fig3.set_xlabel("time")
#savefig("x1-time.png")
show()
---------------------------

In the above code, I read multiple data files and plot three separate
figures. Now I would like to save each of the figures to a file as the
commented savefig satements suggest. The trouble is that if I
uncomment all those savefig statements, I get three saved images all
containing the plot belonging to figure(3), which was the last figure
declared.

I understand this to be happening because savefig will save the
"current" figure, which in this case happens to be the last one
declared.

If I could do something like fig1.savefig("y1-x1.png") or savefig("y1-
x1.png").fig1, this would solve the problem but I'm not aware of any
such methods or modules to enable this. This is thus a flaw in the
general design/implementation of the savefig function, but is there an
alternative function to enable me achieve what I need? Is there
perhaps a possible tweak to savefig to make it do the same?

Thanks in advance,

Robert
 
K

kiwanuka

Hi all,

I wonder if anyone knows any alternative function in pylab (or
otherwise) that could be used to save an image. My problem is as
follows:

---------------
from pylab import *
...

figure(1)
fig1 = gca()
figure(2)
fig2 = gca()
figure(3)
fig3 = gca()

for i,data_file in enumerate(data_file_list):
   time,x, y,x2, y2 = read_csv_file_4(open
(data_file),elements=num_of_elements)
   fig1.plot(-x,-y,color=colours,label=labellist)
   fig2.plot(time,-y,color=colours,label=labellist)
   fig3.plot(time,-x,color=colours,label=labellist)

fig1.legend(loc='best')
fig1.set_title("y1 - x1")
fig1.set_ylabel("y1")
fig1.set_xlabel("x1")
#savefig("y1-x1.png")

fig2.legend(loc='best')
fig2.set_title("y1 - time")
fig2.set_ylabel("y1")
fig2.set_xlabel("time")
#savefig("y1-time.png")

fig3.legend(loc='best')
fig3.set_title("x1 - time")
fig3.set_ylabel("x1")
fig3.set_xlabel("time")
#savefig("x1-time.png")
show()
---------------------------

In the above code, I read multiple data files and plot three separate
figures. Now I would like to save each of the figures to a file as the
commented savefig satements suggest. The trouble is that if I
uncomment all those savefig statements, I get three saved images all
containing the plot belonging to figure(3), which was the last figure
declared.

I understand this to be happening because savefig will save the
"current" figure, which in this case happens to be the last one
declared.

If I could do something like fig1.savefig("y1-x1.png") or savefig("y1-
x1.png").fig1, this would solve the problem but I'm not aware of any
such methods  or modules to enable this. This is thus a flaw in the
general design/implementation of the savefig function, but is there an
alternative function to enable me achieve what I need? Is there
perhaps a possible tweak to savefig to make it do the same?

Thanks in advance,

Robert


Problem solved.
 
A

Alf P. Steinbach

* kiwanuka:
Hi all,

I wonder if anyone knows any alternative function in pylab (or
otherwise) that could be used to save an image. My problem is as
follows:

---------------
from pylab import *
...

figure(1)
fig1 = gca()
figure(2)
fig2 = gca()
figure(3)
fig3 = gca()

for i,data_file in enumerate(data_file_list):
time,x, y,x2, y2 = read_csv_file_4(open
(data_file),elements=num_of_elements)
fig1.plot(-x,-y,color=colours,label=labellist)
fig2.plot(time,-y,color=colours,label=labellist)
fig3.plot(time,-x,color=colours,label=labellist)

fig1.legend(loc='best')
fig1.set_title("y1 - x1")
fig1.set_ylabel("y1")
fig1.set_xlabel("x1")
#savefig("y1-x1.png")

fig2.legend(loc='best')
fig2.set_title("y1 - time")
fig2.set_ylabel("y1")
fig2.set_xlabel("time")
#savefig("y1-time.png")

fig3.legend(loc='best')
fig3.set_title("x1 - time")
fig3.set_ylabel("x1")
fig3.set_xlabel("time")
#savefig("x1-time.png")
show()
---------------------------

In the above code, I read multiple data files and plot three separate
figures. Now I would like to save each of the figures to a file as the
commented savefig satements suggest. The trouble is that if I
uncomment all those savefig statements, I get three saved images all
containing the plot belonging to figure(3), which was the last figure
declared.

I understand this to be happening because savefig will save the
"current" figure, which in this case happens to be the last one
declared.

If I could do something like fig1.savefig("y1-x1.png") or savefig("y1-
x1.png").fig1, this would solve the problem but I'm not aware of any
such methods or modules to enable this. This is thus a flaw in the
general design/implementation of the savefig function, but is there an
alternative function to enable me achieve what I need? Is there
perhaps a possible tweak to savefig to make it do the same?

Thanks in advance,

Robert


Problem solved.


That's nice, but would you mind telling the group the solution?

Assuming that you haven't (I don't see all messages posted to the e-mail list,
only what's propagated to Usenet or originating there).


Cheers,

- Alf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top