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


Python FigureCanvasAgg.print_svg方法代码示例

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


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

示例1: render

# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import print_svg [as 别名]
    def render(self, t = 'png'):
        canvas = FigureCanvas(self.fig)
        output = StringIO.StringIO()

        with Timer() as duration:
            if t == 'svg':
                canvas.print_svg(output)
            if t == 'pdf':
                canvas.print_pdf(output)
            else:
                canvas.print_png(output)

        app.logger.debug("Generating %s took %d ms", t.upper(), duration.miliseconds())

        return output.getvalue()
开发者ID:goldmann,项目名称:collector,代码行数:17,代码来源:graph.py

示例2: draw_custom_graph

# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import print_svg [as 别名]
def draw_custom_graph(user_agents):
    plot_x_y = []

    # requests = log_parser.get_log_dicts(user_agent = r'SiteSucker.*')
    for user_agent in user_agents:
        requests = logger.get_log_dicts(user_agent=user_agent)
        first_date = None
        x = []
        y = []
        for index, request in enumerate(requests):
            if index is not 0:
                x.append(time_delta(request['datetime'], first_date))
            else:
                first_date = request['datetime']
                x.append(0)
            y.append(index)
        plot_x_y.append({
            'x': x,
            'y': y
        })

    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)

    current_index = 0
    for xy in plot_x_y:
        # todo: Use different color (not only random) and add the ability to choose multiple user_agent.
        ax.plot(
            xy['x'], xy['y'],
            color=graph_colors[current_index % len(graph_colors)],
            label=user_agents[current_index]
        )
        ax.legend(framealpha=0.5, loc=4, prop={'size': 8})
        current_index += 1

    plt.xlabel('Delta Time (seconds)')
    plt.ylabel('Number of requests')

    ax.xaxis.set_major_formatter(formatter)

    output = StringIO.StringIO()
    canvas = FigureCanvas(fig)
    canvas.print_svg(output)
    return output
开发者ID:vschiavoni,项目名称:crawler-benchmark,代码行数:46,代码来源:graph.py

示例3: save_plot

# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import print_svg [as 别名]
def save_plot(fig, output_file_prefix):
    canvas = FigureCanvasAgg(fig)        
    png_path = output_file_prefix + '.png'
    canvas.print_png(png_path, dpi=72)        
    svg_path = output_file_prefix + '.svg'
    canvas.print_svg(svg_path, dpi=150)
开发者ID:theunissenlab,项目名称:tlab,代码行数:8,代码来源:plot.py

示例4: wrapper

# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import print_svg [as 别名]
 def wrapper(*args, **kwargs):
     fig = view(*args, **kwargs)
     canvas = FigureCanvas(fig)
     response = HttpResponse(content_type='image/svg+xml')
     canvas.print_svg(response)
     return response
开发者ID:bovine,项目名称:flightloggin2,代码行数:8,代码来源:image_formats.py

示例5: summary_plot

# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import print_svg [as 别名]

#.........这里部分代码省略.........
    print 'legend :: %s(%s)' % (legend.__class__.__name__, legend)
    ## GUBED

    fig = None
    try:
        # init and checks
        bm = get_object_or_404(Benchmark.objects.all(), id=bm_pk)
        tr_list = bm.trial_set.order_by('parameter')
        bt_list = bm.batch_set.filter(status=Benchmark.STATUS.public)
        if request.user.is_authenticated():
            eb_list_self = bm.batch_set.filter(status=Benchmark.STATUS.private)
            if not request.user.is_superuser:
                eb_list_self = eb_list_self.filter(owner=request.user)
            bt_list |= eb_list_self
        bt_list.order_by('id')
        param_labels = [t.parameter for t in tr_list]
        np = len(param_labels)
        y_max = 1.

        # build figure
        fig = Figure(
            figsize=(5, 5),
            facecolor='white',
            edgecolor='white',
            frameon=False)
        #ax = fig.add_subplot(111)
        ax = fig.add_axes([.15, .1, .8, .8])
        ax.set_color_cycle(PLOT_COLORS)

        # plot data
        if mode is None or (mode is not None and mode not in ['error_sum',
                                                              'FPAEno',
                                                              'FNno',
                                                              'FP',
                                                              'FPAEo',
                                                              'FNo']):
            mode = 'error_sum'
        for bt in bt_list:
            y_curve = [nan] * np
            for ev in bt.evaluation_set.all():
                try:
                    y_curve[tr_list.index(ev.trial)] = ev.summary_table()[mode]
                except:
                    pass
            if nansum(y_curve) >= 0:
                # TODO: fix "empty" evaluation batches!!
                y_max = nanmax(y_curve + [y_max])
                #y_curve = map(lambda x: x + 1.0, y_curve)
                #ax.semilogy(y_curve, 'o-', label='EB #%s' % eb.id)
                ax.plot(y_curve, 'o-', label='EB #%s' % bt.id)

        # beautify Y-axis
        ax.set_ylabel('Error Count')
        y_margin = y_max * 0.05
        ax.set_ylim(-y_margin, y_max + y_margin)
        # beautify X-axis
        ax.set_xlabel(bm.parameter)
        x_margin = np * 0.05
        ax.set_xlim(-x_margin, (1 + .5 * (legend is True)) * np + x_margin - 1)
        ax.set_xticks(range(np))
        ax.set_xticklabels(param_labels)
        # figure title
        title = {
            'error_sum': 'Total Error',
            'FPAEno': 'Classification Error (NO)',
            'FNno': 'False Negative (NO)',
            'FP': 'False Positive (NO)',
            'FPAEo': 'Classification Error (O)',
            'FNo': 'False Negative (O)',
        }.get(mode, 'Total Error')
        ax.set_title(title)
        if legend is True:
            ax.legend(
                loc='upper center',
                ncol=2,
                fancybox=True,
                bbox_to_anchor=(.90, 1),
                numpoints=1,
                prop={'size': 8},
            )
        ax.grid()

        ## DEBUG
        #print 'DPI:', fig.get_dpi(), 'y_max', y_max
        ## GUBED
    except:
        import sys, traceback

        traceback.print_exception(*sys.exc_info())
        sys.exc_clear()
    finally:
        #response = HttpResponse(content_type='image/png')
        response = HttpResponse(content_type='image/svg+xml')
        try:
            canvas = FigureCanvas(fig)
            #canvas.print_png(response)
            canvas.print_svg(response)
        except:
            pass
        return response
