コード例 #1
0
ファイル: staticPlot.py プロジェクト: xgds/xgds_plot
def writePlotData(out,
                  seriesId,
                  widthPix=None,
                  heightPix=None,
                  minTime=None,
                  maxTime=None):
    if widthPix is None:
        widthPix = 800
    if heightPix is None:
        heightPix = 120

    xinch = float(widthPix) / 100
    yinch = float(heightPix) / 100
    fig = plt.figure()

    meta = TIME_SERIES_LOOKUP[seriesId]
    queryClass = getClassByName(meta['queryType'])
    queryManager = queryClass(meta)
    valueClass = getClassByName(meta['valueType'])
    valueManager = valueClass(meta, queryManager)

    recs = queryManager.getData(minTime=minTime,
                                maxTime=maxTime)
    timestamps = [epochMsToMatPlotLib(queryManager.getTimestamp(rec))
                  for rec in recs]
    vals = [valueManager.getValue(rec)
            for rec in recs]

    plt.plot(timestamps, vals)

    ax = fig.gca()
    ax.grid(True)
    xmin, xmax, ymin, ymax = ax.axis()
    if minTime:
        xmin = epochMsToMatPlotLib(minTime)
    if maxTime:
        xmax = epochMsToMatPlotLib(maxTime)
    if ymin == 0 and ymax == 1:
        # HACK styling special case
        ymin = -0.1
        ymax = 1.1
    ax.axis([xmin, xmax, ymin, ymax])

    pylabUtil.setXAxisDate()
    plt.title(queryManager.getValueName(meta['valueField']))

    logging.info('writePlotData: writing image')
    plt.setp(fig, figwidth=xinch, figheight=yinch)
    fig.savefig(out,
                format='png',
                bbox_inches='tight',
                dpi=100,
                pad_inches=0.05,
                # transparent=True,
                )

    logging.info('writePlotData: releasing memory')
    fig.clf()
    plt.close(fig)
コード例 #2
0
ファイル: profiles.py プロジェクト: xgds/xgds_plot
def getContourPlotImage(out, x, y, z,
                        xi, yi, zi,
                        labelx, labely,
                        sizePixels,
                        showSamplePoints=True):
    xpix, ypix = sizePixels
    xinch, yinch = xpix / 100, ypix / 100
    fig = plt.figure()

    # suppress outliers
    minLevel = percentile(z, 1.0)
    maxLevel = percentile(z, 99.0)
    logging.info('getContourPlotImage minLevel=%s maxLevel=%s', minLevel, maxLevel)
    norm = matplotlib.colors.Normalize(minLevel, maxLevel)

    dist = maxLevel - minLevel
    minPad = minLevel - 0.05 * dist
    maxPad = maxLevel + 0.05 * dist
    cappedZi = np.maximum(zi, minPad)
    cappedZi = np.minimum(cappedZi, maxPad)

    logging.info('getContourPlotImage: plotting data')
    ax = fig.gca()
    contours = ax.contourf(xi, yi, cappedZi, 256, norm=norm)
    pylabUtil.setXAxisDate()

    fig.colorbar(contours)

    if showSamplePoints:
        logging.info('getContourPlotImage: plotting sample points')

        # suppress scatterplot points outside the contourf grid
        inRange = reduce(np.logical_and,
                         [xi.min() <= x,
                          x <= xi.max(),
                          yi.min() <= y,
                          y <= yi.max()],
                         True)
        rng = np.where(inRange)

        ax.hold(True)
        # add scatterplot sample points to figure
        ax.scatter(x[rng], y[rng], s=0.5, c='k')

    # force the plot limits we want. note the inversion of yi.max() and yi.min()
    # so increasing depth is down.
    logging.info('getContourPlotImage: configuring axes')
    ax.axis([xi.min(), xi.max(), yi.max(), yi.min()])

    logging.info('getContourPlotImage: writing image')
    plt.setp(fig, figwidth=xinch, figheight=yinch)
    fig.savefig(out,
                format='png',
                bbox_inches='tight',
                dpi=100,
                pad_inches=0.05,
                # transparent=True,
                )

    logging.info('getContourPlotImage: releasing memory')
    fig.clf()
    plt.close(fig)