fix some bugs in plotting script