from os import path p = path.dirname(path.abspath(__file__)) hash = subprocess.check_output(["git", "rev-list", "-1", "HEAD", "./"], cwd=p).strip()
import pandas as pd import numpy as np import matplotlib.pyplot as plt import matplotlib.gridspec as gs %matplotlib inline df = pd.DataFrame([ np.random.randn(1000), np.random.random_integers(1, 2, 1000) ]).T df.columns = ["value", "group"] fig = plt.figure(figsize=(10, 6)) grid = gs.GridSpec(2, 2, height_ratios=[3, 1]) for i, g in enumerate([1, 2]): subset = df['value'][df['group'] == g] # Histogram ax = plt.subplot(grid[i]) ax.hist(list(subset), color='k', alpha=0.4) ax.set_title("Group %s" % g) # Box plot ax2 = plt.subplot(grid[i+2]) pd.DataFrame(subset).boxplot(vert=False, return_type='axes') ax2.set_yticklabels(['']) fig.tight_layout() fig.subplots_adjust(top=0.85) fig.suptitle('Example', fontsize=20) None # Don't display the last thing -- `%matplotlib inline` will display the graphs no matter what.
It looks like Gist embed is broken here on PostHaven for IPython notebooks, so the embed below may look strange:
This was actually pretty easy. Here’s what I did:
- Opened a new Terminal window that wasn’t in a
brew install python3
cd ~/.virtualenvs(the folder where my virtualenvs are)
virtualenv -p `which python3` data3to create a new virtualenv using Python 3
workon data3(this is from virtualenvwrapper)
pip install "ipython[all]"
Update: I've been trying out pyenv, which is forked from my much-beloved rbenv. It seems to work fine with virtualenv via pyenv-virtualenv, but I could not get pyenv-virtualenvwrapper to work. I'm using this now to run an updated version of Python 2 without messing with my system Python, and it seems to work fine.
When sharing IPython notebooks with non-programmers, I don't want to cause confusion by including a bunch of code.
Here is the code snippet to put in the cell at the top of the notebook:
And here is an example of how this works in nbviewer.ipython.org.
(The source code for this example and the accompanying HTML output are available here.)