nbval
nbval copied to clipboard
inhibit comparison of matplotlib plots output as pdf
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
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?).
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.
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