配置Ipython的后端以通过代码使用视网膜显示模式 [英] Configure the backend of Ipython to use retina display mode with code

查看:160
本文介绍了配置Ipython的后端以通过代码使用视网膜显示模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用代码配置Jupyter笔记本,因为我有一个包含大量笔记本的存储库,并且希望在所有笔记本之间保持样式一致性,而不必在每个笔记本的开头都写冗长的设置.这样,我所做的就是拥有一种配置CSS的方法,一种用于设置Matplotlib的方法,另一种用于配置Ipython的方法.

I am using code to configure Jupyter notebooks because I have a repo with plenty of notebooks and want to keep style consistency across all without having to write lengthy setting at the start of each. This way, what I do is having a method to configure the CSS, one to set up Matplotlib and one to configure Ipython.

我以这种方式配置笔记本而不是依赖 docs 是两个:

The reasons I configure my notebooks this way rather than relying on a configuration file as per docs are two:

  1. 我正在公开共享笔记本的这个仓库,我希望我的所有配置都可见
  2. 我想保留这些配置,使其仅适用于我正在创建的此回购协议

作为示例,设置CSS的方法如下

As an example, the method to set the CSS looks like

def set_css_style(css_file_path='../styles_files/custom.css'):

    styles = open(css_file_path, "r").read()
    return HTML(styles)

,我在每个笔记本的开头都用set_css_style()来称呼它.同样,我有这种方法来配置Ipython的细节:

and I call it at the start of each notebook with set_css_style(). Similarly, I have this method to configure the specifics of Ipython:

def config_ipython():

    InteractiveShell.ast_node_interactivity = "all"

以上两种用途都可以导入

Both the above use imports

from IPython.core.display import HTML
from IPython.core.interactiveshell import InteractiveShell

目前,可以看出,配置Ipython的方法仅包含创建它的指令,因此当我在单元格中的多行中键入变量名称时,无需添加print使它们全部被打印.

At the moment, as can be seen, the method to configure Ipython only contains the instruction to make it so that when I type the name of variables in multiple lines in a cell I don't need to add a print to make them all be printed.

我的问题是如何将Jupyter magic命令转换为数字以获得视网膜显示质量的代码.这样的命令是

My question is how to transform the Jupyter magic command to obtain retina-display quality for figures into code. Such command is

%config InlineBackend.figure_format = 'retina'

从Ipython的文档中,我找不到如何在方法中调用此指令的方法,即找不到InlineBackend的住处.

From the docs of Ipython I can't find how to call this instruction in a method, namely can't find where InlineBackend lives.

我只想将此配置行添加到上面的config_ipython方法中,可以吗?

I'd just like to add this configuration line to my config_ipython method above, is it possible?

推荐答案

查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