本文整理匯總了Python中matplotlib.ticker.FixedLocator方法的典型用法代碼示例。如果您正苦於以下問題:Python ticker.FixedLocator方法的具體用法?Python ticker.FixedLocator怎麽用?Python ticker.FixedLocator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類matplotlib.ticker
的用法示例。
在下文中一共展示了ticker.FixedLocator方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: set_ticks
# 需要導入模塊: from matplotlib import ticker [as 別名]
# 或者: from matplotlib.ticker import FixedLocator [as 別名]
def set_ticks(self, ticks, minor=False):
"""
Set the locations of the tick marks from sequence ticks
ACCEPTS: sequence of floats
"""
### XXX if the user changes units, the information will be lost here
ticks = self.convert_units(ticks)
if len(ticks) > 1:
xleft, xright = self.get_view_interval()
if xright > xleft:
self.set_view_interval(min(ticks), max(ticks))
else:
self.set_view_interval(max(ticks), min(ticks))
if minor:
self.set_minor_locator(mticker.FixedLocator(ticks))
return self.get_minor_ticks(len(ticks))
else:
self.set_major_locator(mticker.FixedLocator(ticks))
return self.get_major_ticks(len(ticks))
示例2: __init__
# 需要導入模塊: from matplotlib import ticker [as 別名]
# 或者: from matplotlib.ticker import FixedLocator [as 別名]
def __init__(self, ax, mappable, **kw):
mappable.autoscale_None() # Ensure mappable.norm.vmin, vmax
# are set when colorbar is called,
# even if mappable.draw has not yet
# been called. This will not change
# vmin, vmax if they are already set.
self.mappable = mappable
kw['cmap'] = mappable.cmap
kw['norm'] = mappable.norm
kw['alpha'] = mappable.get_alpha()
if isinstance(mappable, contour.ContourSet):
CS = mappable
kw['boundaries'] = CS._levels
kw['values'] = CS.cvalues
kw['extend'] = CS.extend
#kw['ticks'] = CS._levels
kw.setdefault('ticks', ticker.FixedLocator(CS.levels, nbins=10))
kw['filled'] = CS.filled
ColorbarBase.__init__(self, ax, **kw)
if not CS.filled:
self.add_lines(CS)
else:
ColorbarBase.__init__(self, ax, **kw)
示例3: _select_locator
# 需要導入模塊: from matplotlib import ticker [as 別名]
# 或者: from matplotlib.ticker import FixedLocator [as 別名]
def _select_locator(self, formatter):
'''
select a suitable locator
'''
if self.boundaries is None:
if isinstance(self.norm, colors.NoNorm):
nv = len(self._values)
base = 1 + int(nv/10)
locator = ticker.IndexLocator(base=base, offset=0)
elif isinstance(self.norm, colors.BoundaryNorm):
b = self.norm.boundaries
locator = ticker.FixedLocator(b, nbins=10)
elif isinstance(self.norm, colors.LogNorm):
locator = ticker.LogLocator()
else:
locator = ticker.MaxNLocator(nbins=5)
else:
b = self._boundaries[self._inside]
locator = ticker.FixedLocator(b) #, nbins=10)
self.cbar_axis.set_major_locator(locator)
示例4: set_ticks
# 需要導入模塊: from matplotlib import ticker [as 別名]
# 或者: from matplotlib.ticker import FixedLocator [as 別名]
def set_ticks(self, ticks, update_ticks=True):
"""
Set tick locations.
Parameters
----------
ticks : {None, sequence, :class:`~matplotlib.ticker.Locator` instance}
If None, a default Locator will be used.
update_ticks : {True, False}, optional
If True, tick locations are updated immediately. If False,
use :meth:`update_ticks` to manually update the ticks.
"""
if np.iterable(ticks):
self.locator = ticker.FixedLocator(ticks, nbins=len(ticks))
else:
self.locator = ticks
if update_ticks:
self.update_ticks()
self.stale = True
示例5: set_ticks
# 需要導入模塊: from matplotlib import ticker [as 別名]
# 或者: from matplotlib.ticker import FixedLocator [as 別名]
def set_ticks(self, ticks, minor=False):
"""
Set the locations of the tick marks from sequence ticks
Parameters
----------
ticks : sequence of floats
minor : bool
"""
# XXX if the user changes units, the information will be lost here
ticks = self.convert_units(ticks)
if len(ticks) > 1:
xleft, xright = self.get_view_interval()
if xright > xleft:
self.set_view_interval(min(ticks), max(ticks))
else:
self.set_view_interval(max(ticks), min(ticks))
if minor:
self.set_minor_locator(mticker.FixedLocator(ticks))
return self.get_minor_ticks(len(ticks))
else:
self.set_major_locator(mticker.FixedLocator(ticks))
return self.get_major_ticks(len(ticks))
示例6: set_ticks
# 需要導入模塊: from matplotlib import ticker [as 別名]
# 或者: from matplotlib.ticker import FixedLocator [as 別名]
def set_ticks(self, ticks, update_ticks=True):
"""
Set tick locations.
Parameters
----------
ticks : {None, sequence, :class:`~matplotlib.ticker.Locator` instance}
If None, a default Locator will be used.
update_ticks : {True, False}, optional
If True, tick locations are updated immediately. If False,
use :meth:`update_ticks` to manually update the ticks.
"""
if cbook.iterable(ticks):
self.locator = ticker.FixedLocator(ticks, nbins=len(ticks))
else:
self.locator = ticks
if update_ticks:
self.update_ticks()
self.stale = True
示例7: set_ticks
# 需要導入模塊: from matplotlib import ticker [as 別名]
# 或者: from matplotlib.ticker import FixedLocator [as 別名]
def set_ticks(self, ticks, minor=False):
"""
Set the locations of the tick marks from sequence ticks
ACCEPTS: sequence of floats
"""
# XXX if the user changes units, the information will be lost here
ticks = self.convert_units(ticks)
if len(ticks) > 1:
xleft, xright = self.get_view_interval()
if xright > xleft:
self.set_view_interval(min(ticks), max(ticks))
else:
self.set_view_interval(max(ticks), min(ticks))
if minor:
self.set_minor_locator(mticker.FixedLocator(ticks))
return self.get_minor_ticks(len(ticks))
else:
self.set_major_locator(mticker.FixedLocator(ticks))
return self.get_major_ticks(len(ticks))
示例8: set_default_locators_and_formatters
# 需要導入模塊: from matplotlib import ticker [as 別名]
# 或者: from matplotlib.ticker import FixedLocator [as 別名]
def set_default_locators_and_formatters(self, axis):
"""
Override to set up the locators and formatters to use with the
scale. This is only required if the scale requires custom
locators and formatters. Writing custom locators and
formatters is rather outside the scope of this example, but
there are many helpful examples in ``ticker.py``.
In our case, the Mercator example uses a fixed locator from
-90 to 90 degrees and a custom formatter class to put convert
the radians to degrees and put a degree symbol after the
value::
"""
class DegreeFormatter(Formatter):
def __call__(self, x, pos=None):
return "%d\N{DEGREE SIGN}" % np.degrees(x)
axis.set_major_locator(FixedLocator(
np.radians(np.arange(-90, 90, 10))))
axis.set_major_formatter(DegreeFormatter())
axis.set_minor_formatter(DegreeFormatter())
示例9: __init__
# 需要導入模塊: from matplotlib import ticker [as 別名]
# 或者: from matplotlib.ticker import FixedLocator [as 別名]
def __init__(self, ax, mappable, **kw):
# Ensure mappable.norm.vmin, vmax are set when colorbar is called, even
# if mappable.draw has not yet been called. This will not change vmin,
# vmax if they are already set.
mappable.autoscale_None()
self.mappable = mappable
kw['cmap'] = mappable.cmap
kw['norm'] = mappable.norm
kw['alpha'] = mappable.get_alpha()
if isinstance(mappable, contour.ContourSet):
CS = mappable
kw['boundaries'] = CS._levels
kw['values'] = CS.cvalues
kw['extend'] = CS.extend
#kw['ticks'] = CS._levels
kw.setdefault('ticks', ticker.FixedLocator(CS.levels, nbins=10))
kw['filled'] = CS.filled
ColorbarBase.__init__(self, ax, **kw)
if not CS.filled:
self.add_lines(CS)
else:
ColorbarBase.__init__(self, ax, **kw)
示例10: set_ticks
# 需要導入模塊: from matplotlib import ticker [as 別名]
# 或者: from matplotlib.ticker import FixedLocator [as 別名]
def set_ticks(self, ticks, update_ticks=True):
"""
set tick locations. Tick locations are updated immediately unless
update_ticks is *False*. To manually update the ticks, call
*update_ticks* method explicitly.
"""
if cbook.iterable(ticks):
self.locator = ticker.FixedLocator(ticks, nbins=len(ticks))
else:
self.locator = ticks
if update_ticks:
self.update_ticks()
示例11: set_ticklabels
# 需要導入模塊: from matplotlib import ticker [as 別名]
# 或者: from matplotlib.ticker import FixedLocator [as 別名]
def set_ticklabels(self, ticklabels, update_ticks=True):
"""
set tick labels. Tick labels are updated immediately unless
update_ticks is *False*. To manually update the ticks, call
*update_ticks* method explicitly.
"""
if isinstance(self.locator, ticker.FixedLocator):
self.formatter = ticker.FixedFormatter(ticklabels)
if update_ticks:
self.update_ticks()
else:
warnings.warn("set_ticks() must have been called.")
示例12: __init__
# 需要導入模塊: from matplotlib import ticker [as 別名]
# 或者: from matplotlib.ticker import FixedLocator [as 別名]
def __init__(self, ax, mappable, **kw):
# Ensure the given mappable's norm has appropriate vmin and vmax set
# even if mappable.draw has not yet been called.
mappable.autoscale_None()
self.mappable = mappable
kw['cmap'] = cmap = mappable.cmap
kw['norm'] = norm = mappable.norm
if isinstance(mappable, contour.ContourSet):
CS = mappable
kw['alpha'] = mappable.get_alpha()
kw['boundaries'] = CS._levels
kw['values'] = CS.cvalues
kw['extend'] = CS.extend
#kw['ticks'] = CS._levels
kw.setdefault('ticks', ticker.FixedLocator(CS.levels, nbins=10))
kw['filled'] = CS.filled
ColorbarBase.__init__(self, ax, **kw)
if not CS.filled:
self.add_lines(CS)
else:
if getattr(cmap, 'colorbar_extend', False) is not False:
kw.setdefault('extend', cmap.colorbar_extend)
if isinstance(mappable, martist.Artist):
kw['alpha'] = mappable.get_alpha()
ColorbarBase.__init__(self, ax, **kw)
示例13: _plotStats
# 需要導入模塊: from matplotlib import ticker [as 別名]
# 或者: from matplotlib.ticker import FixedLocator [as 別名]
def _plotStats(self, df, strategyName):
"""
繪製賬戶盈虧統計圖
"""
def _dateFormatter(x, pos):
if not (0 <= int(x) < df.shape[0]):
return None
return df.index[int(x)].strftime("%y-%m-%d")
# create grid spec
gs = GridSpec(4, 1)
gs.update(hspace=0)
# subplot for PnL
axPnl = plt.subplot(gs[:-1, :])
axPnl.grid(True)
axPnl.set_title('{}: 盈虧(%)'.format(strategyName))
# set x ticks
x = [x for x in range(df.shape[0])]
xspace = max((len(x)+9)//10, 1)
axPnl.xaxis.set_major_locator(FixedLocator(x[:-xspace-1: xspace] + x[-1:]))
axPnl.xaxis.set_major_formatter(FuncFormatter(_dateFormatter))
# plot pnl
for name in df.columns:
if name not in ['持倉資金(%)', '持倉股票數']:
axPnl.plot(x, df[name].values, label=name)
axPnl.legend(loc='upper left', frameon=False)
# subplot for position
axPos = plt.subplot(gs[-1, :], sharex=axPnl)
axPos.grid(True)
axPos.bar(x, df['持倉資金(%)'].values, label='持倉資金(%)')
axPos.plot(x, df['持倉資金(%)'].values.cumsum()/np.array(list(range(1, df.shape[0] + 1))), label='平均持倉資金(%)', color='g')
axPos.plot(x, df['持倉股票數'].values, label='持倉股票數', color='r')
axPos.legend(loc='upper left', frameon=False)
示例14: set_ticklabels
# 需要導入模塊: from matplotlib import ticker [as 別名]
# 或者: from matplotlib.ticker import FixedLocator [as 別名]
def set_ticklabels(self, ticklabels, update_ticks=True):
"""
Set tick labels.
Tick labels are updated immediately unless *update_ticks* is *False*,
in which case one should call `.update_ticks` explicitly.
"""
if isinstance(self.locator, ticker.FixedLocator):
self.formatter = ticker.FixedFormatter(ticklabels)
if update_ticks:
self.update_ticks()
else:
cbook._warn_external("set_ticks() must have been called.")
self.stale = True
示例15: __init__
# 需要導入模塊: from matplotlib import ticker [as 別名]
# 或者: from matplotlib.ticker import FixedLocator [as 別名]
def __init__(self, ax, mappable, **kw):
# Ensure the given mappable's norm has appropriate vmin and vmax set
# even if mappable.draw has not yet been called.
if mappable.get_array() is not None:
mappable.autoscale_None()
self.mappable = mappable
kw['cmap'] = cmap = mappable.cmap
kw['norm'] = mappable.norm
if isinstance(mappable, contour.ContourSet):
CS = mappable
kw['alpha'] = mappable.get_alpha()
kw['boundaries'] = CS._levels
kw['values'] = CS.cvalues
kw['extend'] = CS.extend
kw.setdefault('ticks', ticker.FixedLocator(CS.levels, nbins=10))
kw['filled'] = CS.filled
ColorbarBase.__init__(self, ax, **kw)
if not CS.filled:
self.add_lines(CS)
else:
if getattr(cmap, 'colorbar_extend', False) is not False:
kw.setdefault('extend', cmap.colorbar_extend)
if isinstance(mappable, martist.Artist):
kw['alpha'] = mappable.get_alpha()
ColorbarBase.__init__(self, ax, **kw)