astrofrog / mpl-scatter-density

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

AttributeError: 'NoneType' object has no attribute 'vmin' #29

Closed NicksonYap closed 4 years ago

NicksonYap commented 4 years ago

Hi there, the library looks awesome, but was getting error even when using the simple example:

Jupyter Lab Matplotlib version: 3.3.0 Python version: 3.8.3 Windows 10

Will be trying out different versions of Python / Matplotlib to see if the error occurs

import numpy as np
import mpl_scatter_density
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')
density = ax.scatter_density(x, y)
ax.set_xlim(-5, 10)
ax.set_ylim(-5, 10)
fig.colorbar(density, label='Number of points per pixel')
fig.savefig('gaussian_colorbar.png')

Error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-18-7c56861efce8> in <module>
     10 fig = plt.figure()
     11 ax = fig.add_subplot(1, 1, 1, projection='scatter_density')
---> 12 density = ax.scatter_density(x, y)
     13 ax.set_xlim(-5, 10)
     14 ax.set_ylim(-5, 10)

~\.conda\envs\TestPythonProject\lib\site-packages\mpl_scatter_density\scatter_density_axes.py in scatter_density(self, x, y, dpi, downres_factor, color, cmap, alpha, norm, **kwargs)
     51         self.set_ylim(np.min(y), np.max(y))
     52 
---> 53         scatter = ScatterDensityArtist(self, x, y, dpi=dpi, downres_factor=downres_factor,
     54                                        color=color, cmap=cmap,
     55                                        alpha=alpha, norm=norm, **kwargs)

~\.conda\envs\TestPythonProject\lib\site-packages\mpl_scatter_density\scatter_density_artist.py in __init__(self, ax, x, y, downres_factor, c, **kwargs)
     56     def __init__(self, ax, x, y, downres_factor=4, c=None, **kwargs):
     57         self.histogram2d_helper = FixedDataDensityHelper(ax, x, y, c=c, downres_factor=downres_factor)
---> 58         super(ScatterDensityArtist, self).__init__(ax, histogram2d_func=self.histogram2d_helper, **kwargs)
     59 
     60     def set_xy(self, x, y):

~\.conda\envs\TestPythonProject\lib\site-packages\mpl_scatter_density\generic_density_artist.py in __init__(self, ax, dpi, color, vmin, vmax, norm, histogram2d_func, update_while_panning, **kwargs)
     54         self._density_vmax = np.nanmax
     55 
---> 56         super(GenericDensityArtist, self).__init__(ax, array_func=histogram2d_func, dpi=dpi, update_while_panning=update_while_panning, **kwargs)
     57 
     58         if color is not None:

~\.conda\envs\TestPythonProject\lib\site-packages\mpl_scatter_density\base_image_artist.py in __init__(self, ax, dpi, array_func, update_while_panning, **kwargs)
     54     def __init__(self, ax, dpi=72, array_func=None, update_while_panning=True, **kwargs):
     55 
---> 56         super(BaseImageArtist, self).__init__(ax, **kwargs)
     57 
     58         self._array_func = array_func

~\.conda\envs\TestPythonProject\lib\site-packages\matplotlib\image.py in __init__(self, ax, cmap, norm, interpolation, origin, extent, filternorm, filterrad, resample, **kwargs)
    895         self._extent = extent
    896 
--> 897         super().__init__(
    898             ax,
    899             cmap=cmap,

~\.conda\envs\TestPythonProject\lib\site-packages\matplotlib\image.py in __init__(self, ax, cmap, norm, interpolation, origin, filternorm, filterrad, resample, **kwargs)
    242                  ):
    243         martist.Artist.__init__(self)
--> 244         cm.ScalarMappable.__init__(self, norm, cmap)
    245         if origin is None:
    246             origin = mpl.rcParams['image.origin']

~\.conda\envs\TestPythonProject\lib\site-packages\matplotlib\cm.py in __init__(self, norm, cmap)
    232         self._A = None
    233         self.norm = None  # So that the setter knows we're initializing.
--> 234         self.set_norm(norm)  # The Normalize instance of this ScalarMappable.
    235         self.cmap = None  # So that the setter knows we're initializing.
    236         self.set_cmap(cmap)  # The Colormap instance of this ScalarMappable.

~\.conda\envs\TestPythonProject\lib\site-packages\mpl_scatter_density\generic_density_artist.py in set_norm(self, norm)
     89 
     90     def set_norm(self, norm):
---> 91         if norm.vmin is not None:
     92             self._density_vmin = norm.vmin
     93         if norm.vmax is not None:

AttributeError: 'NoneType' object has no attribute 'vmin'
astrofrog commented 4 years ago

Fix forthcoming! (it is an issue that occurs with Matplotlib 3.3)