def test_ts_plot_format_coord(self): def check_format_of_first_point(ax, expected_string): first_line = ax.get_lines()[0] first_x = first_line.get_xdata()[0].ordinal first_y = first_line.get_ydata()[0] try: self.assertEqual(expected_string, ax.format_coord(first_x, first_y)) except (ValueError): raise nose.SkipTest("skipping test because issue forming " "test comparison GH7664") annual = Series(1, index=date_range('2014-01-01', periods=3, freq='A-DEC')) check_format_of_first_point(annual.plot(), 't = 2014 y = 1.000000') # note this is added to the annual plot already in existence, and # changes its freq field daily = Series(1, index=date_range('2014-01-01', periods=3, freq='D')) check_format_of_first_point(daily.plot(), 't = 2014-01-01 y = 1.000000') tm.close() # tsplot import matplotlib.pyplot as plt from pandas.tseries.plotting import tsplot tsplot(annual, plt.Axes.plot) check_format_of_first_point(plt.gca(), 't = 2014 y = 1.000000') tsplot(daily, plt.Axes.plot) check_format_of_first_point(plt.gca(), 't = 2014-01-01 y = 1.000000')
def test_ts_plot_format_coord(self): def check_format_of_first_point(ax, expected_string): first_line = ax.get_lines()[0] first_x = first_line.get_xdata()[0].ordinal first_y = first_line.get_ydata()[0] try: self.assertEqual(expected_string, ax.format_coord(first_x, first_y)) except (ValueError): pytest.skip("skipping test because issue forming " "test comparison GH7664") annual = Series(1, index=date_range('2014-01-01', periods=3, freq='A-DEC')) check_format_of_first_point(annual.plot(), 't = 2014 y = 1.000000') # note this is added to the annual plot already in existence, and # changes its freq field daily = Series(1, index=date_range('2014-01-01', periods=3, freq='D')) check_format_of_first_point(daily.plot(), 't = 2014-01-01 y = 1.000000') tm.close() # tsplot import matplotlib.pyplot as plt from pandas.tseries.plotting import tsplot tsplot(annual, plt.Axes.plot) check_format_of_first_point(plt.gca(), 't = 2014 y = 1.000000') tsplot(daily, plt.Axes.plot) check_format_of_first_point(plt.gca(), 't = 2014-01-01 y = 1.000000')
def test_from_weekly_resampling(self): idxh = date_range('1/1/1999', periods=52, freq='W') idxl = date_range('1/1/1999', periods=12, freq='M') high = Series(np.random.randn(len(idxh)), idxh) low = Series(np.random.randn(len(idxl)), idxl) low.plot() ax = high.plot() expected_h = idxh.to_period().asi8.astype(np.float64) expected_l = np.array([1514, 1519, 1523, 1527, 1531, 1536, 1540, 1544, 1549, 1553, 1558, 1562], dtype=np.float64) for l in ax.get_lines(): self.assertTrue(PeriodIndex(data=l.get_xdata()).freq, idxh.freq) xdata = l.get_xdata(orig=False) if len(xdata) == 12: # idxl lines self.assert_numpy_array_equal(xdata, expected_l) else: self.assert_numpy_array_equal(xdata, expected_h) tm.close() # tsplot from pandas.tseries.plotting import tsplot import matplotlib.pyplot as plt tsplot(low, plt.Axes.plot) lines = tsplot(high, plt.Axes.plot) for l in lines: self.assertTrue(PeriodIndex(data=l.get_xdata()).freq, idxh.freq) xdata = l.get_xdata(orig=False) if len(xdata) == 12: # idxl lines self.assert_numpy_array_equal(xdata, expected_l) else: self.assert_numpy_array_equal(xdata, expected_h)
def _make_ts_plot(self, data, **kwargs): from pandas.tseries.plotting import tsplot plotf = self._get_plot_function() if isinstance(data, Series): if self.subplots: # shouldn't even allow users to specify ax = self.axes[0] else: ax = self.ax label = com._stringify(self.label) tsplot(data, plotf, ax=ax, label=label, **kwargs) ax.grid(self.grid) else: for i, col in enumerate(data.columns): if self.subplots: ax = self.axes[i] else: ax = self.ax label = com._stringify(col) tsplot(data[col], plotf, ax=ax, label=label, **kwargs) ax.grid(self.grid) self.fig.subplots_adjust(wspace=0, hspace=0)
def test_ts_plot_format_coord(self): def check_format_of_first_point(ax, expected_string): first_line = ax.get_lines()[0] first_x = first_line.get_xdata()[0].ordinal first_y = first_line.get_ydata()[0] try: assert expected_string == ax.format_coord(first_x, first_y) except (ValueError): pytest.skip("skipping test because issue forming " "test comparison GH7664") annual = Series(1, index=date_range('2014-01-01', periods=3, freq='A-DEC')) _, ax = self.plt.subplots() annual.plot(ax=ax) check_format_of_first_point(ax, 't = 2014 y = 1.000000') # note this is added to the annual plot already in existence, and # changes its freq field daily = Series(1, index=date_range('2014-01-01', periods=3, freq='D')) daily.plot(ax=ax) check_format_of_first_point(ax, 't = 2014-01-01 y = 1.000000') tm.close() # tsplot _, ax = self.plt.subplots() from pandas.tseries.plotting import tsplot tsplot(annual, self.plt.Axes.plot, ax=ax) check_format_of_first_point(ax, 't = 2014 y = 1.000000') tsplot(daily, self.plt.Axes.plot, ax=ax) check_format_of_first_point(ax, 't = 2014-01-01 y = 1.000000')
def _make_ts_plot(self, data, **kwargs): from pandas.tseries.plotting import tsplot plotf = self._get_plot_function() if isinstance(data, Series): ax = self._get_ax(0) #self.axes[0] style = self.style or '' label = com._stringify(self.label) tsplot(data, plotf, ax=ax, label=label, style=self.style, **kwargs) ax.grid(self.grid) else: for i, col in enumerate(data.columns): ax, style = self._get_ax_and_style(i, col) tsplot(data[col], plotf, ax=ax, label=col, style=style, **kwargs) ax.grid(self.grid)
def test_to_weekly_resampling(self): idxh = date_range('1/1/1999', periods=52, freq='W') idxl = date_range('1/1/1999', periods=12, freq='M') high = Series(np.random.randn(len(idxh)), idxh) low = Series(np.random.randn(len(idxl)), idxl) high.plot() ax = low.plot() for l in ax.get_lines(): self.assertEqual(PeriodIndex(data=l.get_xdata()).freq, idxh.freq) # tsplot from pandas.tseries.plotting import tsplot import matplotlib.pyplot as plt tsplot(high, plt.Axes.plot) lines = tsplot(low, plt.Axes.plot) for l in lines: self.assertTrue(PeriodIndex(data=l.get_xdata()).freq, idxh.freq)
def test_tsplot(self): from pandas.tseries.plotting import tsplot import matplotlib.pyplot as plt ax = plt.gca() ts = tm.makeTimeSeries() plot_ax = tsplot(ts, plt.Axes.plot) self.assert_(plot_ax == ax) f = lambda *args, **kwds: tsplot(s, plt.Axes.plot, *args, **kwds) for s in self.period_ser: _check_plot_works(f, s.index.freq, ax=ax, series=s) for s in self.datetime_ser: _check_plot_works(f, s.index.freq.rule_code, ax=ax, series=s) plt.close('all') ax = ts.plot(style='k') self.assert_((0., 0., 0.) == ax.get_lines()[0].get_color())
def test_to_weekly_resampling(self): idxh = date_range('1/1/1999', periods=52, freq='W') idxl = date_range('1/1/1999', periods=12, freq='M') high = Series(np.random.randn(len(idxh)), idxh) low = Series(np.random.randn(len(idxl)), idxl) _, ax = self.plt.subplots() high.plot(ax=ax) low.plot(ax=ax) for l in ax.get_lines(): assert PeriodIndex(data=l.get_xdata()).freq == idxh.freq # tsplot from pandas.tseries.plotting import tsplot _, ax = self.plt.subplots() tsplot(high, self.plt.Axes.plot, ax=ax) lines = tsplot(low, self.plt.Axes.plot, ax=ax) for l in lines: assert PeriodIndex(data=l.get_xdata()).freq == idxh.freq
def test_tsplot(self): from pandas.tseries.plotting import tsplot import matplotlib.pyplot as plt ax = plt.gca() f = lambda *args, **kwds: tsplot(s, plt.Axes.plot, *args, **kwds) for s in self.period_ser: _check_plot_works(f, s.index.freq, ax=ax, series=s) for s in self.datetime_ser: _check_plot_works(f, s.index.freq.rule_code, ax=ax, series=s)
def test_tsplot(self): from pandas.tseries.plotting import tsplot import matplotlib.pyplot as plt plt.close('all') ax = plt.gca() ts = tm.makeTimeSeries() tsplot(ts, plt.Axes.plot) f = lambda *args, **kwds: tsplot(s, plt.Axes.plot, *args, **kwds) plt.close('all') for s in self.period_ser: _check_plot_works(f, s.index.freq, ax=ax, series=s) plt.close('all') for s in self.datetime_ser: _check_plot_works(f, s.index.freq.rule_code, ax=ax, series=s) plt.close('all') plt.close('all') ax = ts.plot(style='k') self.assert_((0., 0., 0.) == ax.get_lines()[0].get_color())
def _make_ts_plot(self, data, **kwargs): from pandas.tseries.plotting import tsplot plotf = self._get_plot_function() if isinstance(data, Series): if self.subplots: # shouldn't even allow users to specify ax = self.axes[0] else: ax = self.ax label = com._stringify(self.label) tsplot(data, plotf, ax=ax, label=label, style=self.style, **kwargs) ax.grid(self.grid) else: for i, col in enumerate(data.columns): if self.subplots: ax = self.axes[i] else: ax = self.ax label = com._stringify(col) tsplot(data[col], plotf, ax=ax, label=label, **kwargs) ax.grid(self.grid)
def test_tsplot(self): from pandas.tseries.plotting import tsplot import matplotlib.pyplot as plt ax = plt.gca() ts = tm.makeTimeSeries() f = lambda *args, **kwds: tsplot(s, plt.Axes.plot, *args, **kwds) for s in self.period_ser: _check_plot_works(f, s.index.freq, ax=ax, series=s) for s in self.datetime_ser: _check_plot_works(f, s.index.freq.rule_code, ax=ax, series=s) for s in self.period_ser: _check_plot_works(s.plot, ax=ax) for s in self.datetime_ser: _check_plot_works(s.plot, ax=ax) ax = ts.plot(style='k') color = (0., 0., 0., 1) if self.mpl_ge_2_0_0 else (0., 0., 0.) self.assertEqual(color, ax.get_lines()[0].get_color())
def test_tsplot(self): from pandas.tseries.plotting import tsplot _, ax = self.plt.subplots() ts = tm.makeTimeSeries() f = lambda *args, **kwds: tsplot(s, self.plt.Axes.plot, *args, **kwds) for s in self.period_ser: _check_plot_works(f, s.index.freq, ax=ax, series=s) for s in self.datetime_ser: _check_plot_works(f, s.index.freq.rule_code, ax=ax, series=s) for s in self.period_ser: _check_plot_works(s.plot, ax=ax) for s in self.datetime_ser: _check_plot_works(s.plot, ax=ax) _, ax = self.plt.subplots() ts.plot(style='k', ax=ax) color = (0., 0., 0., 1) if self.mpl_ge_2_0_0 else (0., 0., 0.) assert color == ax.get_lines()[0].get_color()