Preparing data for plots