Configure the backend of Ipython to use retina display mode with code

旧城冷巷雨未停 提交于 2019-12-21 02:14:08

问题


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.

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

  1. I am sharing this repo of notebooks publicly and I want all my configs to be visible
  2. I want to keep these configs specific to just this repo I'm creating

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)

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

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.

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'

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

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


回答1:


There is a Python API for this:

from IPython.display import set_matplotlib_formats
set_matplotlib_formats('retina')


来源:https://stackoverflow.com/questions/42611694/configure-the-backend-of-ipython-to-use-retina-display-mode-with-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!