make plotting code general