Exemplo n.º 1
0
class TestPlot1D(PlotTestCase):

    def setUp(self):
        d = [0, 1.1, 0, 2]
        self.darray = DataArray(d, coords={'period': range(len(d))})

    def test_xlabel_is_index_name(self):
        self.darray.plot()
        self.assertEqual('period', plt.gca().get_xlabel())

    def test_no_label_name_on_y_axis(self):
        self.darray.plot()
        self.assertEqual('', plt.gca().get_ylabel())

    def test_ylabel_is_data_name(self):
        self.darray.name = 'temperature'
        self.darray.plot()
        self.assertEqual(self.darray.name, plt.gca().get_ylabel())

    def test_wrong_dims_raises_valueerror(self):
        twodims = DataArray(np.arange(10).reshape(2, 5))
        with self.assertRaises(ValueError):
            twodims.plot_line()

    def test_format_string(self):
        self.darray.plot_line('ro')

    def test_can_pass_in_axis(self):
        self.pass_in_axis(self.darray.plot_line)

    def test_nonnumeric_index_raises_typeerror(self):
        a = DataArray([1, 2, 3], {'letter': ['a', 'b', 'c']})
        with self.assertRaisesRegexp(TypeError, r'[Pp]lot'):
            a.plot_line()

    def test_primitive_returned(self):
        p = self.darray.plot_line()
        self.assertTrue(isinstance(p[0], mpl.lines.Line2D))

    def test_plot_nans(self):
        self.darray[1] = np.nan
        self.darray.plot_line()

    def test_x_ticks_are_rotated_for_time(self):
        time = pd.date_range('2000-01-01', '2000-01-10')
        a = DataArray(np.arange(len(time)), {'t': time})
        a.plot_line()
        rotation = plt.gca().get_xticklabels()[0].get_rotation()
        self.assertFalse(rotation == 0)
Exemplo n.º 2
0
 def test_wrong_dims_raises_valueerror(self):
     twodims = DataArray(np.arange(10).reshape(2, 5))
     with self.assertRaises(ValueError):
         twodims.plot_line()
Exemplo n.º 3
0
 def test_x_ticks_are_rotated_for_time(self):
     time = pd.date_range('2000-01-01', '2000-01-10')
     a = DataArray(np.arange(len(time)), {'t': time})
     a.plot_line()
     rotation = plt.gca().get_xticklabels()[0].get_rotation()
     self.assertFalse(rotation == 0)
Exemplo n.º 4
0
 def test_nonnumeric_index_raises_typeerror(self):
     a = DataArray([1, 2, 3], {'letter': ['a', 'b', 'c']})
     with self.assertRaisesRegexp(TypeError, r'[Pp]lot'):
         a.plot_line()