fixed 'reference before assignment' error 

'reference before assignment' error when legend is in standard
(upper right) position. Fixed by setting 'position' and 'anchor' to
'None' if 'legend._loc==1'