You need to choose a suitable matplotlib backend. See example here:
Note that you can also use Slicer’s built-in interactive plotting features. The advantage of Slicer plots is that they are directly connected to MRML nodes: if you update a value in a table node then the plot is updated immediately (and you can drag-and-drop points in the plot to change values in a table).