new encode_plot function in utils