refactored matrix plot