Merge pull request #3257 from matthew-brett/refactor-plot-directive

MRG: refactor and bugfixes for plot_directive