From:
<hec...@te...> - 2004-04-23 18:28:39
|
hi all, i'm getting the following error when running this script. if the script doesn't iterate over "tels" it runs fine... it seems to do things right just once. thanks in advance, hector ################################################################################ ERROR ################################################################################ C:\Documents and Settings\villaf>python e:\src\python\ttp\ttp_plot.py 1082751605.0 : Fri Apr 23 12:20:05 2004 : ttp_plot start Traceback (most recent call last): File "e:\src\python\ttp\ttp_plot.py", line 56, in ? plotting_date('traffic', 'tmp_calls0', 3) File "e:\src\python\ttp\ttp_plot.py", line 39, in plotting_date plot_date(datum, vals, PyDatetimeConverter()) File "C:\Python23\Lib\site-packages\matplotlib\matlab.py", line 1011, in plot_date try: lines = gca().plot_date(*args, **kwargs) File "C:\Python23\Lib\site-packages\matplotlib\axes.py", line 1198, in plot_date locator = MinuteLocator(1) File "C:\Python23\Lib\site-packages\matplotlib\ticker.py", line 720, in __init__ MultipleLocator.__init__(self, base*SEC_PER_MIN) NameError: global name 'SEC_PER_MIN' is not defined ################################################################################ SCRIPT ################################################################################ import time, ConfigParser, MySQLdb import datetime import matplotlib matplotlib.use('Agg') from matplotlib.matlab import * from matplotlib.dates import PyDatetimeConverter, MONDAY from matplotlib.ticker import WeekdayLocator, DayLocator, DateFormatter config = ConfigParser.ConfigParser() config.readfp(open('e:\\src\\python\\ttp\\ttp.conf', 'r')) loc_host = config.get('DATABASE', 'loc_host') loc_user = config.get('DATABASE', 'loc_user') loc_passwd = config.get('DATABASE', 'loc_passwd') loc_db = config.get('DATABASE', 'loc_db') loc_db = MySQLdb.connect(host = loc_host, user = loc_user, passwd = loc_passwd, db = loc_db) cursor = loc_db.cursor() def plotting_date(db, table, dig): cursor.execute("DROP TABLE IF EXISTS %s.tmp" % (db)) cursor.execute("CREATE TABLE %s.tmp " "SELECT fecha, mid(tel,1,%d) as tel, sum(minutos) as min FROM %s.%s GROUP BY 1,2" % (db,dig,db,table)) cursor.execute("SELECT DISTINCT tel FROM %s.tmp" % (db)) tels = cursor.fetchall() for tel in tels: cursor.execute("SELECT fecha, min FROM %s.tmp WHERE tel = '%s'" % (db,tel[0])) data = cursor.fetchall() datum = [datetime.datetime(int(q[0][0:4]), int(q[0][4:6]), int(q[0][6:8]), 0, 0) for q in data] vals = [q[1] for q in data] ax = subplot(1,1,1) plot_date(datum, vals, PyDatetimeConverter()) ax.xaxis.set_major_locator(WeekdayLocator(MONDAY)) ax.xaxis.set_major_formatter(DateFormatter('%b %d')) ax.xaxis.set_minor_locator(DayLocator()) ax.xaxis.autoscale_view() title('TEST') ylabel('test') labels = ax.get_xticklabels() set(labels, 'rotation', 'vertical') grid(True) savefig("c:\\tmp\\%s_%s_test" % (tel[0],table)) # --- main -- # if __name__ == '__main__': print time.mktime(time.localtime()), ': \t', time.asctime(), ': \t', 'ttp_plot start' plotting_date('traffic', 'tmp_calls0', 3) print time.mktime(time.localtime()), ': \t', time.asctime(), ': \t', 'ttp_plot end' |
From:
<hec...@te...> - 2004-04-23 21:34:46
|
I changed the script and I got this error Thanks for your help ######################################################################## NEW ERROR ######################################################################## C:\Documents and Settings\villaf>python e:\src\python\ttp\ttp_plot.py 1082763298.0 : Fri Apr 23 15:34:58 2004 : ttp_plot start Traceback (most recent call last): File "e:\src\python\ttp\ttp_plot.py", line 60, in ? get_data('traffic', 'tmp_calls0', 3) File "e:\src\python\ttp\ttp_plot.py", line 37, in get_data plotting_date(tel[0], datum, vals) File "e:\src\python\ttp\ttp_plot.py", line 54, in plotting_date savefig("c:\\tmp\\%s_%s" % (tel,table)) File "C:\Python23\Lib\site-packages\matplotlib\matlab.py", line 1115,=20 in savefig manager.canvas.print_figure(*args, **kwargs) File=20 "C:\Python23\Lib\site-packages\matplotlib\backends\backend_agg.py", line=20 419, in print_figure self.renderer._renderer.write_png(filename) IOError: could not open file ######################################################################## SCRIPT ######################################################################## import time, ConfigParser, MySQLdb import datetime import matplotlib matplotlib.use('Agg') from matplotlib.matlab import * from matplotlib.dates import PyDatetimeConverter, MONDAY from matplotlib.ticker import WeekdayLocator, DayLocator, DateFormatter config =3D ConfigParser.ConfigParser() config.readfp(open('e:\\src\\python\\ttp\\ttp.conf', 'r')) loc_host =3D config.get('DATABASE', 'loc_host') loc_user =3D config.get('DATABASE', 'loc_user') loc_passwd =3D config.get('DATABASE', 'loc_passwd') loc_db =3D config.get('DATABASE', 'loc_db') loc_db =3D MySQLdb.connect(host =3D loc_host, user =3D loc_user, passwd =3D= =20 loc_passwd, db =3D loc_db) cursor =3D loc_db.cursor() def get_data(db, table, dig): cursor.execute("DROP TABLE IF EXISTS %s.tmp" % (db)) cursor.execute("CREATE TABLE %s.tmp " "SELECT fecha, mid(tel,1,%d) as tel, sum(minutos) as=20 min FROM %s.%s GROUP BY 1,2" % (db,dig,db,table)) cursor.execute("SELECT DISTINCT tel FROM %s.tmp" % (db)) tels =3D cursor.fetchall() for tel in tels: cursor.execute("SELECT fecha, min FROM %s.tmp WHERE tel =3D '%s'"= =20 % (db,tel[0])) data =3D cursor.fetchall() datum =3D [datetime.datetime(int(q[0][0:4]), int(q[0][4:6]),=20 int(q[0][6:8]), 0, 0) for q in data] vals =3D [q[1] for q in data] plotting_date(tel[0], datum, vals) def plotting_date(tel, datum, vals): ax =3D subplot(1,1,1) plot_date(datum, vals, PyDatetimeConverter()) ax.xaxis.set_major_locator(WeekdayLocator(MONDAY)) ax.xaxis.set_major_formatter(DateFormatter('%b %d')) ax.xaxis.set_minor_locator(DayLocator()) ax.xaxis.autoscale_view() title('TEST') ylabel('test') labels =3D ax.get_xticklabels() set(labels, 'rotation', 'vertical') grid(True) savefig("c:\\tmp\\%s_%s" % (tel,table)) # --- main -- # if __name__ =3D=3D '__main__': print time.mktime(time.localtime()), ': \t', time.asctime(), ': \t',=20 'ttp_plot start' get_data('traffic', 'tmp_calls0', 3) print time.mktime(time.localtime()), ': \t', time.asctime(), ': \t',=20 'ttp_plot end' H=E9ctor Villafuerte D. wrote: > > hi all, > i'm getting the following error when running this script. > if the script doesn't iterate over "tels" it runs fine... > it seems to do things right just once. > thanks in advance, > hector > > > #######################################################################= ######### > ERROR > #######################################################################= ######### > > C:\Documents and Settings\villaf>python e:\src\python\ttp\ttp_plot.py > 1082751605.0 : Fri Apr 23 12:20:05 2004 : ttp_plot start > Traceback (most recent call last): > File "e:\src\python\ttp\ttp_plot.py", line 56, in ? > plotting_date('traffic', 'tmp_calls0', 3) > File "e:\src\python\ttp\ttp_plot.py", line 39, in plotting_date > plot_date(datum, vals, PyDatetimeConverter()) > File "C:\Python23\Lib\site-packages\matplotlib\matlab.py", line=20 > 1011, in plot_date > try: lines =3D gca().plot_date(*args, **kwargs) > File "C:\Python23\Lib\site-packages\matplotlib\axes.py", line 1198,=20 > in plot_date > locator =3D MinuteLocator(1) > File "C:\Python23\Lib\site-packages\matplotlib\ticker.py", line 720,=20 > in __init__ > MultipleLocator.__init__(self, base*SEC_PER_MIN) > NameError: global name 'SEC_PER_MIN' is not defined > > > #######################################################################= ######### > SCRIPT > #######################################################################= ######### > > import time, ConfigParser, MySQLdb > import datetime > import matplotlib > matplotlib.use('Agg') > from matplotlib.matlab import * > from matplotlib.dates import PyDatetimeConverter, MONDAY > from matplotlib.ticker import WeekdayLocator, DayLocator, DateFormatter > > config =3D ConfigParser.ConfigParser() > config.readfp(open('e:\\src\\python\\ttp\\ttp.conf', 'r')) > loc_host =3D config.get('DATABASE', 'loc_host') > loc_user =3D config.get('DATABASE', 'loc_user') > loc_passwd =3D config.get('DATABASE', 'loc_passwd') > loc_db =3D config.get('DATABASE', 'loc_db') > > loc_db =3D MySQLdb.connect(host =3D loc_host, user =3D loc_user, passwd= =3D=20 > loc_passwd, db =3D loc_db) > cursor =3D loc_db.cursor() > > def plotting_date(db, table, dig): > > cursor.execute("DROP TABLE IF EXISTS %s.tmp" % (db)) > cursor.execute("CREATE TABLE %s.tmp " > "SELECT fecha, mid(tel,1,%d) as tel, sum(minutos)=20 > as min FROM %s.%s GROUP BY 1,2" % (db,dig,db,table)) > cursor.execute("SELECT DISTINCT tel FROM %s.tmp" % (db)) > tels =3D cursor.fetchall() > for tel in tels: > cursor.execute("SELECT fecha, min FROM %s.tmp WHERE tel =3D=20 > '%s'" % (db,tel[0])) > data =3D cursor.fetchall() > datum =3D [datetime.datetime(int(q[0][0:4]), int(q[0][4:6]),=20 > int(q[0][6:8]), 0, 0) for q in data] > vals =3D [q[1] for q in data] > > ax =3D subplot(1,1,1) > plot_date(datum, vals, PyDatetimeConverter()) > > ax.xaxis.set_major_locator(WeekdayLocator(MONDAY)) > ax.xaxis.set_major_formatter(DateFormatter('%b %d')) > ax.xaxis.set_minor_locator(DayLocator()) > ax.xaxis.autoscale_view() > title('TEST') > ylabel('test') > labels =3D ax.get_xticklabels() > set(labels, 'rotation', 'vertical') > grid(True) > savefig("c:\\tmp\\%s_%s_test" % (tel[0],table)) > > > # --- main -- # > if __name__ =3D=3D '__main__': > print time.mktime(time.localtime()), ': \t', time.asctime(), ':=20 > \t', 'ttp_plot start' > plotting_date('traffic', 'tmp_calls0', 3) > print time.mktime(time.localtime()), ': \t', time.asctime(), ':=20 > \t', 'ttp_plot end' > > > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: The Robotic Monkeys at ThinkGeek > For a limited time only, get FREE Ground shipping on all orders of $35 > or more. Hurry up and shop folks, this offer expires April 30th! > http://www.thinkgeek.com/freeshipping/?cpg=3D12297 > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > |
From: John H. <jdh...@ac...> - 2004-04-24 13:53:43
|
>>>>> "H=E9ctor" =3D=3D H=E9ctor Villafuerte D <hec...@te...= m.gt> writes: H=E9ctor> savefig("c:\\tmp\\%s_%s" % (tel,table)) File H=E9ctor> "C:\Python23\Lib\site-packages\matplotlib\matlab.py", line H=E9ctor> 1115, in savefig manager.canvas.print_figure(*args, H=E9ctor> **kwargs) File H=E9ctor> "C:\Python23\Lib\site-packages\matplotlib\backends\backend_= agg.py", H=E9ctor> line 419, in print_figure H=E9ctor> self.renderer._renderer.write_png(filename) IOError: could H=E9ctor> not open file This is a new one; I think the file is not writable and it is not a matplotlib problem per se. Is it possible that C:\\tmp does not exist? You may want to try something along the lines of import os ...snip... dirname =3D 'c:\\tmp' fname =3D os.path.join(dirname, '%s_%s' % (tel,table)) print 'dir exists', os.path.exists(dirname) print 'filename', fname file(fname, 'w').write('test\n') and see if you can see what is going wrong. JDH |
From: John H. <jdh...@ac...> - 2004-04-24 13:49:14
|
>>>>> "H=E9ctor" =3D=3D H=E9ctor Villafuerte D <hec...@te...= m.gt> writes: H=E9ctor> 720, in __init__ MultipleLocator.__init__(self, H=E9ctor> base*SEC_PER_MIN) NameError: global name 'SEC_PER_MIN' is H=E9ctor> not defined This is a bug in ticker that will be fixed in the next bugfix release. If you want to fix it yourself now, edit matplotlib/ticker.py and add SEC_PER_MIN to the list of things imported from the dates module. Ie, from dates import EpochConverter, SEC_PER_HOUR, SEC_PER_DAY, SEC_PER_WEEK= , \ SEC_PER_MIN |
From:
<hec...@te...> - 2004-04-26 15:56:09
|
John Hunter wrote: >>>>>>"H=E9ctor" =3D=3D H=E9ctor Villafuerte D <hec...@te...= m.gt> writes: >>>>>> =20 >>>>>> > > H=E9ctor> 720, in __init__ MultipleLocator.__init__(self, > H=E9ctor> base*SEC_PER_MIN) NameError: global name 'SEC_PER_MIN' is > H=E9ctor> not defined > >This is a bug in ticker that will be fixed in the next bugfix >release. If you want to fix it yourself now, edit >matplotlib/ticker.py and add SEC_PER_MIN to the list of things >imported from the dates module. Ie, > >from dates import EpochConverter, SEC_PER_HOUR, SEC_PER_DAY, SEC_PER_WEE= K, \ > SEC_PER_MIN > > =20 > Thanks John, everything works right now, except for fact that I need to "clear" it on=20 every iteration ... and the line where I try to clear the previous figure ("ax.clear()") is=20 giving me troubles. Thanks in advance! ###################################################################### ERROR ###################################################################### C:\Documents and Settings\villaf>python e:\src\python\ttp\ttp_plot.py 1083001763.0 : Mon Apr 26 09:49:23 2004 : ttp_plot start Traceback (most recent call last): File "e:\src\python\ttp\ttp_plot.py", line 58, in ? get_data('traffic', 'tmp_calls0', 3) File "e:\src\python\ttp\ttp_plot.py", line 39, in get_data plot_date(datum, vals, PyDatetimeConverter(), 'b-') File "C:\Python23\Lib\site-packages\matplotlib\matlab.py", line 1011,=20 in plot_date try: lines =3D gca().plot_date(*args, **kwargs) File "C:\Python23\Lib\site-packages\matplotlib\axes.py", line 1172, in=20 plot_date self.plot(e, y, fmt, **kwargs) File "C:\Python23\Lib\site-packages\matplotlib\axes.py", line 1156, in=20 plot self.xaxis.autoscale_view() File "C:\Python23\Lib\site-packages\matplotlib\axis.py", line 405, in=20 autoscale_view self._majorTicker.locator.autoscale() File "C:\Python23\lib\site-packages\matplotlib\ticker.py", line 567,=20 in autoscale self._locator =3D self.get_locator(d) File "C:\Python23\lib\site-packages\matplotlib\ticker.py", line 573,=20 in get_locator ld =3D log10(d) OverflowError: math range error ###################################################################### SCRIPT ###################################################################### import time, ConfigParser, MySQLdb import datetime import matplotlib matplotlib.use('Agg') from matplotlib.matlab import * from matplotlib.dates import PyDatetimeConverter, MONDAY from matplotlib.ticker import WeekdayLocator, DayLocator, DateFormatter config =3D ConfigParser.ConfigParser() config.readfp(open('e:\\src\\python\\ttp\\ttp.conf', 'r')) loc_host =3D config.get('DATABASE', 'loc_host') loc_user =3D config.get('DATABASE', 'loc_user') loc_passwd =3D config.get('DATABASE', 'loc_passwd') loc_db =3D config.get('DATABASE', 'loc_db') loc_db =3D MySQLdb.connect(host =3D loc_host, user =3D loc_user, passwd =3D= =20 loc_passwd, db =3D loc_db) cursor =3D loc_db.cursor() def get_data(db, table, dig): cursor.execute("DROP TABLE IF EXISTS %s.tmp" % (db)) cursor.execute("CREATE TABLE %s.tmp " "SELECT fecha, mid(tel,1,%d) as tel, sum(minutos) as=20 min FROM %s.%s GROUP BY 1,2" % (db,dig,db,table)) cursor.execute("SELECT DISTINCT tel FROM %s.tmp" % (db)) tels =3D cursor.fetchall() for tel in tels: cursor.execute("SELECT fecha, min FROM %s.tmp WHERE tel =3D '%s'"= =20 % (db,tel[0])) data =3D cursor.fetchall() datum =3D [datetime.datetime(int(q[0][0:4]), int(q[0][4:6]),=20 int(q[0][6:8]), 0, 0) for q in data] vals =3D [q[1] for q in data] ax =3D subplot(1,1,1) plot_date(datum, vals, PyDatetimeConverter(), 'b-') ax.xaxis.set_major_locator(WeekdayLocator(MONDAY)) ax.xaxis.set_major_formatter(DateFormatter('%b %d')) ax.xaxis.set_minor_locator(DayLocator()) ax.xaxis.autoscale_view() title('TEST') ylabel('test') labels =3D ax.get_xticklabels() set(labels, 'rotation', 'vertical') grid(True) savefig("c:\\tmp\\%s_%s" % (tel[0],table)) ax.clear() # --- main -- # if __name__ =3D=3D '__main__': print time.mktime(time.localtime()), ': \t', time.asctime(), ': \t',=20 'ttp_plot start' get_data('traffic', 'tmp_calls0', 3) print time.mktime(time.localtime()), ': \t', time.asctime(), ': \t',=20 'ttp_plot end' |
From: John H. <jdh...@ac...> - 2004-04-26 16:45:41
|
>>>>> "H=E9ctor" =3D=3D H=E9ctor Villafuerte D <hec...@te...= m.gt> writes: H=E9ctor> Thanks John, everything works right now, except for fact H=E9ctor> that I need to "clear" it on every iteration ... and the H=E9ctor> line where I try to clear the previous figure H=E9ctor> ("ax.clear()") is giving me troubles. Thanks in advance! When you call subplot(1,1,1) it will return the previously defined one and not create a new one. This is useful in interactive mode if you want to switch between active subplots. Since all command work on the active axes, you need a way to switch between them. For repeatedly drawing figures in a loop, I recommend for tel in tels: figure(1) ...plot... close(1) rather than using clear. However, it does not appear from your traceback that clear is directly causing the problem. You are getting an overflow error on the call to log10(d) where d is the datalim distance. It might be useful to check your datum and vals ranges to make sure they are what you think they are and not some obscenely large number. What happens if you do converter =3D PyDatetimeConverter() e =3D [converter.epoch(thisd) for thisd in datum] print 'date range', min(e), max(e) print 'val range', min(vals), max(vals) before the call to plot_date? In any case, I think it better to return no ticks and warn rather than die, so I've changed the ld =3D log10(d) line in matplotlib.ticker.AutoLocator.get_locator to try: ld =3D log10(d) except OverflowError: print >> sys.stderr, 'AutoLocator illegal datalim range %= s; returning NullLocator'%d return NullLocator() You may want to try this after checking the above. Let me know how it goes. JDH |