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


Python Figure.findobj方法代码示例

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


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

示例1: plot_realtime_gammaray

# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import findobj [as 别名]
def plot_realtime_gammaray(request, object_id) :

    well = Well.objects.get(pk=object_id)
    wltz = pytz.timezone(well.timezone)
    gammas = []    
    times = []

    ragg = ToolMWDRealTime.objects.filter(well=well, type='gammaray').aggregate(Max('time_stamp'))
    hoursago = (ragg['time_stamp__max'] or datetime.utcnow()) - timedelta(hours=1)
    r = ToolMWDRealTime.objects.filter(well=well, type='gammaray', time_stamp__gt=hoursago).order_by('time_stamp')    

    # System goes to 100% memory used if 0-1 points are plotted
    if len(r) < 2 :
        return render_to_response('message.html', {'message': 'No Data to graph'})
    
    [gammas.append(v.value) for v in r]    
    [times.append(v.time_stamp) for v in r]    

    def depth_formatter(time_stamp, arg2) :
        time_stamp = matplotlib.dates.num2date(time_stamp)
        time_stamp = time_stamp.replace(tzinfo=None)
        wlt = pytz.utc.localize(time_stamp).astimezone(wltz).replace(tzinfo=None)
        ftime = wlt.strftime('%H:%M')
        
        try :            
            lower = WITS0.objects.filter(well=well, recid=1, itemid=8, time_stamp__lt = time_stamp ).order_by('-time_stamp')[0]
            higher = WITS0.objects.filter(well=well, recid=1, itemid=8, time_stamp__gt = time_stamp ).order_by('time_stamp')[0]
        except:            
            return '%s / No Dpth' % ftime

        # Linear Interpolation where x = seconds and y = depth    
        x = mktime(time_stamp.timetuple())
        xa = mktime(lower.time_stamp.timetuple())
        xb = mktime(higher.time_stamp.timetuple())

        ya = float(lower.value)
        yb = float(higher.value)
        
        depth = ya + ((x - xa) * (yb - ya))/(xb - xa)
        
        return '%s / %s' % (ftime, str(int(depth)) )

    fig = Figure()
    canvas = FigureCanvas(fig)
    ax = fig.add_axes([0.4, 0.08 ,0.55 ,0.85])
    ax.plot(gammas, times)
    wlt = pytz.utc.localize(ragg['time_stamp__max'] or datetime.utcnow()).astimezone(wltz).replace(tzinfo=None)
    ftime = wlt.strftime('%Y/%m/%d %H:%M')
    title = 'Gamma Ray\n' + ftime
    ax.set_title(title)
    ax.grid(True)
    ax.set_xlabel('Gamma Ray (counts/sec)')
    ax.set_ylabel('Time / Depth (ft)')    
    formatter = dates.DateFormatter('%H:%M') 
    ax.yaxis.set_major_formatter(FuncFormatter(depth_formatter))
    ax.set_ylim(matplotlib.dates.date2num(times[-1]),matplotlib.dates.date2num(times[0]))
    ax.yaxis.set_major_locator( LinearLocator( numticks=10 ) )
    ax.xaxis.set_major_locator( LinearLocator( numticks=5 ) )

    going_down = True
    prev_depth = -999
    for t in times :
        try :            
            lower = WITS0.objects.filter(well=well, recid=1, itemid=8, time_stamp__lt = t ).order_by('-time_stamp')[0]
            higher = WITS0.objects.filter(well=well, recid=1, itemid=8, time_stamp__gt = t ).order_by('time_stamp')[0]
        except:            
            continue

        # Linear Interpolation where x = seconds and y = depth    
        x = mktime(t.timetuple())
        xa = mktime(lower.time_stamp.timetuple())
        xb = mktime(higher.time_stamp.timetuple())

        ya = float(lower.value)
        yb = float(higher.value)
        
        depth = ya + ((x - xa) * (yb - ya))/(xb - xa)
        #print depth, going_down
        if depth < prev_depth :
            if going_down :
                going_down=False
                t1 = t

        if depth >= prev_depth and not going_down :
            going_down=True
            t2 = t                        
            ax.axhspan(matplotlib.dates.date2num(t1), matplotlib.dates.date2num(t2), facecolor='#FF0033', alpha=0.25)

        prev_depth = depth

    if not going_down :
        ax.axhspan(matplotlib.dates.date2num(t1), matplotlib.dates.date2num(times[-1]), facecolor='#FF0033', alpha=0.25)
    
    fontsize=8

    for o in fig.findobj(text.Text) :
        o.set_fontsize(fontsize)
    
    fig.set_size_inches( (3, 5) )
        
#.........这里部分代码省略.........
开发者ID:xkenneth,项目名称:tdsurface,代码行数:103,代码来源:views.py


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