问题描述
在jupyter笔记本中,是否有一种方法可以在每个内联matplotlib图形下方添加乳胶图形标题?希望这样做,以便在运行nbconvert --to乳胶时对每个图形进行注释.
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.
但是我不清楚如何相对于以\ begin {verbatim}块结尾的图形放置LaTeX.我可以将其放置在情节之后的markdown单元格中;但是,这并没有像我想要的那样包装数字.
But I am not clear on how to position the LaTeX relative to the figure which ends up in \begin{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图形下添加乳胶图形标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!