nbval icon indicating copy to clipboard operation
nbval copied to clipboard

inhibit comparison of matplotlib plots output as pdf

Open chrisjsewell opened this issue 7 years ago • 3 comments

Hey guys, nice package. However, I have matplotlib outputting pdf format, so am getting a lot of:

Traceback: mismatch 'application/pdf'
<<<<<<<<<<<< Reference output from ipynb file:
JVBERi0x...<snip base64, md5=69c76c0e76f1e696...>
============ disagrees with newly computed (test) output:
JVBERi0x...<snip base64, md5=4f47c0c9cd063f84...>
>>>>>>>>>>>>

I guess the simplest fix would be to have the option to add "application/pdf" to self.skip_compare

chrisjsewell avatar Aug 22 '17 03:08 chrisjsewell

I think that fix sounds reasonable if you want to send a PR. We don't have any good option to compare PDFs, unless nbdime can do that now (@vidartf?).

takluyver avatar Aug 22 '17 10:08 takluyver

Jupyterlab is getting a PDF renderer, so nbdime should be able to display that when it propagates down. However, it is not currently possible as far as I know, no.

vidartf avatar Aug 22 '17 20:08 vidartf

Yeh will do. I think, as I've seen discussed a bit in the other issues here, comparing images/pdf out of matplotlib is probably not going to be robust enough anyway. To add my 2 cents, its not the cleanest thing to do with matplotlib, but a model-view type approach could be a simpler compromise:

from IPython.display import display
import matplotlib.pyplot as plt
import io
def show_fig(model):
    file_obj = io.BytesIO()
    plt.savefig(file_obj, format='png')
    plt.close()
    display({'image/png':file_obj.getvalue(),
                 'application/json':model}, raw=True)

x = [1, 2]
y = [3, 4]
plt.plot(x, y)
show_fig({'x':x, 'y':y})

Then just compare the json

chrisjsewell avatar Aug 22 '17 23:08 chrisjsewell