.. _immplscatterdensityrst: =================== mpl-scatter-density =================== .. only:: html **Links:** :download:`notebook `, :downloadlink:`html `, :download:`PDF `, :download:`python `, :downloadlink:`slides `, :githublink:`GitHub|_doc/notebooks/2016/pydata/im_mpl_scatter_density.ipynb|*` `mpl-scatter-density `__ speeds up density graph. `matplotlib `__ is very slow when it comes to draw millions of points. `datashader `__ is one alternative but was meant for zooming/dezooming. This package provides a simple functionality. The example comes the documentation. .. code:: %matplotlib inline .. code:: from jyquickhelper import add_notebook_menu add_notebook_menu() .. contents:: :local: example ------- .. code:: import numpy as np import mpl_scatter_density import matplotlib.pyplot as plt import matplotlib.colors as col # Generate fake data N = 10000000 x = np.random.normal(4, 2, N) y = np.random.normal(3, 1, N) # Make the plot - note that for the projection option to work, the # mpl_scatter_density module has to be imported above. fig = plt.figure() ax = fig.add_subplot(1, 1, 1, projection='scatter_density') try: ax.scatter_density(x, y) ax.set_xlim(-5, 10) ax.set_ylim(-5, 10) except AttributeError as e: print('issue with more recent version') print(e) .. parsed-literal:: issue with more recent version 'NoneType' object has no attribute 'vmin' .. image:: im_mpl_scatter_density_4_1.png The corresponding *matplotib* function does not exist as is. The module `seaborn `__ provides density visualization but it is not designed for such big sample. .. code:: import numpy as np import seaborn as sns import matplotlib.pyplot as plt # Generate fake data N = 10000 x = np.random.normal(4, 2, N) y = np.random.normal(3, 1, N) #import seaborn as sns import matplotlib.pyplot as plt f, ax = plt.subplots(figsize=(8, 8)) ax = sns.kdeplot(x, y, shade=True, shade_lowest=False) .. parsed-literal:: c:\python372_x64\lib\site-packages\statsmodels\tools\_testing.py:19: FutureWarning: pandas.util.testing is deprecated. Use the functions in the public API at pandas.testing instead. import pandas.util.testing as tm .. image:: im_mpl_scatter_density_6_1.png