Skip to content

Instantly share code, notes, and snippets.

@nsarode
Last active September 18, 2022 05:40
Show Gist options
  • Save nsarode/4fc6ace22c72f0450a1753d45d766bf2 to your computer and use it in GitHub Desktop.
Save nsarode/4fc6ace22c72f0450a1753d45d766bf2 to your computer and use it in GitHub Desktop.
Jupyter lab notebook tips & tricks [#python #jupyter]

Generic

Cell operation shortcuts

❗ capitalization doesn't matter for these shortcuts

  • b to add new cell below
  • m change cell to markdown
  • y change cell to code
  • dd delete cell
  • ctrl + B toggle files tab (on the left)
  • cmd + \ comment/uncomment multiple selected lines (Note : For windows use ctrl+\ )

Rescue lost code (function) from a Jupyter/IPython notebook

Code Source

def rescue_code(function):
    import inspect
    get_ipython().set_next_input("".join(inspect.getsourcelines(function)[0]))

rescue_code(functionName)

Plots and images

To show plots in line

%matplotlib inline

Changing inline plot size

fig=plt.figure(figsize=(18, 16))

Additional parameters that could be adjusted

fig=plt.figure(figsize=(18, 16), dpi= 80, facecolor='w', edgecolor='k')

Default inline plot sizes can be changed too

matplotlib.rcParams['figure.figsize'] = [width, height]

Kernel

To show complete kernel output i.e. see output from ALL statements like a regular kernel

By default, jupyter notebook truncates the stdout. This is to make sure that everything is printed (use responsibly !)

from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"

Remote access

Access jupyter notebooks securely on remote linux machine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment