refactor plotting