繁体   English   中英

在jupyter笔记本中设置markdown内联的字体大小

[英]Setting font size for markdown inline in jupyter notebook

我想通过python笔记本中的代码设置默认字体大小和字体类型。

例如,我使用它来设置绘图大小默认值:

params = {'legend.fontsize': 'x-large','figure.figsize': (15, 10),'axes.labelsize': 'x-large','axes.titlesize':'x-large',
         'xtick.labelsize':'x-large','ytick.labelsize':'x-large'}
pylab.rcParams.update(params)

我用它来设置窗口宽度默认值

from IPython.core.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))

是否有一个命令允许我将默认降价字体设置为Arial大小24? 谢谢!

可以修补MarkdownCell.render以将markdown单元格渲染为指定的字体大小。

将下面的代码段转储到代码单元格中并运行。

from IPython.core.display import Javascript, display

def set_markdown_font():
    javascript = """
    var _render = IPython.MarkdownCell.prototype.render;

    if (_render.decorator === undefined) {
      IPython.MarkdownCell.prototype.render = function () {
        this.element.find('.rendered_html p').css('font-size', '30px');
        return _render.apply(this, arguments);
      }
      IPython.MarkdownCell.prototype.render.decorator = true;
    }
    """
    display(Javascript(data=javascript))

set_markdown_font()

编辑

您还可以使用.rendered_html类定位HTMLElement并对其进行适当的样式设置。 我更喜欢这个(CSS over JS)。

from IPython.core.display import display, HTML
display(HTML("<style>.rendered_html { font-size: 30px; }</style>"))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM