After a bit of fiddling it was clear that my overall approach was totally wrong. My script had three tiled subplots and I was dancing around tiles and text files. Then I was trying to add the legend to each tile. Modifying this script was murder.
It's much easier to read all the text files into arrays or structures first. Then do the plots. I don't know why I didn't use this approach.
Thanks to all who posted. I'll come back with a new question if I run into problems with the new approach.