本文整理汇总了Python中matplotlib.dates.AutoDateFormatter方法的典型用法代码示例。如果您正苦于以下问题:Python dates.AutoDateFormatter方法的具体用法?Python dates.AutoDateFormatter怎么用?Python dates.AutoDateFormatter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.dates
的用法示例。
在下文中一共展示了dates.AutoDateFormatter方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: axisinfo
# 需要导入模块: from matplotlib import dates [as 别名]
# 或者: from matplotlib.dates import AutoDateFormatter [as 别名]
def axisinfo( unit, axis ):
""": Returns information on how to handle an axis that has Epoch data.
= INPUT VARIABLES
- unit The units to use for a axis with Epoch data.
= RETURN VALUE
- Returns a matplotlib AxisInfo data structure that contains
minor/major formatters, major/minor locators, and default
label information.
"""
majloc = date_ticker.AutoDateLocator()
majfmt = date_ticker.AutoDateFormatter( majloc )
return units.AxisInfo( majloc = majloc,
majfmt = majfmt,
label = unit )
#------------------------------------------------------------------------
示例2: test_RRuleLocator
# 需要导入模块: from matplotlib import dates [as 别名]
# 或者: from matplotlib.dates import AutoDateFormatter [as 别名]
def test_RRuleLocator():
import matplotlib.testing.jpl_units as units
units.register()
# This will cause the RRuleLocator to go out of bounds when it tries
# to add padding to the limits, so we make sure it caps at the correct
# boundary values.
t0 = datetime.datetime(1000, 1, 1)
tf = datetime.datetime(6000, 1, 1)
fig = plt.figure()
ax = plt.subplot(111)
ax.set_autoscale_on(True)
ax.plot([t0, tf], [0.0, 1.0], marker='o')
rrule = mdates.rrulewrapper(dateutil.rrule.YEARLY, interval=500)
locator = mdates.RRuleLocator(rrule)
ax.xaxis.set_major_locator(locator)
ax.xaxis.set_major_formatter(mdates.AutoDateFormatter(locator))
ax.autoscale_view()
fig.autofmt_xdate()
示例3: test_DateFormatter
# 需要导入模块: from matplotlib import dates [as 别名]
# 或者: from matplotlib.dates import AutoDateFormatter [as 别名]
def test_DateFormatter():
import matplotlib.testing.jpl_units as units
units.register()
# Lets make sure that DateFormatter will allow us to have tick marks
# at intervals of fractional seconds.
t0 = datetime.datetime(2001, 1, 1, 0, 0, 0)
tf = datetime.datetime(2001, 1, 1, 0, 0, 1)
fig = plt.figure()
ax = plt.subplot(111)
ax.set_autoscale_on(True)
ax.plot([t0, tf], [0.0, 1.0], marker='o')
# rrule = mpldates.rrulewrapper( dateutil.rrule.YEARLY, interval=500 )
# locator = mpldates.RRuleLocator( rrule )
# ax.xaxis.set_major_locator( locator )
# ax.xaxis.set_major_formatter( mpldates.AutoDateFormatter(locator) )
ax.autoscale_view()
fig.autofmt_xdate()
示例4: axisinfo
# 需要导入模块: from matplotlib import dates [as 别名]
# 或者: from matplotlib.dates import AutoDateFormatter [as 别名]
def axisinfo(unit, axis):
""": Returns information on how to handle an axis that has Epoch data.
= INPUT VARIABLES
- unit The units to use for a axis with Epoch data.
= RETURN VALUE
- Returns a matplotlib AxisInfo data structure that contains
minor/major formatters, major/minor locators, and default
label information.
"""
majloc = date_ticker.AutoDateLocator()
majfmt = date_ticker.AutoDateFormatter(majloc)
return units.AxisInfo(majloc=majloc, majfmt=majfmt, label=unit)
# -----------------------------------------------------------------------
示例5: axisinfo
# 需要导入模块: from matplotlib import dates [as 别名]
# 或者: from matplotlib.dates import AutoDateFormatter [as 别名]
def axisinfo(unit, axis):
""": Returns information on how to handle an axis that has Epoch data.
= INPUT VARIABLES
- unit The units to use for a axis with Epoch data.
= RETURN VALUE
- Returns a matplotlib AxisInfo data structure that contains
minor/major formatters, major/minor locators, and default
label information.
"""
majloc = date_ticker.AutoDateLocator()
majfmt = date_ticker.AutoDateFormatter(majloc)
return units.AxisInfo(majloc=majloc, majfmt=majfmt, label=unit)
示例6: __init__
# 需要导入模块: from matplotlib import dates [as 别名]
# 或者: from matplotlib.dates import AutoDateFormatter [as 别名]
def __init__(self, locator, tz=None, defaultfmt='%Y-%m-%d'):
dates.AutoDateFormatter.__init__(self, locator, tz, defaultfmt)
# matplotlib.dates._UTC has no _utcoffset called by pandas
if self._tz is dates.UTC:
self._tz._utcoffset = self._tz.utcoffset(None)
示例7: _load_graph
# 需要导入模块: from matplotlib import dates [as 别名]
# 或者: from matplotlib.dates import AutoDateFormatter [as 别名]
def _load_graph(self, info_cache):
# define the necessary colors
color_bg = self.get_color('bg', ColorHexCode.WHITE)
color_fg = self.get_color('fg', ColorHexCode.BLACK)
color_line_bg = self.get_color('line_bg', ColorHexCode.WHITE)
color_line_fg = self.get_color('line_fg', ColorHexCode.BLACK)
visits = info_cache['visits']['edges']
first_seen_timestamps = [utilities.datetime_utc_to_local(visit['node']['firstSeen']) for visit in visits]
ax = self.axes[0]
ax.tick_params(
axis='both',
which='both',
colors=color_fg,
top=False,
bottom=False
)
ax.set_facecolor(color_line_bg)
ax.set_ylabel('Number of Visits', color=self.get_color('fg', ColorHexCode.WHITE), size=10)
self._ax_hide_ticks(ax)
self._ax_set_spine_color(ax, color_bg)
if not len(first_seen_timestamps):
ax.set_yticks((0,))
ax.set_xticks((0,))
return
first_seen_timestamps.sort()
ax.plot_date(
first_seen_timestamps,
range(1, len(first_seen_timestamps) + 1),
'-',
color=color_line_fg,
linewidth=6
)
self.figure.autofmt_xdate()
self.figure.subplots_adjust(top=0.85, right=0.95, bottom=0.25, left=0.1)
locator = dates.AutoDateLocator()
ax.xaxis.set_major_locator(locator)
ax.xaxis.set_major_formatter(dates.AutoDateFormatter(locator))
return
示例8: __init__
# 需要导入模块: from matplotlib import dates [as 别名]
# 或者: from matplotlib.dates import AutoDateFormatter [as 别名]
def __init__(self, locator, tz=None, defaultfmt='%Y-%m-%d'):
dates.AutoDateFormatter.__init__(self, locator, tz, defaultfmt)
# matplotlib.dates._UTC has no _utcoffset called by pandas
if self._tz is dates.UTC:
self._tz._utcoffset = self._tz.utcoffset(None)
# For mpl > 2.0 the format strings are controlled via rcparams
# so do not mess with them. For mpl < 2.0 change the second
# break point and add a musec break point
if _mpl_le_2_0_0():
self.scaled[1. / SEC_PER_DAY] = '%H:%M:%S'
self.scaled[1. / MUSEC_PER_DAY] = '%H:%M:%S.%f'
示例9: __init__
# 需要导入模块: from matplotlib import dates [as 别名]
# 或者: from matplotlib.dates import AutoDateFormatter [as 别名]
def __init__(self, locator, tz=None, defaultfmt='%Y-%m-%d'):
dates.AutoDateFormatter.__init__(self, locator, tz, defaultfmt)
# matplotlib.dates._UTC has no _utcoffset called by pandas
if self._tz is dates.UTC:
self._tz._utcoffset = self._tz.utcoffset(None)
self.scaled = {
365.0: '%Y',
30.: '%b %Y',
1.0: '%b %d %Y',
1. / 24.: '%H:%M:%S',
1. / 24. / 3600. / 1000.: '%H:%M:%S.%f'
}
示例10: test_date_formatter_callable
# 需要导入模块: from matplotlib import dates [as 别名]
# 或者: from matplotlib.dates import AutoDateFormatter [as 别名]
def test_date_formatter_callable():
scale = -11
locator = mock.Mock(_get_unit=mock.Mock(return_value=scale))
callable_formatting_function = (lambda dates, _:
[dt.strftime('%d-%m//%Y') for dt in dates])
formatter = mdates.AutoDateFormatter(locator)
formatter.scaled[-10] = callable_formatting_function
assert_equal(formatter([datetime.datetime(2014, 12, 25)]),
['25-12//2014'])
示例11: test_date_formatter_callable
# 需要导入模块: from matplotlib import dates [as 别名]
# 或者: from matplotlib.dates import AutoDateFormatter [as 别名]
def test_date_formatter_callable():
scale = -11
locator = Mock(_get_unit=Mock(return_value=scale))
callable_formatting_function = (lambda dates, _:
[dt.strftime('%d-%m//%Y') for dt in dates])
formatter = mdates.AutoDateFormatter(locator)
formatter.scaled[-10] = callable_formatting_function
assert formatter([datetime.datetime(2014, 12, 25)]) == ['25-12//2014']
示例12: _make_plot
# 需要导入模块: from matplotlib import dates [as 别名]
# 或者: from matplotlib.dates import AutoDateFormatter [as 别名]
def _make_plot(self):
try:
from pandas.plotting._timeseries import (_decorate_axes,
format_dateaxis)
except ImportError:
from pandas.tseries.plotting import _decorate_axes, format_dateaxis
plotf = self._get_plot_function()
ax = self._get_ax(0)
data = self.data
data.index.name = 'Date'
data = data.to_period(freq=self.freq)
index = data.index
data = data.reset_index(level=0)
if self._is_ts_plot():
data['Date'] = data['Date'].apply(lambda x: x.ordinal)
_decorate_axes(ax, self.freq, self.kwds)
candles = plotf(data, ax, **self.kwds)
format_dateaxis(ax, self.freq, index)
else:
from matplotlib.dates import date2num, AutoDateFormatter, AutoDateLocator
data['Date'] = data['Date'].apply(lambda x: date2num(x.to_timestamp()))
candles = plotf(data, ax, **self.kwds)
locator = AutoDateLocator()
ax.xaxis.set_major_locator(locator)
ax.xaxis.set_major_formatter(AutoDateFormatter(locator))
return candles