I've written my first python script with matplotlib, which works fine at the
command line but not with cron. It's quite puzzling to me, and probably
involves some path declaration that I don't know about.
#plot data from automate.csv
import matplotlib
import datetime
import numpy
from matplotlib import legend
from matplotlib.pyplot import figure, show, plot_date, setp, ylabel, savefig,
xlabel
from matplotlib.dates import DayLocator, HourLocator, DateLocator,
DateFormatter,drange, MinuteLocator, date2num, num2date
from matplotlib.mlab import csv2rec
from matplotlib.ticker import *
newr = csv2rec('/home/paulsimon/Documents/automate.csv')
x = date2num(newr.field(0))
fig = figure()
ax1 = fig.add_subplot(111)
line1, = ax1.plot_date(newr['dattim'], newr['bench_1'], '-r',label = 'bench 1')
line2, = ax1.plot_date(newr['dattim'], newr['bench_2'], '-b', label = 'bench 2')
line3, = ax1.plot_date(newr['dattim'], newr['eave'],'-k', label = 'eave')
line4, = ax1.plot_date(newr['dattim'], newr['outside'], '-g', label = 'outside')
ylabel('temperature')
xlabel(r'time/date')
hours = HourLocator(range(0,26,4))
dateformatter = DateFormatter('%I:%M %p\n%m/%d/%y')
ax1.xaxis.set_major_formatter(dateformatter)
ax1.xaxis.set_major_locator(hours)
ax1.set_ylim(30,100)
# Rotate x labels
for label in ax1.xaxis.get_ticklabels():
label.set_fontsize(8)
ax1.grid(True)
ax1.xaxis.grid(False)
yminorLocator = MultipleLocator(5)
ax1.yaxis.set_minor_locator(yminorLocator)
ax1.yaxis.grid(True,which='major', linestyle ='-')
ax1.yaxis.grid(True,which='minor',linestyle = ':')
leg = ax1.legend(('bench 1', 'bench 2', ' eave', 'outside'), 'lower right',
shadow = True)
for t in leg.get_texts():
t.set_fontsize('small')
savefig('/home/paulsimon/python_scripts/image.png', format = 'png')
Running with --debug option, here are the two different output files:
$HOME=/home/paulsimon
CONFIGDIR=/home/paulsimon/.matplotlib
matplotlib data path /usr/lib/python2.5/site-packages/matplotlib/mpl-data
loaded rc file /usr/lib/python2.5/site-packages/matplotlib/mpl-data/matplotlibrc
matplotlib version 0.91.2
verbose.level debug
interactive is False
units is False
platform is linux2
loaded modules: ['_bisect', 'xml.sax.urlparse', 'distutils',
'matplotlib.matplotlib', 'datetime', 'matplotlib.tempfile',
'distutils.sysconfig', 'encodings.encodings', 'pytz.cStringIO', 'xml',
'distutils.dep_util', 'struct', 'tempfile', 'xml.sax.urllib', 'imp', '_struct',
'pytz.os', 'zipimport', 'string', 'encodings.utf_8', 'matplotlib.__future__',
'pytz.tzinfo', 'pytz.datetime', 'distutils.re', 'bisect', 'signal', 'random',
'xml.sax.xmlreader', 'matplotlib.pytz', 'distutils.log', 'pytz.tzfile',
'cStringIO', 'pkgutil', 'locale', 'xml.sax.saxutils', 'encodings', 'dateutil',
'matplotlib.warnings', 'matplotlib.string', 'pytz.pytz', 'urllib',
'matplotlib.sys', 're', 'new', 'math', 'fcntl', 'UserDict', 'distutils.os',
'matplotlib', 'codecs', 'md5', '_locale', 'matplotlib.sre_constants',
'matplotlib.os', 'thread', 'pkg_resources', 'weakref', 'itertools',
'distutils.spawn', 'distutils.sys', 'os', 'sre_parse', '__future__',
'matplotlib.copy', 'xml.sax.types', '_sre', '__builtin__', 'matplotlib.re',
'operator', 'distutils.util', 'distutils.string', 'matplotlib.datetime',
'posixpath', 'errno', '_socket', 'binascii', 'sre_constants', 'matplotlib.md5',
'types', 'pytz.sys', 'xml.sax.handler', 'pytz.pkg_resources', 'xml.sax.os',
'matplotlib.xml', '_codecs', 'pytz', 'matplotlib.pyparsing', 'copy', 'socket',
'_types', 'matplotlib.dateutil', 'hashlib', 'posix', 'encodings.aliases',
'matplotlib.fontconfig_pattern', 'exceptions', 'xml.sax._exceptions',
'pytz.bisect', 'distutils.distutils', 'copy_reg', 'sre_compile', 'xml.sax',
'_hashlib', '_random', 'pytz.struct', 'site', '__main__', 'shutil',
'matplotlib.weakref', 'strop', 'encodings.codecs', 'gettext',
'matplotlib.rcsetup', 'pytz.sets', 'xml.sax.codecs', 'stat', '_ssl',
'warnings', 'encodings.types', 'sets', 'sys', 'xml.sax.sys', 'os.path',
'pytz.gettext', 'matplotlib.distutils', '_weakref', 'distutils.errors',
'urlparse', 'linecache', 'matplotlib.shutil', 'time']
Using fontManager instance from /home/paulsimon/.matplotlib/fontManager.cache
numerix numpy 1.0.4
backend GTKAgg version 2.12.1
findfont found Bitstream Vera Sans, normal, normal 400, normal, 8.0
findfont returning
/usr/lib/python2.5/site-packages/matplotlib/mpl-data/fonts/ttf/Vera.ttf
findfont found Bitstream Vera Sans, normal, normal 400, normal, 8.0
findfont returning
/usr/lib/python2.5/site-packages/matplotlib/mpl-data/fonts/ttf/Vera.ttf
findfont found Bitstream Vera Sans, normal, normal 400, normal, 8.0
...
findfont returning
/usr/lib/python2.5/site-packages/matplotlib/mpl-data/fonts/ttf/Vera.ttf
findfont found Bitstream Vera Sans, normal, normal 400, normal, 9.996
findfont returning
/usr/lib/python2.5/site-packages/matplotlib/mpl-data/fonts/ttf/Vera.ttf
And this is the output file (complete) running under cron:
$HOME=/home/paulsimon
CONFIGDIR=/home/paulsimon/.matplotlib
matplotlib data path /usr/lib/python2.5/site-packages/matplotlib/mpl-data
loaded rc file /usr/lib/python2.5/site-packages/matplotlib/mpl-data/matplotlibrc
matplotlib version 0.91.2
verbose.level debug
interactive is False
units is False
platform is linux2
loaded modules: ['_bisect', 'xml.sax.urlparse', 'distutils',
'matplotlib.matplotlib', 'datetime', 'matplotlib.tempfile',
'distutils.sysconfig', 'encodings.encodings', 'pytz.cStringIO', 'xml',
'distutils.dep_util', 'struct', 'tempfile', 'xml.sax.urllib', 'imp', '_struct',
'pytz.os', 'zipimport', 'string', 'matplotlib.__future__', 'pytz.tzinfo',
'pytz.datetime', 'distutils.re', 'bisect', 'signal', 'random',
'xml.sax.xmlreader', 'matplotlib.pytz', 'distutils.log', 'pytz.tzfile',
'cStringIO', 'pkgutil', 'locale', 'xml.sax.saxutils', 'encodings', 'dateutil',
'matplotlib.warnings', 'matplotlib.string', 'pytz.pytz', 'urllib',
'matplotlib.sys', 're', 'new', 'math', 'fcntl', 'UserDict', 'distutils.os',
'matplotlib', 'codecs', 'md5', '_locale', 'matplotlib.sre_constants',
'matplotlib.os', 'thread', 'pkg_resources', 'weakref', 'itertools',
'distutils.spawn', 'distutils.sys', 'os', 'sre_parse', '__future__',
'matplotlib.copy', 'xml.sax.types', '_sre', '__builtin__', 'matplotlib.re',
'operator', 'distutils.util', 'distutils.string', 'matplotlib.datetime',
'posixpath', 'errno', '_socket', 'binascii', 'sre_constants', 'matplotlib.md5',
'types', 'pytz.sys', 'xml.sax.handler', 'pytz.pkg_resources', 'xml.sax.os',
'matplotlib.xml', '_codecs', 'pytz', 'matplotlib.pyparsing', 'copy', 'socket',
'_types', 'matplotlib.dateutil', 'hashlib', 'posix', 'encodings.aliases',
'matplotlib.fontconfig_pattern', 'exceptions', 'xml.sax._exceptions',
'pytz.bisect', 'distutils.distutils', 'copy_reg', 'sre_compile', 'xml.sax',
'_hashlib', '_random', 'pytz.struct', 'site', '__main__', 'shutil',
'matplotlib.weakref', 'strop', 'encodings.codecs', 'gettext',
'matplotlib.rcsetup', 'pytz.sets', 'xml.sax.codecs', 'stat', '_ssl',
'warnings', 'encodings.types', 'encodings.ascii', 'sets', 'sys', 'xml.sax.sys',
'os.path', 'pytz.gettext', 'matplotlib.distutils', '_weakref',
'distutils.errors', 'urlparse', 'linecache', 'matplotlib.shutil', 'time']
numerix numpy 1.0.4
Using fontManager instance from /home/paulsimon/.matplotlib/fontManager.cache
The plot output took me a lot of time to work out, which I enjoyed, and the
output is dazzling!
Paul Simon
------------------------------------------------------------------------------
_______________________________________________
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users