Write graph to a pdf instead of displaying it.