Optimized plotting routine