more work on trying to merge duplicated plotting code