Python matplotlib.ticker 模块,FixedFormatter() 实例源码
我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用matplotlib.ticker.FixedFormatter()。
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.")
def set_ticklabels(self, ticker.FixedLocator):
self.formatter = ticker.FixedFormatter(ticklabels)
if update_ticks:
self.update_ticks()
else:
warnings.warn("set_ticks() must have been called.")
def setLinesensor(self):
try:
self.compressLabel(self.sensorList)
x1=[]
x1pos=[]
labels1=[]
j = -1
x1pos.append(0)
labels1.append('')
# self.setTestData()
for i in self.sensorList:
if i.startX > j:
x1.append(i.startX)
j = i.startX
x1.append(i.stopX)
x1pos.append(i.labelPos)
labels1.append(i.label)
self.par1.xaxis.set_major_formatter(ticker.NullFormatter())
self.par1.xaxis.set_minor_locator(ticker.FixedLocator(x1pos))
self.par1.xaxis.set_minor_formatter(ticker.FixedFormatter(labels1))
self.par1.xaxis.set_ticks(x1)
except Exception as _err:
print(_err)
logging.exception(_err)
pass
def setLineRBW(self):
self.compressLabel(self.rbwList)
try:
x1 = []
x1pos = []
labels1 = []
j = -1
x1pos.append(0)
labels1.append('')
# self.setTestData()
for i in self.rbwList:
if i.startX > j:
x1.append(i.startX)
j = i.startX
x1.append(i.stopX)
x1pos.append(i.labelPos)
labels1.append(i.label)
# self.par2.spines["bottom"].set_position(("outward",50))
# self.par2.xaxis.set_ticks_position('bottom')
# self.par2.set_xscale('log')
self.par2.xaxis.set_major_formatter(ticker.NullFormatter())
self.par2.xaxis.set_minor_locator(ticker.FixedLocator(x1pos))
self.par2.xaxis.set_minor_formatter(ticker.FixedFormatter(labels1))
self.par2.xaxis.set_ticks(x1)
self.par2.xaxis.set_tick_params(which='minor',length=1,direction='out', pad=5, labelbottom='on')
self.par2.xaxis.set_tick_params(which='major',length=10,labelbottom='on')
except Exception as _err:
print(_err)
logging.exception(_err)
def setLineAMP(self):
self.compressLabel(self.ampList)
try:
x1 = []
x1pos = []
labels1 = []
j = -1
x1pos.append(0)
labels1.append('')
# self.setTestData()
for i in self.ampList:
if i.startX > j:
x1.append(i.startX)
j = i.startX
x1.append(i.stopX)
x1pos.append(i.labelPos)
labels1.append(i.label)
if not self.line2TextFlag:
# self.par3.text(-0.05,-0.33,"amp",horizontalalignment='left',transform=self.host.transAxes)
# self.par3.text(-0.05,-0.40,"att",transform=self.host.transAxes)
# self.par3.spines["bottom"].set_position(("outward",90))
self.par3.xaxis.set_ticks_position('bottom')
self.par3.xaxis.set_major_formatter(ticker.NullFormatter())
self.par3.xaxis.set_minor_formatter(ticker.NullFormatter())
self.par3.xaxis.set_tick_params(which='minor',direction='in', pad=-10, labelbottom='on')
self.par3.xaxis.set_tick_params(which='major', pad=-20,labelbottom='on')
self.line2TextFlag = True
self.par3.xaxis.set_minor_locator(ticker.FixedLocator(x1pos))
self.par3.xaxis.set_minor_formatter(ticker.FixedFormatter(labels1))
self.par3.xaxis.set_ticks(x1)
#set color for autorange indication
_Ret = self.par3.xaxis.get_minorticklabels()
n = 0
for i in _Ret:
if self.ampList[n].color =='r':
i._color = 'r' #sorry,found no other access
if n < len(self.ampList) - 1:
n += 1
except Exception as _err:
print(_err)
logging.exception(_err)
pass
def setLineATT(self):
self.compressLabel(self.attList)
try:
x1 = []
x1pos = []
labels1 = []
j = -1
x1pos.append(0)
labels1.append('')
# self.setTestData()
for i in self.attList:
if i.startX > j:
x1.append(i.startX)
j = i.startX
x1.append(i.stopX)
x1pos.append(i.labelPos)
labels1.append(i.label)
# self.par4.spines["bottom"].set_position(("outward",90))
# self.par4.xaxis.set_ticks_position('bottom')
# # self.par1.set_xlim(1e3,1e9)
# self.par4.set_xscale('log')
self.par4.xaxis.set_major_formatter(ticker.NullFormatter())
self.par4.xaxis.set_minor_locator(ticker.FixedLocator(x1pos))
self.par4.xaxis.set_minor_formatter(ticker.FixedFormatter(labels1))
self.par4.xaxis.set_ticks(x1)
self.par4.xaxis.set_tick_params(which='minor', labelbottom='on')
self.par4.xaxis.set_tick_params(which='major',labelbottom='on')
_Ret = self.par4.xaxis.get_minorticklabels()
n = 0
for i in _Ret:
if self.attList[n].color =='r':
i._color = 'red'
if n < len(self.attList) - 1:
n += 1
# self.signalGraphUpdate.emit()
except Exception as _err:
print(_err)
logging.exception(_err)
pass
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。