added plotting function, with error