本文整理汇总了Python中matplotlib.ticker.ScalarFormatter方法的典型用法代码示例。如果您正苦于以下问题:Python ticker.ScalarFormatter方法的具体用法?Python ticker.ScalarFormatter怎么用?Python ticker.ScalarFormatter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.ticker
的用法示例。
在下文中一共展示了ticker.ScalarFormatter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __setup_plot
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import ScalarFormatter [as 别名]
def __setup_plot(self):
figure = Figure(facecolor='lightgrey')
self._axes = figure.add_subplot(111)
self._axes.set_title('Timeline')
self._axes.set_xlabel('Time')
self._axes.set_ylabel('Frequency (MHz)')
self._axes.grid(True)
locator = AutoDateLocator()
formatter = AutoDateFormatter(locator)
self._axes.xaxis.set_major_formatter(formatter)
self._axes.xaxis.set_major_locator(locator)
formatter = ScalarFormatter(useOffset=False)
self._axes.yaxis.set_major_formatter(formatter)
self._axes.yaxis.set_minor_locator(AutoMinorLocator(10))
self._canvas = FigureCanvas(self._panelPlot, -1, figure)
self._canvas.mpl_connect('motion_notify_event', self.__on_motion)
Legend.__init__(self, self._axes, self._canvas)
示例2: subplots
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import ScalarFormatter [as 别名]
def subplots(*args, **kwargs):
subplot_kw = kwargs.get('subplot_kw', {})
subplot_kw['adjustable'] = subplot_kw.get('adjustable', 'box')
kwargs['subplot_kw'] = subplot_kw
fig, axes = plt.subplots(*args, **kwargs)
def fmt(ax):
ax.set_aspect('equal')
ax.xaxis.set_major_formatter(ScalarFormatter(useOffset=True))
ax.yaxis.set_major_formatter(ScalarFormatter(useOffset=True))
ax.xaxis.get_major_formatter().set_powerlimits((0, 0))
ax.yaxis.get_major_formatter().set_powerlimits((0, 0))
try:
for ax in axes:
fmt(ax)
except TypeError:
fmt(axes)
return fig, axes
示例3: visualize
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import ScalarFormatter [as 别名]
def visualize(file_path):
entries = []
with open(file_path) as f:
entries = [json.loads(line) for line in f.readlines() if line.strip()]
if not entries:
print('There is no data in file {}'.format(file_path))
return
pdf = backend_pdf.PdfPages("process_info.pdf")
idx = 0
names = [name for name in entries[0].keys() if name != 'time']
times = [entry['time'] for entry in entries]
for name in names:
values = [entry[name] for entry in entries]
fig = plt.figure()
ax = plt.gca()
ax.yaxis.set_major_formatter(tick.ScalarFormatter(useMathText=True))
plt.ticklabel_format(style='sci', axis='y', scilimits=(-2,3))
plt.plot(times, values, colors[idx % len(colors)], marker='x', label=name)
plt.xlabel('Time (sec)')
plt.ylabel(name)
plt.ylim(ymin=0)
plt.legend(loc = 'upper left')
pdf.savefig(fig)
idx += 1
plt.show()
pdf.close()
print('Generated process_info.pdf from {}'.format(file_path))
示例4: plot_row
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import ScalarFormatter [as 别名]
def plot_row(arrs, save_dir, filename, same_range=False, plot_fn='imshow',
cmap='viridis'):
"""
Args:
arrs (sequence of 2D Tensor or Numpy): seq of arrs to be plotted
save_dir (str):
filename (str):
same_range (bool): if True, subplots have the same range (colorbar)
plot_fn (str): choices=['imshow', 'contourf']
"""
interpolation = None
arrs = [to_numpy(arr) for arr in arrs]
if same_range:
vmax = max([np.amax(arr) for arr in arrs])
vmin = min([np.amin(arr) for arr in arrs])
else:
vmax, vmin = None, None
fig, _ = plt.subplots(1, len(arrs), figsize=(4.4 * len(arrs), 4))
for i, ax in enumerate(fig.axes):
if plot_fn == 'imshow':
cax = ax.imshow(arrs[i], cmap=cmap, interpolation=interpolation,
vmin=vmin, vmax=vmax)
elif plot_fn == 'contourf':
cax = ax.contourf(arrs[i], 50, cmap=cmap, vmin=vmin, vmax=vmax)
if plot_fn == 'contourf':
for c in cax.collections:
c.set_edgecolor("face")
c.set_linewidth(0.000000000001)
ax.set_axis_off()
cbar = plt.colorbar(cax, ax=ax, fraction=0.046, pad=0.04,
format=ticker.ScalarFormatter(useMathText=True))
cbar.formatter.set_powerlimits((-2, 2))
cbar.ax.yaxis.set_offset_position('left')
# cbar.ax.tick_params(labelsize=5)
cbar.update_ticks()
plt.tight_layout(pad=0.05, w_pad=0.05, h_pad=0.05)
plt.savefig(save_dir + f'/{filename}.{ext}', dpi=dpi, bbox_inches='tight')
plt.close(fig)
示例5: cla
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import ScalarFormatter [as 别名]
def cla(self):
'clear the current axis'
self.set_major_locator(mticker.AutoLocator())
self.set_major_formatter(mticker.ScalarFormatter())
self.set_minor_locator(mticker.NullLocator())
self.set_minor_formatter(mticker.NullFormatter())
self.set_label_text('')
self._set_artist_props(self.label)
# Keep track of setting to the default value, this allows use to know
# if any of the following values is explicitly set by the user, so as
# to not overwrite their settings with any of our 'auto' settings.
self.isDefault_majloc = True
self.isDefault_minloc = True
self.isDefault_majfmt = True
self.isDefault_minfmt = True
self.isDefault_label = True
# Clear the callback registry for this axis, or it may "leak"
self.callbacks = cbook.CallbackRegistry()
# whether the grids are on
self._gridOnMajor = rcParams['axes.grid']
self._gridOnMinor = False
self.label.set_text('')
self._set_artist_props(self.label)
self.reset_ticks()
self.converter = None
self.units = None
self.set_units(None)
示例6: __init__
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import ScalarFormatter [as 别名]
def __init__(self, useMathText=True):
self._fmt = mticker.ScalarFormatter(useMathText=useMathText, useOffset=False)
self._fmt.create_dummy_axis()
self._ignore_factor = True
示例7: __init__
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import ScalarFormatter [as 别名]
def __init__( self, *args, **kwargs ):
'The arguments are identical to matplotlib.ticker.ScalarFormatter.'
ticker.ScalarFormatter.__init__( self, *args, **kwargs )
示例8: cla
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import ScalarFormatter [as 别名]
def cla(self):
'clear the current axis'
self.set_major_locator(mticker.AutoLocator())
self.set_major_formatter(mticker.ScalarFormatter())
self.set_minor_locator(mticker.NullLocator())
self.set_minor_formatter(mticker.NullFormatter())
self.set_label_text('')
self._set_artist_props(self.label)
# Keep track of setting to the default value, this allows use to know
# if any of the following values is explicitly set by the user, so as
# to not overwrite their settings with any of our 'auto' settings.
self.isDefault_majloc = True
self.isDefault_minloc = True
self.isDefault_majfmt = True
self.isDefault_minfmt = True
self.isDefault_label = True
# Clear the callback registry for this axis, or it may "leak"
self.callbacks = cbook.CallbackRegistry()
# whether the grids are on
self._gridOnMajor = rcParams['axes.grid'] and (rcParams['axes.grid.which'] in ('both','major'))
self._gridOnMinor = rcParams['axes.grid'] and (rcParams['axes.grid.which'] in ('both','minor'))
self.label.set_text('')
self._set_artist_props(self.label)
self.reset_ticks()
self.converter = None
self.units = None
self.set_units(None)
示例9: test_use_offset
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import ScalarFormatter [as 别名]
def test_use_offset():
for use_offset in [True, False]:
with matplotlib.rc_context({'axes.formatter.useoffset': use_offset}):
tmp_form = mticker.ScalarFormatter()
nose.tools.assert_equal(use_offset, tmp_form.get_useOffset())
示例10: __init__
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import ScalarFormatter [as 别名]
def __init__(self, *args, **kwargs):
'The arguments are identical to matplotlib.ticker.ScalarFormatter.'
ticker.ScalarFormatter.__init__(self, *args, **kwargs)
示例11: __init__
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import ScalarFormatter [as 别名]
def __init__(self, useMathText=True):
self._fmt = mticker.ScalarFormatter(
useMathText=useMathText, useOffset=False)
self._fmt.create_dummy_axis()
self._ignore_factor = True
示例12: test_use_offset
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import ScalarFormatter [as 别名]
def test_use_offset(self, use_offset):
with matplotlib.rc_context({'axes.formatter.useoffset': use_offset}):
tmp_form = mticker.ScalarFormatter()
assert use_offset == tmp_form.get_useOffset()
示例13: test_scilimits
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import ScalarFormatter [as 别名]
def test_scilimits(self, sci_type, scilimits, lim, orderOfMag):
tmp_form = mticker.ScalarFormatter()
tmp_form.set_scientific(sci_type)
tmp_form.set_powerlimits(scilimits)
fig, ax = plt.subplots()
ax.yaxis.set_major_formatter(tmp_form)
ax.set_ylim(*lim)
tmp_form.set_locs(ax.yaxis.get_majorticklocs())
assert orderOfMag == tmp_form.orderOfMagnitude
示例14: scale_axes
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import ScalarFormatter [as 别名]
def scale_axes(axis, scale, offset=0.):
from matplotlib.ticker import ScalarFormatter
class FormatScaled(ScalarFormatter):
@staticmethod
def __call__(value, pos):
return '{:,.1f}'.format(offset + value * scale).replace(',', ' ')
axis.set_major_formatter(FormatScaled())
示例15: plot_stab_vs_k
# 需要导入模块: from matplotlib import ticker [as 别名]
# 或者: from matplotlib.ticker import ScalarFormatter [as 别名]
def plot_stab_vs_k(slow_resolved, mvals, kvals, stabval):
"""
Plotting routine for moduli
Args:
slow_resolved (bool): switch for lambda_slow
mvals (numpy.ndarray): number of nodes
kvals (numpy.ndarray): number of iterations
stabval (numpy.ndarray): moduli
"""
rcParams['figure.figsize'] = 2.5, 2.5
fig = plt.figure()
fs = 8
plt.plot(kvals, stabval[0, :], 'o-', color='b', label=("M=%2i" % mvals[0]), markersize=fs - 2)
plt.plot(kvals, stabval[1, :], 's-', color='r', label=("M=%2i" % mvals[1]), markersize=fs - 2)
plt.plot(kvals, stabval[2, :], 'd-', color='g', label=("M=%2i" % mvals[2]), markersize=fs - 2)
plt.plot(kvals, 1.0 + 0.0 * kvals, '--', color='k')
plt.xlabel('Number of iterations K', fontsize=fs)
plt.ylabel(r'Modulus of stability function $\left| R \right|$', fontsize=fs)
plt.ylim([0.0, 1.2])
if slow_resolved:
plt.legend(loc='upper right', fontsize=fs, prop={'size': fs})
else:
plt.legend(loc='lower left', fontsize=fs, prop={'size': fs})
plt.gca().get_xaxis().get_major_formatter().labelOnlyBase = False
plt.gca().get_xaxis().set_major_formatter(ScalarFormatter())
# plt.show()
if slow_resolved:
filename = 'data/stab_vs_k_resolved.png'
else:
filename = 'data/stab_vs_k_unresolved.png'
fig.savefig(filename, bbox_inches='tight')