test_plot_implicit: Cleanup the figures created after the tests are over

I also refactored the existing code for the utility classes/functions
used in the tests into a separate module.
@debugger22 not sure what you are referring to?