当前位置: 首页>>代码示例>>Python>>正文


Python NavigationToolbar2QTAgg.findChildren方法代码示例

本文整理汇总了Python中matplotlib.backends.backend_qt4agg.NavigationToolbar2QTAgg.findChildren方法的典型用法代码示例。如果您正苦于以下问题:Python NavigationToolbar2QTAgg.findChildren方法的具体用法?Python NavigationToolbar2QTAgg.findChildren怎么用?Python NavigationToolbar2QTAgg.findChildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.backends.backend_qt4agg.NavigationToolbar2QTAgg的用法示例。


在下文中一共展示了NavigationToolbar2QTAgg.findChildren方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: QMplWidget

# 需要导入模块: from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.NavigationToolbar2QTAgg import findChildren [as 别名]
class QMplWidget (QtGui.QWidget):
    
    picked = QtCore.pyqtSignal (str)
    axisChanged = QtCore.pyqtSignal (tuple, tuple)
    
    def __init__(self, parent=None):
        super(QMplWidget, self).__init__(parent)
        
        self.figure = Figure()
        self.canvas = FigureCanvas(self.figure)
        try:
            self.ax = self.figure.add_subplot(111)
        except:
            rcdefaults()
            self.ax = self.figure.add_subplot(111)
        
        
        self.toolbar = NavigationToolbar(self.canvas, self)
        map (lambda a: a.setVisible(False), filter(lambda a: a.text() in ['Customize'], self.toolbar.findChildren(QtGui.QAction)))

        layout = QtGui.QVBoxLayout()
        layout.addWidget(self.canvas)
        layout.addWidget(self.toolbar)
        self.setLayout(layout)
        
        def on_pick(event):
            if event.mouseevent.button == 1:
                label = event.artist.get_label()
                if len(label):
                    self.picked.emit (label)
        self.canvas.mpl_connect('pick_event', on_pick)
        
        self.legendCols = 1
        self.legendPos = 0
        
        self.grid = rcParams['axes.grid']
        self.qualifiedColorMaps = ['Accent', 'Dark2', 'Paired', 'Pastel1', 'Pastel2', 'Set1', 'Set2', 'Set3']
        self.colorMap = None
        
        self.oldLines = {}
        self.xdate = False
        self.ydate = False
        self.clean()
        
    def genColorMap (self, numColors=10, colorMapName = ''):
        if not colorMapName in self.qualifiedColorMaps:
            colorMapName = self.qualifiedColorMaps[randint(1,len(self.qualifiedColorMaps))-1] 
        cm = get_cmap(colorMapName, numColors)
        self.colorMap = [cm(1.*i/numColors) for i in range(numColors)]
    
    def clean (self, xField='', yField='', resetStyle = False):
        self.oldLines = {}
        if not resetStyle:
            map (lambda l: self.oldLines.__setitem__(l.get_label(),l), self.ax.get_lines())
        
        self.ax.cla()        
        def on_axeslim_changed (ax):
            self.axisChanged.emit (ax.get_xlim(),ax.get_ylim())
        self.ax.callbacks.connect('xlim_changed', on_axeslim_changed)
        self.ax.callbacks.connect('ylim_changed', on_axeslim_changed)
        on_axeslim_changed (self.ax)
        
        self.xdate = (xField == 'Time')
        self.ydate = (yField == 'Time')
        self.ax.set_color_cycle(self.colorMap)
    
    def applyTimeFormat (self, timeFormat = ''):
        timeFormatter = mpdates.DateFormatter(timeFormat) if len(timeFormat) else None
        if self.xdate and timeFormatter:
            self.ax.xaxis.set_major_formatter(timeFormatter)
        if self.ydate and timeFormatter:
            self.ax.yaxis.set_major_formatter(timeFormatter)
        self.figure.autofmt_xdate()
    
    def plot(self, x=[], y=[], label = None):
        def _float(value):
            try:
                return float(value)
            except:
                return -9999
            
        if self.xdate:
            x = [mpdates.datestr2num(v) for v in x]
        else:
            x = [_float(v) for v in x]
        if self.ydate:
            y = [mpdates.datestr2num(v) for v in y]
        else:
            y = [_float(v) for v in y]
        
        line, = self.ax.plot (x, y, label = label, picker=5)
        if self.xdate:
            self.ax.xaxis_date()
        if self.ydate:
            self.ax.yaxis_date()
            
        if self.oldLines.has_key(label):
            line.update_from(self.oldLines.pop(label))
        
    def updateLegend (self):
#.........这里部分代码省略.........
开发者ID:kinow,项目名称:SOSClient,代码行数:103,代码来源:utils.py


注:本文中的matplotlib.backends.backend_qt4agg.NavigationToolbar2QTAgg.findChildren方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。