astrofrog / mpl-scatter-density

:zap: Fast scatter density plots for Matplotlib :zap:
BSD 2-Clause "Simplified" License
494 stars 24 forks source link

Does not work with inline matplotlib on Jupyter-Notebooks #15

Open ijoseph opened 6 years ago

ijoseph commented 6 years ago

MWE:

In a Jupyter Notebook,

%matplotlib inline

import mpl_scatter_density

import numpy as np

import matplotlib.pyplot as plt

N = 10000000
x = np.random.normal(4, 2, N)
y = np.random.normal(3, 1, N)

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='scatter_density')
ax.scatter_density(x, y)
ax.set_xlim(-5, 10)
ax.set_ylim(-5, 10)

throws TypeError: 'NoneType' object is not iterable.

Using Jupyter Notebook version 5.0.0, matplotlib version 2.1.0 on Google Chrome on MacOS 10.13.4.

However, works fine with %matplotlib notebook.

FedericoV commented 6 years ago

Not very elegant, but this fixes it:

hist = ax.scatter_density(x, y)
hist.set_extent(hist.get_extent())
ijoseph commented 6 years ago

Welp, that definitely isn't elegant (seems like the coding equivalent of a mathematical tautology), yet it does work! Fantastic. Thank you.

ijoseph commented 6 years ago

Wow, this is so good. seaborn's hexgrid is a joke, comparatively, in terms of both speed and informativeness.