Python matplotlib.ticker.Locator() Examples
The following are 15
code examples of matplotlib.ticker.Locator().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
matplotlib.ticker
, or try the search function
.
Example #1
Source File: axis.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def set_major_locator(self, locator): """ Set the locator of the major ticker. Parameters ---------- locator : ~matplotlib.ticker.Locator """ if not isinstance(locator, mticker.Locator): raise TypeError("locator argument should be instance of " "matplotlib.ticker.Locator") self.isDefault_majloc = False self.major.locator = locator if self.major.formatter: self.major.formatter._set_locator(locator) locator.set_axis(self) self.stale = True
Example #2
Source File: axis.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def set_minor_locator(self, locator): """ Set the locator of the minor ticker. Parameters ---------- locator : ~matplotlib.ticker.Locator """ if not isinstance(locator, mticker.Locator): raise TypeError("locator argument should be instance of " "matplotlib.ticker.Locator") self.isDefault_minloc = False self.minor.locator = locator if self.minor.formatter: self.minor.formatter._set_locator(locator) locator.set_axis(self) self.stale = True
Example #3
Source File: axis.py From CogAlg with MIT License | 6 votes |
def set_major_locator(self, locator): """ Set the locator of the major ticker. Parameters ---------- locator : `~matplotlib.ticker.Locator` """ if not isinstance(locator, mticker.Locator): raise TypeError("locator argument should be instance of " "matplotlib.ticker.Locator") self.isDefault_majloc = False self.major.locator = locator if self.major.formatter: self.major.formatter._set_locator(locator) locator.set_axis(self) self.stale = True
Example #4
Source File: axis.py From CogAlg with MIT License | 6 votes |
def set_minor_locator(self, locator): """ Set the locator of the minor ticker. Parameters ---------- locator : `~matplotlib.ticker.Locator` """ if not isinstance(locator, mticker.Locator): raise TypeError("locator argument should be instance of " "matplotlib.ticker.Locator") self.isDefault_minloc = False self.minor.locator = locator if self.minor.formatter: self.minor.formatter._set_locator(locator) locator.set_axis(self) self.stale = True
Example #5
Source File: axis.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def set_major_locator(self, locator): """ Set the locator of the major ticker. Parameters ---------- locator : ~matplotlib.ticker.Locator """ if not isinstance(locator, mticker.Locator): raise TypeError("formatter argument should be instance of " "matplotlib.ticker.Locator") self.isDefault_majloc = False self.major.locator = locator locator.set_axis(self) self.stale = True
Example #6
Source File: axis.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def set_minor_locator(self, locator): """ Set the locator of the minor ticker. Parameters ---------- locator : ~matplotlib.ticker.Locator """ if not isinstance(locator, mticker.Locator): raise TypeError("formatter argument should be instance of " "matplotlib.ticker.Locator") self.isDefault_minloc = False self.minor.locator = locator locator.set_axis(self) self.stale = True
Example #7
Source File: axis.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def set_major_locator(self, locator): """ Set the locator of the major ticker. Parameters ---------- locator : ~matplotlib.ticker.Locator """ if not isinstance(locator, mticker.Locator): raise TypeError("formatter argument should be instance of " "matplotlib.ticker.Locator") self.isDefault_majloc = False self.major.locator = locator locator.set_axis(self) self.stale = True
Example #8
Source File: axis.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def set_minor_locator(self, locator): """ Set the locator of the minor ticker. Parameters ---------- locator : ~matplotlib.ticker.Locator """ if not isinstance(locator, mticker.Locator): raise TypeError("formatter argument should be instance of " "matplotlib.ticker.Locator") self.isDefault_minloc = False self.minor.locator = locator locator.set_axis(self) self.stale = True
Example #9
Source File: element.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _set_axis_ticks(self, axis, ticks, log=False, rotation=0): """ Allows setting the ticks for a particular axis either with a tuple of ticks, a tick locator object, an integer number of ticks, a list of tuples containing positions and labels or a list of positions. Also supports enabling log ticking if an integer number of ticks is supplied and setting a rotation for the ticks. """ if isinstance(ticks, (list, tuple)) and all(isinstance(l, list) for l in ticks): axis.set_ticks(ticks[0]) axis.set_ticklabels(ticks[1]) elif isinstance(ticks, ticker.Locator): axis.set_major_locator(ticks) elif not ticks and ticks is not None: axis.set_ticks([]) elif isinstance(ticks, int): if log: locator = ticker.LogLocator(numticks=ticks, subs=range(1,10)) else: locator = ticker.MaxNLocator(ticks) axis.set_major_locator(locator) elif isinstance(ticks, (list, tuple)): labels = None if all(isinstance(t, tuple) for t in ticks): ticks, labels = zip(*ticks) axis.set_ticks(ticks) if labels: axis.set_ticklabels(labels) for tick in axis.get_ticklabels(): tick.set_rotation(rotation)
Example #10
Source File: element.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _adjust_cbar(self, cbar, label, dim): noalpha = math.floor(self.style[self.cyclic_index].get('alpha', 1)) == 1 for lb in ['clabel', 'labels']: labelsize = self._fontsize(lb, common=False).get('fontsize') if labelsize is not None: break if (cbar.solids and noalpha): cbar.solids.set_edgecolor("face") cbar.set_label(label, fontsize=labelsize) if isinstance(self.cbar_ticks, ticker.Locator): cbar.ax.yaxis.set_major_locator(self.cbar_ticks) elif self.cbar_ticks == 0: cbar.set_ticks([]) elif isinstance(self.cbar_ticks, int): locator = ticker.MaxNLocator(self.cbar_ticks) cbar.ax.yaxis.set_major_locator(locator) elif isinstance(self.cbar_ticks, list): if all(isinstance(t, tuple) for t in self.cbar_ticks): ticks, labels = zip(*self.cbar_ticks) else: ticks, labels = zip(*[(t, dim.pprint_value(t)) for t in self.cbar_ticks]) cbar.set_ticks(ticks) cbar.set_ticklabels(labels) for tk in ['cticks', 'ticks']: ticksize = self._fontsize(tk, common=False).get('fontsize') if ticksize is not None: cbar.ax.tick_params(labelsize=ticksize) break
Example #11
Source File: axis.py From coffeegrindsize with MIT License | 5 votes |
def set_major_locator(self, locator): """ Set the locator of the major ticker. Parameters ---------- locator : ~matplotlib.ticker.Locator """ if not isinstance(locator, mticker.Locator): raise TypeError("formatter argument should be instance of " "matplotlib.ticker.Locator") self.isDefault_majloc = False self.major.locator = locator locator.set_axis(self) self.stale = True
Example #12
Source File: axis.py From coffeegrindsize with MIT License | 5 votes |
def set_minor_locator(self, locator): """ Set the locator of the minor ticker. Parameters ---------- locator : ~matplotlib.ticker.Locator """ if not isinstance(locator, mticker.Locator): raise TypeError("formatter argument should be instance of " "matplotlib.ticker.Locator") self.isDefault_minloc = False self.minor.locator = locator locator.set_axis(self) self.stale = True
Example #13
Source File: dates.py From Computable with MIT License | 4 votes |
def __call__(self): # if no data have been set, this will tank with a ValueError try: dmin, dmax = self.viewlim_to_dt() except ValueError: return [] if dmin > dmax: dmax, dmin = dmin, dmax delta = relativedelta(dmax, dmin) # We need to cap at the endpoints of valid datetime try: start = dmin - delta except ValueError: start = _from_ordinalf(1.0) try: stop = dmax + delta except ValueError: # The magic number! stop = _from_ordinalf(3652059.9999999) self.rule.set(dtstart=start, until=stop, count=self.MAXTICKS + 1) # estimate the number of ticks very approximately so we don't # have to do a very expensive (and potentially near infinite) # 'between' calculation, only to find out it will fail. nmax, nmin = date2num((dmax, dmin)) estimate = (nmax - nmin) / (self._get_unit() * self._get_interval()) # This estimate is only an estimate, so be really conservative # about bailing... if estimate > self.MAXTICKS * 2: raise RuntimeError( 'RRuleLocator estimated to generate %d ticks from %s to %s: ' 'exceeds Locator.MAXTICKS * 2 (%d) ' % (estimate, dmin, dmax, self.MAXTICKS * 2)) dates = self.rule.between(dmin, dmax, True) if len(dates) == 0: return date2num([dmin, dmax]) return self.raise_if_exceeds(date2num(dates))
Example #14
Source File: dates.py From matplotlib-4-abaqus with MIT License | 4 votes |
def __call__(self): # if no data have been set, this will tank with a ValueError try: dmin, dmax = self.viewlim_to_dt() except ValueError: return [] if dmin > dmax: dmax, dmin = dmin, dmax delta = relativedelta(dmax, dmin) # We need to cap at the endpoints of valid datetime try: start = dmin - delta except ValueError: start = _from_ordinalf(1.0) try: stop = dmax + delta except ValueError: # The magic number! stop = _from_ordinalf(3652059.9999999) self.rule.set(dtstart=start, until=stop, count=self.MAXTICKS + 1) # estimate the number of ticks very approximately so we don't # have to do a very expensive (and potentially near infinite) # 'between' calculation, only to find out it will fail. nmax, nmin = date2num((dmax, dmin)) estimate = (nmax - nmin) / (self._get_unit() * self._get_interval()) # This estimate is only an estimate, so be really conservative # about bailing... if estimate > self.MAXTICKS * 2: raise RuntimeError( 'RRuleLocator estimated to generate %d ticks from %s to %s: ' 'exceeds Locator.MAXTICKS * 2 (%d) ' % (estimate, dmin, dmax, self.MAXTICKS * 2)) dates = self.rule.between(dmin, dmax, True) if len(dates) == 0: return date2num([dmin, dmax]) return self.raise_if_exceeds(date2num(dates))
Example #15
Source File: dates.py From neural-network-animation with MIT License | 4 votes |
def __call__(self): # if no data have been set, this will tank with a ValueError try: dmin, dmax = self.viewlim_to_dt() except ValueError: return [] if dmin > dmax: dmax, dmin = dmin, dmax delta = relativedelta(dmax, dmin) # We need to cap at the endpoints of valid datetime try: start = dmin - delta except ValueError: start = _from_ordinalf(1.0) try: stop = dmax + delta except ValueError: # The magic number! stop = _from_ordinalf(3652059.9999999) self.rule.set(dtstart=start, until=stop, count=self.MAXTICKS + 1) # estimate the number of ticks very approximately so we don't # have to do a very expensive (and potentially near infinite) # 'between' calculation, only to find out it will fail. nmax, nmin = date2num((dmax, dmin)) estimate = (nmax - nmin) / (self._get_unit() * self._get_interval()) # This estimate is only an estimate, so be really conservative # about bailing... if estimate > self.MAXTICKS * 2: raise RuntimeError( 'RRuleLocator estimated to generate %d ticks from %s to %s: ' 'exceeds Locator.MAXTICKS * 2 (%d) ' % (estimate, dmin, dmax, self.MAXTICKS * 2)) dates = self.rule.between(dmin, dmax, True) if len(dates) == 0: return date2num([dmin, dmax]) return self.raise_if_exceeds(date2num(dates))