put plots into a function