When plotting, use Agg backend in matplotlib to avoid X-server connection.