rewrite of plotting script