[_memory_viz.py] Fix bug when using profile_plot (#103384)
When we updated plotting to add level of detail the Legend
code for profile_plot got broken. This patch fixes it.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/103384
Approved by: https://github.com/drisspg