如何在 jupyter/matplotlib 图形下方添加乳胶图形标题 [英] How to add latex figure captions below jupyter / matplotlib figures
问题描述
在 jupyter notebook 中,有没有办法在每个内联 matplotlib 图形下方添加乳胶图形标题?这是需要的,以便在运行 nbconvert --to latex 时对每个图形进行注释.
From within the jupyter notebook, is there a way to add latex figure caption below each inline matplotlib figure? This is desired so that each figure is annotated when running nbconvert --to latex.
但我不清楚如何相对于在 egin{verbatim} 块中结束的图形定位 LaTeX.我可以将它放在情节之后的降价单元格中;但是,这并没有像我想要的那样包装数字.
But I am not clear on how to position the LaTeX relative to the figure which ends up in egin{verbatim} block. I can place it in a markdown cell just after the plot; but, that does not wrap the figure as I want.
推荐答案
有点变通方法,但是下面的辅助函数调用 plt.close() 来阻止显示内联图形,只留下为图形生成的 LaTeX 块.
A bit of a workaround but the following helper function calls plt.close() to keep the inline figures from being displayed leaving only the generated LaTeX block for the figure.
bShowInline = True # Set = False for document generation
def makeplot( plt, figlabel, figcaption):
figname = figlabel+'.png'
plt.savefig(figname)
if bShowInline:
plt.show()
else:
plt.close()
strLatex="""
\begin{figure}[b]
centering
includegraphics[totalheight=10.0cm]{%s}
caption{%s}
label{fig:%s}
end{figure}"""%(figname, figcaption, figlabel)
return display(Latex(strLatex))
有没有更清洁的方法?
这篇关于如何在 jupyter/matplotlib 图形下方添加乳胶图形标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!