creates plot function