本文整理汇总了Python中pandas.tseries.plotting.tsplot方法的典型用法代码示例。如果您正苦于以下问题:Python plotting.tsplot方法的具体用法?Python plotting.tsplot怎么用?Python plotting.tsplot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.tseries.plotting
的用法示例。
在下文中一共展示了plotting.tsplot方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_to_weekly_resampling
# 需要导入模块: from pandas.tseries import plotting [as 别名]
# 或者: from pandas.tseries.plotting import tsplot [as 别名]
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
_, ax = self.plt.subplots()
from pandas.tseries.plotting import tsplot
with tm.assert_produces_warning(FutureWarning):
tsplot(high, self.plt.Axes.plot, ax=ax)
with tm.assert_produces_warning(FutureWarning):
lines = tsplot(low, self.plt.Axes.plot, ax=ax)
for l in lines:
assert PeriodIndex(data=l.get_xdata()).freq == idxh.freq
示例2: test_tsplot
# 需要导入模块: from pandas.tseries import plotting [as 别名]
# 或者: from pandas.tseries.plotting import tsplot [as 别名]
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)
ax = ts.plot(style='k')
self.assertEqual((0., 0., 0.), ax.get_lines()[0].get_color())
示例3: test_tsplot
# 需要导入模块: from pandas.tseries import plotting [as 别名]
# 或者: from pandas.tseries.plotting import tsplot [as 别名]
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()
示例4: test_to_weekly_resampling
# 需要导入模块: from pandas.tseries import plotting [as 别名]
# 或者: from pandas.tseries.plotting import tsplot [as 别名]
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
示例5: test_tsplot_deprecated
# 需要导入模块: from pandas.tseries import plotting [as 别名]
# 或者: from pandas.tseries.plotting import tsplot [as 别名]
def test_tsplot_deprecated(self):
from pandas.tseries.plotting import tsplot
_, ax = self.plt.subplots()
ts = tm.makeTimeSeries()
with tm.assert_produces_warning(FutureWarning):
tsplot(ts, self.plt.Axes.plot, ax=ax)
示例6: test_tsplot
# 需要导入模块: from pandas.tseries import plotting [as 别名]
# 或者: from pandas.tseries.plotting import tsplot [as 别名]
def test_tsplot(self):
from pandas.tseries.plotting import tsplot
_, ax = self.plt.subplots()
ts = tm.makeTimeSeries()
def f(*args, **kwds):
with tm.assert_produces_warning(FutureWarning):
return 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)
assert color == ax.get_lines()[0].get_color()
示例7: test_ts_plot_format_coord
# 需要导入模块: from pandas.tseries import plotting [as 别名]
# 或者: from pandas.tseries.plotting import tsplot [as 别名]
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
from pandas.tseries.plotting import tsplot
_, ax = self.plt.subplots()
with tm.assert_produces_warning(FutureWarning):
tsplot(annual, self.plt.Axes.plot, ax=ax)
check_format_of_first_point(ax, 't = 2014 y = 1.000000')
with tm.assert_produces_warning(FutureWarning):
tsplot(daily, self.plt.Axes.plot, ax=ax)
check_format_of_first_point(ax, 't = 2014-01-01 y = 1.000000')
示例8: test_from_weekly_resampling
# 需要导入模块: from pandas.tseries import plotting [as 别名]
# 或者: from pandas.tseries.plotting import tsplot [as 别名]
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)
_, ax = self.plt.subplots()
low.plot(ax=ax)
high.plot(ax=ax)
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():
assert PeriodIndex(data=l.get_xdata()).freq == idxh.freq
xdata = l.get_xdata(orig=False)
if len(xdata) == 12: # idxl lines
tm.assert_numpy_array_equal(xdata, expected_l)
else:
tm.assert_numpy_array_equal(xdata, expected_h)
tm.close()
_, ax = self.plt.subplots()
from pandas.tseries.plotting import tsplot
with tm.assert_produces_warning(FutureWarning):
tsplot(low, self.plt.Axes.plot, ax=ax)
with tm.assert_produces_warning(FutureWarning):
lines = tsplot(high, self.plt.Axes.plot, ax=ax)
for l in lines:
assert PeriodIndex(data=l.get_xdata()).freq == idxh.freq
xdata = l.get_xdata(orig=False)
if len(xdata) == 12: # idxl lines
tm.assert_numpy_array_equal(xdata, expected_l)
else:
tm.assert_numpy_array_equal(xdata, expected_h)
示例9: test_tsplot
# 需要导入模块: from pandas.tseries import plotting [as 别名]
# 或者: from pandas.tseries.plotting import tsplot [as 别名]
def test_tsplot(self):
from pandas.tseries.plotting import tsplot
_, ax = self.plt.subplots()
ts = tm.makeTimeSeries()
def f(*args, **kwds):
with tm.assert_produces_warning(FutureWarning):
return 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()
示例10: _use_dynamic_x
# 需要导入模块: from pandas.tseries import plotting [as 别名]
# 或者: from pandas.tseries.plotting import tsplot [as 别名]
def _use_dynamic_x(self):
freq = self._index_freq()
ax = self._get_ax(0)
ax_freq = getattr(ax, 'freq', None)
if freq is None: # convert irregular if axes has freq info
freq = ax_freq
else: # do not use tsplot if irregular was plotted first
if (ax_freq is None) and (len(ax.get_lines()) > 0):
return False
return (freq is not None) and self._is_dynamic_freq(freq)
示例11: _make_ts_plot
# 需要导入模块: from pandas.tseries import plotting [as 别名]
# 或者: from pandas.tseries.plotting import tsplot [as 别名]
def _make_ts_plot(self, data, **kwargs):
from pandas.tseries.plotting import tsplot
kwargs = kwargs.copy()
colors = self._get_colors()
plotf = self._get_plot_function()
lines = []
labels = []
def _plot(data, col_num, ax, label, style, **kwds):
newlines = tsplot(data, plotf, ax=ax, label=label,
style=style, **kwds)
ax.grid(self.grid)
lines.append(newlines[0])
if self.mark_right:
labels.append(self._get_marked_label(label, col_num))
else:
labels.append(label)
if isinstance(data, Series):
ax = self._get_ax(0) # self.axes[0]
style = self.style or ''
label = com.pprint_thing(self.label)
kwds = kwargs.copy()
self._maybe_add_color(colors, kwds, style, 0)
_plot(data, 0, ax, label, self.style, **kwds)
else:
for i, col in enumerate(data.columns):
label = com.pprint_thing(col)
ax = self._get_ax(i)
style = self._get_style(i, col)
kwds = kwargs.copy()
self._maybe_add_color(colors, kwds, style, i)
_plot(data[col], i, ax, label, style, **kwds)
self._make_legend(lines, labels)
示例12: _maybe_convert_index
# 需要导入模块: from pandas.tseries import plotting [as 别名]
# 或者: from pandas.tseries.plotting import tsplot [as 别名]
def _maybe_convert_index(self, data):
# tsplot converts automatically, but don't want to convert index
# over and over for DataFrames
from pandas.core.frame import DataFrame
if (isinstance(data.index, DatetimeIndex) and
isinstance(data, DataFrame)):
freq = getattr(data.index, 'freq', None)
if freq is None:
freq = getattr(data.index, 'inferred_freq', None)
if isinstance(freq, DateOffset):
freq = freq.rule_code
freq = get_base_alias(freq)
freq = get_period_alias(freq)
if freq is None:
ax = self._get_ax(0)
freq = getattr(ax, 'freq', None)
if freq is None:
raise ValueError('Could not get frequency alias for plotting')
data = DataFrame(data.values,
index=data.index.to_period(freq=freq),
columns=data.columns)
return data
示例13: test_ts_plot_format_coord
# 需要导入模块: from pandas.tseries import plotting [as 别名]
# 或者: from pandas.tseries.plotting import tsplot [as 别名]
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')
示例14: test_from_weekly_resampling
# 需要导入模块: from pandas.tseries import plotting [as 别名]
# 或者: from pandas.tseries.plotting import tsplot [as 别名]
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)
_, ax = self.plt.subplots()
low.plot(ax=ax)
high.plot(ax=ax)
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():
assert PeriodIndex(data=l.get_xdata()).freq == idxh.freq
xdata = l.get_xdata(orig=False)
if len(xdata) == 12: # idxl lines
tm.assert_numpy_array_equal(xdata, expected_l)
else:
tm.assert_numpy_array_equal(xdata, expected_h)
tm.close()
# tsplot
from pandas.tseries.plotting import tsplot
_, ax = self.plt.subplots()
tsplot(low, self.plt.Axes.plot, ax=ax)
lines = tsplot(high, self.plt.Axes.plot, ax=ax)
for l in lines:
assert PeriodIndex(data=l.get_xdata()).freq == idxh.freq
xdata = l.get_xdata(orig=False)
if len(xdata) == 12: # idxl lines
tm.assert_numpy_array_equal(xdata, expected_l)
else:
tm.assert_numpy_array_equal(xdata, expected_h)