jupyter nbconvert img_test.ipynb --to rst import nbformat
from nbconvert import RSTExporter
nbfile = 'img_test.ipynb'
basename, _ = os.path.splitext(nbfile)
with open(nbfile, 'r') as nb:
nbdata = nbformat.reads(nb.read(), as_version=4)
body, images = RSTExporter().from_notebook_node(nbdata)
with open(basename + '.rst', 'w') as rst_out:
rst_out.write(body)
for img_name, img_data in images['outputs'].items():
with open(img_name, 'wb') as img:
img.write(img_name)
Here's the bad image from the python function. Notice the difference in the x-axis label
Here's the notebook spec that generated both of those:
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline\n",
"from matplotlib.pyplot import subplots\n",
"fig, ax = subplots()\n",
"ax.set_xlabel('Alpha and Beta (α=0, β=1)')\n",
"fig.tight_layout()"
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python [default]",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
In this line:Can you try adding a parameter to open(..., encoding='utf-8')I think it's reading the notebook file wrong because of the default encoding on Windows.
nbdata = nbformat.read(nbf, as_version=4, encoding='utf-8')