Assigning a value to single underscore _ in Python/IPython interpreter

The Python interpreter assigns the last expression value to _. This behaviour is limited to the REPL interpreter only, and is intended to assist in interactive coding sessions: >>> import math >>> math.pow(3.0, 5) 243.0 >>> result = _ >>> result 243.0 The standard Python interpreter goes to some length to not trample on user-defined … Read more

matplotlib python inline on/off

You can switch the matplotlib’s backend by %matplotlib <backend>. To switch back to your system’s default backend use %matplotlib auto or just simply %matplotlib. There are many backends available such as gtk, qt, notebook, etc. I personally highly recommend the notebook (a.k.a. nbagg) backend. It is similar to inline but interactive, allowing zooming/panning from inside … Read more

show origin axis (x,y) in matplotlib plot

Using subplots is not too complicated, the spines might be. Dumb, simple way: %matplotlib inline import numpy as np import matplotlib.pyplot as plt x = np.linspace(0.2,10,100) fig, ax = plt.subplots() ax.plot(x, 1/x) ax.plot(x, np.log(x)) ax.set_aspect(‘equal’) ax.grid(True, which=”both”) ax.axhline(y=0, color=”k”) ax.axvline(x=0, color=”k”) And I get: (you can’t see the vertical axis since the lower x-limit is … Read more

How to change the default browser used by the ipython/jupyter notebook in Linux?

You can create jupyter_notebook_config.py by: jupyter notebook –generate-config Then you go to ~/.jupyter/jupyter_notebook_config.py and change # c.NotebookApp.browser=”” to for example: c.NotebookApp.browser=”/usr/bin/google-chrome %s” You can choose which ever browser is installed. You’ll find the path for example by typing which firefox Do not forget to delete the #