Example #1
0
 def test_cmap_scale_sqrt(self):
     params = _ScatterParams(x=self.x,
                             y=self.y,
                             c=self.c,
                             cmap_scale='sqrt')
     assert params.cmap_scale == 'sqrt'
     assert isinstance(params.norm, matplotlib.colors.PowerNorm)
     assert params.norm.gamma == 0.5
Example #2
0
 def test_data_3d(self):
     params = _ScatterParams(x=self.x, y=self.y, z=self.z)
     np.testing.assert_equal(params._data, [self.x, self.y, self.z])
     np.testing.assert_equal(params.data, [
         self.x[params.plot_idx], self.y[params.plot_idx],
         self.z[params.plot_idx]
     ])
     assert params.subplot_kw == {'projection': '3d'}
Example #3
0
 def test_list_cmap(self):
     params = _ScatterParams(x=self.x,
                             y=self.y,
                             c=self.c,
                             cmap=['red', 'black'])
     assert params.list_cmap()
     np.testing.assert_equal(params.cmap([0, 255]),
                             [[1, 0, 0, 1], [0, 0, 0, 1]])
Example #4
0
 def test_continuous(self):
     params = _ScatterParams(x=self.x, y=self.y, c=self.c)
     assert not params.array_c()
     assert not params.constant_c()
     assert params.discrete is False
     assert params.legend is True
     assert params.cmap_scale == 'linear'
     assert params.cmap == 'inferno'
     params = _ScatterParams(x=self.x,
                             y=self.y,
                             discrete=False,
                             c=np.round(self.c % 1, 1))
     assert not params.array_c()
     assert not params.constant_c()
     assert params.discrete is False
     assert params.legend is True
     assert params.labels is None
     assert params.cmap_scale == 'linear'
     assert params.cmap == 'inferno'
Example #5
0
 def test_extend(self):
     params = _ScatterParams(x=self.x,
                             y=self.y,
                             c=self.c,
                             vmin=np.mean(self.c))
     assert params.extend == 'min'
     params = _ScatterParams(x=self.x,
                             y=self.y,
                             c=self.c,
                             vmax=np.mean(self.c))
     assert params.extend == 'max'
     params = _ScatterParams(x=self.x,
                             y=self.y,
                             c=self.c,
                             vmin=(np.min(self.c) + np.mean(self.c)) / 2,
                             vmax=(np.max(self.c) + np.mean(self.c)) / 2)
     assert params.extend == 'both'
     params = _ScatterParams(x=self.x, y=self.y, c=self.c)
     assert params.extend == 'neither'
Example #6
0
 def test_dict_cmap(self):
     params = _ScatterParams(x=self.x,
                             y=self.y,
                             c=np.where(self.c > 0, '+', '-'),
                             cmap={
                                 '+': 'k',
                                 '-': 'r'
                             })
     assert not params.list_cmap()
     if sys.version_info[1] > 5:
         np.testing.assert_equal(params.cmap.colors,
                                 [[0, 0, 0, 1], [1, 0, 0, 1]])
         assert np.all(params._labels == np.array(['+', '-']))
     else:
         try:
             np.testing.assert_equal(params.cmap.colors,
                                     [[0, 0, 0, 1], [1, 0, 0, 1]])
             assert np.all(params._labels == np.array(['+', '-']))
         except AssertionError:
             np.testing.assert_equal(params.cmap.colors,
                                     [[1, 0, 0, 1], [0, 0, 0, 1]])
             assert np.all(params._labels == np.array(['-', '+']))
     params = _ScatterParams(x=self.x,
                             y=self.y,
                             c=np.where(self.c > 0, '+', '-'),
                             cmap={
                                 '-': 'k',
                                 '+': 'r'
                             })
     if sys.version_info[1] > 5:
         np.testing.assert_equal(params.cmap.colors,
                                 [[0, 0, 0, 1], [1, 0, 0, 1]])
         assert np.all(params._labels == np.array(['-', '+']))
     else:
         try:
             np.testing.assert_equal(params.cmap.colors,
                                     [[0, 0, 0, 1], [1, 0, 0, 1]])
             assert np.all(params._labels == np.array(['-', '+']))
         except AssertionError:
             np.testing.assert_equal(params.cmap.colors,
                                     [[1, 0, 0, 1], [0, 0, 0, 1]])
             assert np.all(params._labels == np.array(['+', '-']))
