What solved the problem for me was to restart my kernel, import the following first:
import matplotlib
matplotlib.use('TKAgg')
Then,
import matplotlib.pyplot as plt
You probably imported matplotlib with another framework before you tried to change to TKAgg. Restart your kernel.