Exemplo n.º 1
0
    def test_figure_size(self):

        self.assertArrayEqual(self.g.fig.get_size_inches(), (10, 3))

        g = xplt.FacetGrid(self.darray, col='z', size=6)
        self.assertArrayEqual(g.fig.get_size_inches(), (19, 6))

        g = self.darray.plot.imshow(col='z', size=6)
        self.assertArrayEqual(g.fig.get_size_inches(), (19, 6))

        g = xplt.FacetGrid(self.darray, col='z', size=4, aspect=0.5)
        self.assertArrayEqual(g.fig.get_size_inches(), (7, 4))
Exemplo n.º 2
0
    def test_empty_cell(self):
        g = xplt.FacetGrid(self.darray, col='z', col_wrap=2)
        g.map_dataarray(xplt.imshow, 'x', 'y')

        bottomright = g.axes[-1, -1]
        self.assertFalse(bottomright.has_data())
        self.assertFalse(bottomright.get_visible())
Exemplo n.º 3
0
 def test_verbose_facetgrid(self):
     a = easy_array((10, 15, 3))
     d = DataArray(a, dims=['y', 'x', 'z'])
     g = xplt.FacetGrid(d, col='z')
     g.map_dataarray(self.plotfunc, 'x', 'y')
     for ax in g.axes.flat:
         self.assertTrue(ax.has_data())
Exemplo n.º 4
0
    def test_text_not_super_long(self):
        self.darray.coords['z'] = [100 * letter for letter in 'abc']
        g = xplt.FacetGrid(self.darray, col='z')
        g.map_dataarray(xplt.contour, 'x', 'y')
        alltxt = text_in_fig()
        maxlen = max(len(txt) for txt in alltxt)
        self.assertLess(maxlen, 50)

        t0 = g.axes[0, 0].get_title()
        self.assertTrue(t0.endswith('...'))
Exemplo n.º 5
0
    def test_figure_size(self):

        self.assertArrayEqual(self.g.fig.get_size_inches(), (10, 3))

        g = xplt.FacetGrid(self.darray, col='z', size=6)
        self.assertArrayEqual(g.fig.get_size_inches(), (19, 6))

        g = self.darray.plot.imshow(col='z', size=6)
        self.assertArrayEqual(g.fig.get_size_inches(), (19, 6))

        g = xplt.FacetGrid(self.darray, col='z', size=4, aspect=0.5)
        self.assertArrayEqual(g.fig.get_size_inches(), (7, 4))

        g = xplt.FacetGrid(self.darray, col='z', figsize=(9, 4))
        self.assertArrayEqual(g.fig.get_size_inches(), (9, 4))

        with self.assertRaisesRegexp(ValueError, "cannot provide both"):
            g = xplt.plot(self.darray, row=2, col='z', figsize=(6, 4), size=6)

        with self.assertRaisesRegexp(ValueError, "Can't use"):
            g = xplt.plot(self.darray, row=2, col='z', ax=plt.gca(), size=6)
Exemplo n.º 6
0
    def test_default_labels(self):
        g = xplt.FacetGrid(self.darray, col='col', row='row')
        self.assertEqual((2, 3), g.axes.shape)

        g.map_dataarray(xplt.imshow, 'x', 'y')

        # Rightmost column should be labeled
        for label, ax in zip(self.darray.coords['row'].values, g.axes[:, -1]):
            self.assertTrue(substring_in_axes(label, ax))

        # Top row should be labeled
        for label, ax in zip(self.darray.coords['col'].values, g.axes[0, :]):
            self.assertTrue(substring_in_axes(label, ax))
Exemplo n.º 7
0
    def test_map_dataset(self):
        g = xplt.FacetGrid(self.darray.to_dataset(name='foo'), col='z')
        g.map(plt.contourf, 'x', 'y', 'foo')

        alltxt = text_in_fig()
        for label in ['x', 'y']:
            self.assertIn(label, alltxt)
        # everything has a label
        self.assertNotIn('None', alltxt)

        # colorbar can't be inferred automatically
        self.assertNotIn('foo', alltxt)
        self.assertEqual(0, len(find_possible_colorbars()))

        g.add_colorbar(label='colors!')
        self.assertIn('colors!', text_in_fig())
        self.assertEqual(1, len(find_possible_colorbars()))
    def test_map_dataset(self):
        g = xplt.FacetGrid(self.darray.to_dataset(name='foo'), col='z')
        g.map(plt.contourf, 'x', 'y', 'foo')

        alltxt = text_in_fig()
        for label in ['x', 'y']:
            assert label in alltxt
        # everything has a label
        assert 'None' not in alltxt

        # colorbar can't be inferred automatically
        assert 'foo' not in alltxt
        assert 0 == len(find_possible_colorbars())

        g.add_colorbar(label='colors!')
        assert 'colors!' in text_in_fig()
        assert 1 == len(find_possible_colorbars())
Exemplo n.º 9
0
    def test_robust(self):
        z = np.zeros((20, 20, 2))
        darray = DataArray(z, dims=['y', 'x', 'z'])
        darray[:, :, 1] = 1
        darray[2, 0, 0] = -1000
        darray[3, 0, 0] = 1000
        g = xplt.FacetGrid(darray, col='z')
        g.map_dataarray(xplt.imshow, 'x', 'y', robust=True)

        # Color limits should be 0, 1
        # The largest number displayed in the figure should be less than 21
        numbers = set()
        alltxt = text_in_fig()
        for txt in alltxt:
            try:
                numbers.add(float(txt))
            except ValueError:
                pass
        largest = max(abs(x) for x in numbers)
        self.assertLess(largest, 21)
Exemplo n.º 10
0
 def test_nonunique_index_error(self):
     self.darray.coords['z'] = [0.1, 0.2, 0.2]
     with self.assertRaisesRegexp(ValueError, r'[Uu]nique'):
         xplt.FacetGrid(self.darray, col='z')
Exemplo n.º 11
0
 def test_float_index(self):
     self.darray.coords['z'] = [0.1, 0.2, 0.4]
     g = xplt.FacetGrid(self.darray, col='z')
     g.map_dataarray(xplt.imshow, 'x', 'y')
Exemplo n.º 12
0
 def test_norow_nocol_error(self):
     with self.assertRaisesRegexp(ValueError, r'[Rr]ow'):
         xplt.FacetGrid(self.darray)
Exemplo n.º 13
0
 def setUp(self):
     d = easy_array((10, 15, 3))
     self.darray = DataArray(d,
                             dims=['y', 'x', 'z'],
                             coords={'z': ['a', 'b', 'c']})
     self.g = xplt.FacetGrid(self.darray, col='z')
Exemplo n.º 14
0
 def test_norow_nocol_error(self):
     with raises_regex(ValueError, r'[Rr]ow'):
         xplt.FacetGrid(self.darray)