开发者ID:G-Node,项目名称:spike,代码行数:104,代码来源:views.py

示例6: histogram

# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import print_svg [as 别名]
def histogram(work_id, extension):
    print 'request.path', request.path
    print extension 
    # import ipdb; ipdb.set_trace()

    work = mysession.query(Work).filter(Work.work_id == work_id).one()
    print "work", work.long_title

    word_counts = []
    for paragraph in mysession.query(Paragraph).filter(Paragraph.work_id == work_id):
        word_counts.append(paragraph.word_count)

    (counts, bins) = np.histogram(word_counts, bins = 20)

    df = pd.DataFrame(counts, index=bins[0:-1])

    if extension == 'json':
        # print "counts", counts
        # print "bins", bins

        # bar = vincent.Bar(list(counts))
        bar = vincent.Bar(df)
        # bar.axes.extend([vincent.Axis(type='y', scale='y'), vincent.Axis(type='x', scale='x')])

        # FIXME this is probably caused by a new vincent API
	# vincent 0.3.0 works great!
        #props = vincent.AxisProperties(labels=ValueRef(value='left'))
        props = vincent.AxisProperties(labels=PropertySet(
                         align = ValueRef(value='left'),
                         angle = ValueRef(value=90),
                         baseline = ValueRef(value='middle'),
                         font_size = ValueRef(value=9)))
        bar.axes[0].properties = props

	bar.axes[1].properties = vincent.AxisProperties(labels=PropertySet(font_size = ValueRef(value=9)))
      
	bar.axes[1].title_offset = 40
        bar.axes[0].title_offset = 40
	bar.axes[0].format = ".0f"
        bar.height = 150
        bar.width = 170
      # "height": 400,
      # "width": 500,

        bar.axis_titles(x='Bins', y='Frequency')
	#bar.axes.extend([Axis(type='x', ), Axis(type='y', )])

        j = bar.to_json()
        # return the histogram of word frequency per paragraph for a given work_id 
        # return 'work_id %s' % work_id

        resp = Response(j, status=200, mimetype='application/json')    
        return resp

    elif extension == 'png':

        fig = Figure(figsize = (8, 6))
        axis = fig.add_subplot(1, 1, 1)
        
        axis.hist(word_counts, bins=20)
        # axis = df.hist()
        canvas = FigureCanvas(fig)
        output = StringIO.StringIO()
        canvas.print_png(output)
        response = make_response(output.getvalue())
        response.mimetype = 'image/png'
        return response

    elif extension == 'svg':

        fig = Figure(figsize = (8, 6))
        axis = fig.add_subplot(1, 1, 1)
        axis.set_ylabel("Frequency")
        axis.set_xlabel("Bins")
        axis.hist(word_counts, bins=20)
        # axis = df.hist()
        canvas = FigureCanvas(fig)
        output = StringIO.StringIO()
        canvas.print_svg(output)
        response = make_response(output.getvalue())
        response.mimetype = 'image/svg+xml'
        return response

    else:
        return "Resource not found"
开发者ID:adlukasiak,项目名称:shakespeare-navigator,代码行数:87,代码来源:shakespeare.py


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