[英]How to write Jinja2 template for Jupyter nbconvert to show markdown and suppress output number?
我正在嘗試編寫一個Jinja2
模板,以使用nbconvert
通過LaTex
將Jupyter notebook
轉換為PDF。 我目前的嘗試未顯示Markdown單元格或圖像標題,並且在所有matplotlib圖形上方都顯示了以下輸出:
out[1]: <matplotlib.axes._subplots.AxesSubplot at 0x2e62e885cc0>
我想顯示markdown單元格和標題,並禁止顯示matplotlib對象描述。
我當前的模板改編自nbconvert github存儲庫上托管的模板,如下所示:
% Default to the notebook output style
((* if not cell_style is defined *))
((* set cell_style = 'style_ipython.tplx' *))
((* endif *))
% Inherit from the specified cell style.
((* extends cell_style *))
%===============================================================================
% Latex Book
%===============================================================================
((* block docclass *))
\documentclass{report}
((* endblock docclass *))
% Author and Title from metadata
((* block maketitle *))
((*- if nb.metadata["latex_metadata"]: -*))
((*- if nb.metadata["latex_metadata"]["title"]: -*))
\title{((( nb.metadata["latex_metadata"]["title"] )))}
((*- endif *))
((*- else -*))
\title{((( resources.metadata.name )))}
((*- endif *))
\date{\today}
\maketitle
((* endblock maketitle *))
((* block markdowncell scoped *))
((( cell.source | citation2latex | strip_files_prefix | convert_pandoc('markdown+tex_math_double_backslash', 'json',extra_args=[]) | resolve_references | convert_pandoc('json','latex', extra_args=["--chapters"]) )))
((* endblock markdowncell *))
% Disable input cells
((* block input_group *))
((* endblock input_group *))
這似乎幾乎不是一個“答案”,但是您是否嘗試在代碼單元的最后一行的末尾使用分號? Jupyter的正常行為是顯示代碼單元返回的最后一個對象。 如果您的最后一行與matplotlib
,則該行代碼通常返回一個matplotlib
對象,您通常對此並不十分感興趣。因此,例如:
from matplotlib.pyplot import plot, xlabel, grid
from numpy import linspace, sin
x = linspace(-20, 20, 200)
plot(x, sin(x))
grid()
xlabel('x')
產生您所描述的輸出。 以下不會產生單行打印。 唯一的區別是最后的分號。
from matplotlib.pyplot import plot, xlabel, grid
from numpy import linspace, sin
x = linspace(-20, 20, 200)
plot(x, sin(x))
grid()
xlabel('x');
避免輸出的另一種方法是重新排列行。 grid()
函數通常返回None
,因此,如果將該行放在最后,也不會獲得任何輸出。
這是您要問的嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.