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:
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?
There is a Python API for this:
from IPython.display import set_matplotlib_formats
set_matplotlib_formats('retina')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With