added code to use Agg backend for non-interactive plotting