Example #7
0
 def test_c_none(self):
     params = _ScatterParams(x=self.x, y=self.y)
     assert params.constant_c()
     assert not params.array_c()
     assert params.discrete is None
     assert params.legend is False
     assert params.vmin is None
     assert params.vmax is None
     assert params.cmap is None
     assert params.cmap_scale is None
     assert params.extend is None
Example #8
0
 def test_plot_idx_shuffle(self):
     params = _ScatterParams(x=self.x,
                             y=self.y,
                             z=self.z,
                             c=self.c,
                             s=np.abs(self.x))
     assert not np.all(params.plot_idx == np.arange(params.size))
     np.testing.assert_equal(params.x, self.x[params.plot_idx])
     np.testing.assert_equal(params.y, self.y[params.plot_idx])
     np.testing.assert_equal(params.z, self.z[params.plot_idx])
     np.testing.assert_equal(params.c, self.c[params.plot_idx])
     np.testing.assert_equal(params.s, np.abs(self.x)[params.plot_idx])
Example #9
0
 def test_plot_idx_no_shuffle(self):
     params = _ScatterParams(x=self.x,
                             y=self.y,
                             z=self.z,
                             c=self.c,
                             s=np.abs(self.x),
                             shuffle=False)
     np.testing.assert_equal(params.plot_idx, np.arange(params.size))
     np.testing.assert_equal(params.x, self.x)
     np.testing.assert_equal(params.y, self.y)
     np.testing.assert_equal(params.z, self.z)
     np.testing.assert_equal(params.c, self.c)
     np.testing.assert_equal(params.s, np.abs(self.x))
Example #10
0
 def test_vmin_default(self):
     params = _ScatterParams(x=self.x, y=self.y, c=self.c)
     assert params.vmin == np.min(self.c)
Example #11
0
 def test_s_default(self):
     params = _ScatterParams(x=self.x, y=self.y)
     assert params.s == 200 / np.sqrt(params.size)
Example #12
0
 def test_size(self):
     params = _ScatterParams(x=self.x, y=self.y)
     assert params.size == len(self.x)
Example #13
0
 def test_cmap_given(self):
     params = _ScatterParams(x=self.x, y=self.y, c=self.c, cmap='viridis')
     assert params.cmap == 'viridis'
     assert not params.list_cmap()
Example #14
0
 def test_s_given(self):
     params = _ScatterParams(x=self.x, y=self.y, s=3)
     assert params.s == 3
Example #15
0
 def test_c_discrete(self):
     c = np.where(self.c > 0, 'a', 'b')
     params = _ScatterParams(x=self.x, y=self.y, c=c)
     np.testing.assert_equal(params.c_discrete, np.where(c == 'a', 0, 1))
     np.testing.assert_equal(params.labels, ['a', 'b'])
Example #16
0
 def test_legend(self):
     params = _ScatterParams(x=self.x, y=self.y, c=self.c, legend=False)
     assert params.legend is False
     params = _ScatterParams(x=self.x, y=self.y, c=self.c, colorbar=False)
     assert params.legend is False
Example #17
0
 def test_vmax_default(self):
     params = _ScatterParams(x=self.x, y=self.y, c=self.c)
     assert params.vmax == np.max(self.c)
Example #18
0
 def test_vmax_given(self):
     params = _ScatterParams(x=self.x, y=self.y, c=self.c, vmax=0)
     assert params.vmax == 0
Example #19
0
 def test_data_2d(self):
     params = _ScatterParams(x=self.x, y=self.y)
     np.testing.assert_equal(params._data, [self.x, self.y])
     np.testing.assert_equal(
         params.data, [self.x[params.plot_idx], self.y[params.plot_idx]])
     assert params.subplot_kw == {}