Split plotting into separate function