I am using Jupyter Lab 2.0, matplotlib 3.2.0 and Python 3.8.0
So, I found out you can get interactive plots in Jupyter Lab, and embarked on the journey to make this happen for myself. Along the way, here are the things I tried:
- Ensured nodejs is installed
- Installed the Jupyter Lab extension manager
- Installed
ipympl
- Installed
jupyter-matplotlib
- Re-build JupyterLab
- Restart JupyterLab (several times)
Next, in my code I tried all of the following common recommendations (alone and in various combinations):
matplotlib.use("nbragg")
%matplotlib ipympl
%matplotlib widget
%matplotlib inline
At best, some of these cause all of my rcParams defaults to be overridden, and show tiny graphs with no interactivity. At worst, my graphs don't show at all, except for sometimes displaying some random text below the code.
I have tried all of the suggestions from the following SO answers, GitHub and matplotlib docs:
- jupyterlab interactive plot
- https://github.com/matplotlib/ipympl/issues/9
- https://github.com/matplotlib/ipympl/issues/133
- https://matplotlib.org/users/prev_whats_new/whats_new_1.4.html#the-nbagg-backend
Sample of my working code:
train_df = pd.read_csv('data/train.csv', index_col='PassengerId')
test_df = pd.read_csv('data/test.csv', index_col='PassengerId')
survival = train_df.pop('Survived')
df = pd.concat([train_df, test_df])
# extract last names and titles:
df['Title'] = df.Name.str.extract(r'([A-Za-z]+)\.')
# extract last name:
df['LName'] = df.Name.str.extract(r'([A-Za-z]+),')
# Plot histogram of parsed titles:
sns.countplot(df.Title).set_title("Histogram of Passenger Titles")
plt.show()
Note that I have tried this with and without plt.show()
.