updated plotting function