i have the following code:
import psycopg2
import pylab
class Datenanzeige:
def __init__(self):
self.conn = psycopg2.connect("dbname='test' user='test' host='test' password='test'")
self.cur = self.conn.cursor()
self.site = ['FFF', 'PPP', 'DDD', 'KKK']
self.plant = [1, 2, 3, 4, 5, 6]
def anzeige(self):
for i in range(4):
for j in range(6):
self.datProd1 = []
self.datProd2 = []
self.cur.execute("""
SELECT proddate, Sum(mods) AS Summevonmods
FROM "20091229global"
GROUP BY proddate, site, plant, pid
HAVING proddate > Date('today') - 14
AND
site='"""+self.site[i]+"""'
AND
pid=802
AND
plant='"""+str(self.plant[j])+"""'
ORDER BY proddate, site, plant, pid;
""")
self.row = self.cur.fetchone()
while self.row:
self.datProd1.append(self.row[0])
self.datProd2.append(self.row[1])
pylab.title('Progress of %s' %self.site[i])
pylab.ylabel('number')
pylab.xlabel('date')
pylab.plot(self.datProd1, self.datProd2)
pylab.savefig("bild%i" %i )
self.row=self.cur.fetchone()
q = Datenanzeige()
q.anzeige()
the code is working. i get for every self.site variable another picture but every following picture includes the lines of the former one. how can i prevent this?
i need separate pictures without lines of the former one.
To do what you want, you need do one of two things:
use the
clf()andcla()(clear figure and clear axes respectively) methods after you’ve saved your figures.Create multiple figures, and then set the title and axes label on each figure. At the moment, you’re using a default background figure that pylab gives you. You need to explicitly create and modify different ones. I can’t write the exact code of the top of my head to do that, but a look at the matplotlib api should give you what you are looking for. It will look something like this: