本文整理汇总了Python中matplotlib.transforms.nonsingular函数的典型用法代码示例。如果您正苦于以下问题:Python nonsingular函数的具体用法?Python nonsingular怎么用?Python nonsingular使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了nonsingular函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_nonsingular
def test_nonsingular():
# test for zero-expansion type cases; other cases may be added later
zero_expansion = np.array([-0.001, 0.001])
cases = [(0, np.nan), (0, 0), (0, 7.9e-317)]
for args in cases:
out = np.array(mtrans.nonsingular(*args))
assert_array_equal(out, zero_expansion)
示例2: view_limits
def view_limits(self, vmin, vmax):
'Try to choose the view limits intelligently'
b = self._transform.base
if vmax<vmin:
vmin, vmax = vmax, vmin
if not is_decade(abs(vmin), b):
if vmin < 0:
vmin = -decade_up(-vmin, b)
else:
vmin = decade_down(vmin, b)
if not is_decade(abs(vmax), b):
if vmax < 0:
vmax = -decade_down(-vmax, b)
else:
vmax = decade_up(vmax, b)
if vmin == vmax:
if vmin < 0:
vmin = -decade_up(-vmin, b)
vmax = -decade_down(-vmax, b)
else:
vmin = decade_down(vmin, b)
vmax = decade_up(vmax, b)
result = mtransforms.nonsingular(vmin, vmax)
return result
示例3: __call__
def __call__(self, x, pos=None):
'Return the format for tick val *x* at position *pos*'
vmin, vmax = self.axis.get_view_interval()
vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander = 0.05)
d = abs(vmax-vmin)
b=self._base
if x == 0:
return '0'
sign = np.sign(x)
# only label the decades
fx = math.log(abs(x))/math.log(b)
isDecade = is_close_to_int(fx)
if not isDecade and self.labelOnlyBase: s = ''
#if 0: pass
elif fx>10000: s= '%1.0e'%fx
#elif x<1: s = '$10^{%d}$'%fx
#elif x<1: s = '10^%d'%fx
elif fx<1: s = '%1.0e'%fx
else : s = self.pprint_val(fx,d)
if sign == -1:
s = '-%s' % s
return self.fix_minus(s)
示例4: view_limits
def view_limits(self, vmin, vmax):
"""
Try to choose the view limits intelligently. In contrast to the stock
LogLocator, this version always pads by one decade so that the contents
of the largest and smallest histogram bins can be seen even if they
fall on a decade.
"""
b = self._base
if vmax < vmin:
vmin, vmax = vmax, vmin
if self.axis.axes.name == 'polar':
vmax = math.ceil(math.log(vmax) / math.log(b))
vmin = b ** (vmax - self.numdecs)
return vmin, vmax
minpos = self.axis.get_minpos()
if minpos <= 0 or not np.isfinite(minpos):
raise ValueError(
"Data has no positive values, and therefore can not be "
"log-scaled.")
if vmin <= minpos:
vmin = minpos
vmin = mticker.decade_down(vmin*(1-1e-10), self._base)
vmax = mticker.decade_up(vmax*(1+1e-10), self._base)
if vmin == vmax:
vmin = mticker.decade_down(vmin, self._base)
vmax = mticker.decade_up(vmax, self._base)
result = mtransforms.nonsingular(vmin, vmax)
return result
示例5: get_view_interval
def get_view_interval(self):
vmin, vmax = self.axis.get_view_interval()
if self.epoch:
vmin -= float(self.epoch.gps)
vmax -= float(self.epoch.gps)
if self._scale:
vmin /= self._scale
vmax /= self._scale
return mtransforms.nonsingular(vmin, vmax, expander = 0.05)
示例6: __call__
def __call__(self):
vmin, vmax = self.axis.get_view_interval()
vmin, vmax = nonsingular(vmin, vmax, expander = 0.05)
vmin = vmin ** self.exponent
vmax = vmax ** self.exponent
if vmax<vmin:
vmin, vmax = vmax, vmin
ticklocs = np.linspace(vmin, vmax, num=self.numticks, endpoint=True)
return self.raise_if_exceeds(ticklocs ** (1.0 / self.exponent))
示例7: tick_values
def tick_values(self, vmin, vmax):
vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander=1e-7,
tiny=1e-13)
self.ndays = float(abs(vmax - vmin))
utime = cftime.utime(self.date_unit, self.calendar)
lower = utime.num2date(vmin)
upper = utime.num2date(vmax)
resolution, n = self.compute_resolution(vmin, vmax, lower, upper)
if resolution == 'YEARLY':
# TODO START AT THE BEGINNING OF A DECADE/CENTURY/MILLENIUM as
# appropriate.
years = self._max_n_locator.tick_values(lower.year, upper.year)
ticks = [cftime.datetime(int(year), 1, 1) for year in years]
elif resolution == 'MONTHLY':
# TODO START AT THE BEGINNING OF A DECADE/CENTURY/MILLENIUM as
# appropriate.
months_offset = self._max_n_locator.tick_values(0, n)
ticks = []
for offset in months_offset:
year = lower.year + np.floor((lower.month + offset) / 12)
month = ((lower.month + offset) % 12) + 1
ticks.append(cftime.datetime(int(year), int(month), 1))
elif resolution == 'DAILY':
# TODO: It would be great if this favoured multiples of 7.
days = self._max_n_locator_days.tick_values(vmin, vmax)
ticks = [utime.num2date(dt) for dt in days]
elif resolution == 'HOURLY':
hour_unit = 'hours since 2000-01-01'
hour_utime = cftime.utime(hour_unit, self.calendar)
in_hours = hour_utime.date2num([lower, upper])
hours = self._max_n_locator.tick_values(in_hours[0], in_hours[1])
ticks = [hour_utime.num2date(dt) for dt in hours]
elif resolution == 'MINUTELY':
minute_unit = 'minutes since 2000-01-01'
minute_utime = cftime.utime(minute_unit, self.calendar)
in_minutes = minute_utime.date2num([lower, upper])
minutes = self._max_n_locator.tick_values(in_minutes[0],
in_minutes[1])
ticks = [minute_utime.num2date(dt) for dt in minutes]
elif resolution == 'SECONDLY':
second_unit = 'seconds since 2000-01-01'
second_utime = cftime.utime(second_unit, self.calendar)
in_seconds = second_utime.date2num([lower, upper])
seconds = self._max_n_locator.tick_values(in_seconds[0],
in_seconds[1])
ticks = [second_utime.num2date(dt) for dt in seconds]
else:
msg = 'Resolution {} not implemented yet.'.format(resolution)
raise ValueError(msg)
return utime.date2num(ticks)
示例8: view_limits
def view_limits(self, dmin, dmax):
"""
Set the view limits to the nearest multiples of base that
contain the data
"""
vmin = self._base.le(math.copysign(math.sqrt(abs(dmin)), dmin))
vmax = self._base.ge(math.sqrt(dmax))
if vmin == vmax:
vmin -= 1
vmax += 1
return mtransforms.nonsingular(math.copysign(vmin**2, vmin), vmax**2)
示例9: autoscale
def autoscale(self):
"""
Sets the view limits to the nearest multiples of base that contain the data.
"""
# requires matplotlib >= 0.98.0
(vmin, vmax) = self.axis.get_data_interval()
locs = self._get_default_locs(vmin, vmax)
(vmin, vmax) = locs[[0, -1]]
if vmin == vmax:
vmin -= 1
vmax += 1
return nonsingular(vmin, vmax)
示例10: tick_values
def tick_values(self, vmin, vmax):
"""Return the ticks for this axis
"""
vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander=1e-13,
tiny=1e-14)
locs = self.bin_boundaries(vmin, vmax)
prune = self._prune
if prune == 'lower':
locs = locs[1:]
elif prune == 'upper':
locs = locs[:-1]
elif prune == 'both':
locs = locs[1:-1]
return self.raise_if_exceeds(locs)
示例11: plot
def plot(self, experiment, **kwargs):
"""Plot a faceted histogram view of a channel"""
#kwargs.setdefault('histtype', 'stepfilled')
#kwargs.setdefault('alpha', 0.5)
kwargs.setdefault('edgecolor', 'none')
#kwargs.setdefault('mincnt', 1)
#kwargs.setdefault('bins', 'log')
kwargs.setdefault('antialiased', True)
if not self.subset:
x = experiment.data
else:
x = experiment.query(self.subset)
xmin, xmax = (np.amin(x[self.xchannel]), np.amax(x[self.xchannel]))
ymin, ymax = (np.amin(x[self.ychannel]), np.amax(x[self.ychannel]))
# to avoid issues with singular data, expand the min/max pairs
xmin, xmax = mtrans.nonsingular(xmin, xmax, expander=0.1)
ymin, ymax = mtrans.nonsingular(ymin, ymax, expander=0.1)
extent = (xmin, xmax, ymin, ymax)
kwargs.setdefault('extent', extent)
xbins = num_hist_bins(experiment[self.xchannel])
ybins = num_hist_bins(experiment[self.ychannel])
bins = np.mean([xbins, ybins])
kwargs.setdefault('bins', bins) # Do not move above. don't ask.
g = sns.FacetGrid(x,
col = (self.xfacet if self.xfacet else None),
row = (self.yfacet if self.yfacet else None),
hue = (self.huefacet if self.huefacet else None))
g.map(plt.hexbin, self.xchannel, self.ychannel, **kwargs)
示例12: view_limits
def view_limits(self, vmin, vmax):
'Try to choose the view limits intelligently'
b = self._base
if vmax < vmin:
vmin, vmax = vmax, vmin
if self.axis.axes.name == 'polar':
vmax = math.ceil(math.log(vmax - self.zero) / math.log(b))
vmin = b ** (vmax - self.numdecs)
return vmin, vmax
minpos = self.axis.get_minpos()
if (self.sign > 0.0) :
if vmax <= self.zero or not np.isfinite(minpos):
raise ValueError(
"Data has no positive values, and therefore can not be "
"log-scaled.")
else:
if vmin >= self.zero or not np.isfinite(minpos):
raise ValueError(
"Data has no positive values, and therefore can not be "
"log-scaled.")
if not is_decade((vmin - self.zero) * self.sign, self._base):
if self.sign > 0.0:
vmin = decade_down((vmin - self.zero) * self.sign, self._base) + self.zero
else:
vmin = decade_up((vmin - self.zero) * self.sign, self._base) * self.sign + self.zero
if not is_decade((vmax - self.zero) * self.sign, self._base):
if self.sign > 0.0:
vmax = decade_up((vmax - self.zero) * self.sign, self._base) + self.zero
else:
vmax = decade_down((vmax - self.zero) * self.sign, self._base) * self.sign + self.zero
if vmin == vmax:
if (self.sign > 0.0):
vmin = decade_down((vmin - self.zero) * self.sign, self._base) + self.zero
vmax = decade_up((vmax - self.zero) * self.sign, self._base) + self.zero
else:
vmin = decade_up((vmin - self.zero) * self.sign, self._base) * self.sign + self.zero
vmax = decade_down((vmax - self.zero) * self.sign, self._base) * self.sign + self.zero
result = mtransforms.nonsingular(vmin, vmax)
return result
示例13: autoscale
def autoscale(self):
'Try to choose the view limits intelligently'
self.verify_intervals()
vmin, vmax = self.dataInterval.get_bounds()
if vmax<vmin:
vmin, vmax = vmax, vmin
minpos = self.dataInterval.minpos()
if minpos<=0:
raise RuntimeError('No positive data to plot')
if vmin<=0:
vmin = minpos
if not is_decade(vmin,self._base): vmin = decade_down(vmin,self._base)
if not is_decade(vmax,self._base): vmax = decade_up(vmax,self._base)
if vmin==vmax:
vmin = decade_down(vmin,self._base)
vmax = decade_up(vmax,self._base)
return mtrans.nonsingular(vmin, vmax)