cardiff: Moving plotting code in separate function

To make the code easier to read, let's make a function about the
plotting stuff.