Improve script to automatically draw plots