Refactored code that handles plotting empty graphs.