pack the plot into function