Пример #1
0
def CreateLegendPlot(measurements, title_font="modern 12",
                     title="Legend", legend_font="modern 9"):
    """ Plot contour for two axes of an RTDC measurement
    
    Parameters
    ----------
    measurements : list of instances of RTDS_DataSet
        Contains color information and titel.
        - mm.Configuration["Plotting"]["Contour Color"]
        - mm.title
    """
    aplot = ca.Plot()
    # normalize our data in range zero to 100
    aplot.range2d.high=(100,100)
    aplot.range2d.low=(0,0)
    aplot.title = title
    aplot.title_font = title_font
    leftmarg = 7
    toppos = 90
    increment = 10
    for mm in measurements:
        if mm.Configuration["Plotting"]["Scatter Title Colored"]:
            mmlabelcolor = mm.Configuration["Plotting"]["Contour Color"]
        else:
            mmlabelcolor = "black"
        alabel = ca.DataLabel(
                        component=aplot, 
                        label_position="right",
                        data_point=(leftmarg,toppos),
                        padding_bottom=0,
                        marker_size=5,
                        bgcolor="transparent",
                        border_color="transparent",
                        label_text="  "+mm.title,
                        font=legend_font,
                        text_color=mmlabelcolor,
                        marker="circle",
                        marker_color="transparent",
                        marker_line_color=mm.Configuration["Plotting"]["Contour Color"],
                        show_label_coords=False,
                        arrow_visible=False
                              )
        toppos -= increment
        aplot.overlays.append(alabel)
    
    aplot.padding_left = 0
    aplot.y_axis = None
    aplot.x_axis = None
    aplot.x_grid = None
    aplot.y_grid = None

    # pan tool
    pan = cta.PanTool(aplot, drag_button="left")
    aplot.tools.append(pan)

    return aplot
Пример #2
0
 def _add_data_labels(self, renderer, fraction):
     idx = renderer.index._data
     val = renderer.value._data
     for i, v in enumerate(fraction):
         label = _chaco.DataLabel(
             component=renderer,
             data_point=(idx[i], val[i]),
             label_text="{}%".format(v),
             marker_visible=False,
             border_visible=False,
             show_label_coords=False,
             bgcolor=(0.5, 0.5, 0.5, 0.0),
         )
         renderer.overlays.append(label)
Пример #3
0
 def _add_data_labels(self, renderer, fraction, pec):
     idx = renderer.index._data
     val = renderer.value._data
     for i, v in enumerate(fraction):
         if not v:
             continue
         p = pec[i]
         label = _chaco.DataLabel(
             component=renderer,
             data_point=(idx[i], val[i]),
             label_text="{0}%({1})".format(p, v),
             label_position='bottom',
             arrow_visible=False,
             marker_visible=False,
             border_visible=False,
             show_label_coords=False,
             bgcolor=(0.5, 0.5, 0.5, 0.0),
         )
         renderer.overlays.append(label)
Пример #4
0
    def create_data_label(self, xp, yp, d, di):
        nform = "[%(x).5g, %(y).5g]"
        if self.nfiles() - 1 or self.overlay_plot_data:
            lform = "({0}) {1}".format(self.get_file_name(d), nform)
        else:
            lform = nform
        label = capi.DataLabel(component=self.container,
                               data_point=(xp, yp),
                               label_position="bottom right",
                               border_visible=False,
                               bgcolor="transparent",
                               label_format=lform,
                               marker_color=tuple(COLOR_PALETTE[(d + di) %
                                                                10]),
                               marker_line_color="transparent",
                               marker="diamond",
                               arrow_visible=False)

        self.time_data_labels[d].append(label)
        self.container.overlays.append(label)
        return
Пример #5
0
def legend_plot(measurements, title_font="modern 12",
                title="Legend", legend_font="modern 9"):
    """Plot legend for an RT-DC data set
    
    Parameters
    ----------
    measurements : list of RTDCBase
        Contains color information and titel.
        - mm.config["plotting"]["contour color"]
        - mm.title
    """
    # The legend is actually a list of plot labels
    aplot = ca.Plot()
    # normalize range from zero to 100 for convenience
    aplot.range2d.high=(100,100)
    aplot.range2d.low=(0,0)
    aplot.title = title
    aplot.title_font = title_font
    leftmarg = 7
    fname, fsize = legend_font.rsplit(" ", 1)
    fsize = int(fsize)
    autoscale = measurements[0].config["plotting"]["legend autoscaled"]
    if autoscale and len(measurements)>=10:
        # This case makes the legend entries fit into the plot window 
        lm = len(measurements)
        marker_size = int(np.floor(5/lm*9))
        fsize = int(np.floor(fsize/lm*9))
        increment = 100/(lm+1)
        # This is a heuristic setting that works for most plots:
        # (not sure how chaco defines marker positions)
        label_position = -6*(5/lm*9)**.3
    else:
        marker_size = 5
        increment = 10
        label_position = -10
    legend_font = " ".join([fname, str(fsize)])
    toppos = 100 - increment
        
    for mm in measurements:
        if mm.config["plotting"]["scatter title colored"]:
            mmlabelcolor = mm.config["plotting"]["contour color"]
        else:
            mmlabelcolor = "black"
        alabel = ca.DataLabel(
                        component=aplot, 
                        label_position=[0,label_position],
                        data_point=(leftmarg,toppos),
                        padding_bottom=0,
                        marker_size=marker_size,
                        bgcolor="transparent",
                        border_color="transparent",
                        label_text="  "+mm.title,
                        font=legend_font,
                        text_color=mmlabelcolor,
                        marker="circle",
                        marker_color="transparent",
                        marker_line_color=mm.config["plotting"]["contour color"],
                        show_label_coords=False,
                        arrow_visible=False
                              )
        toppos -= increment
        aplot.overlays.append(alabel)
    
    aplot.padding_left = 0
    aplot.y_axis = None
    aplot.x_axis = None
    aplot.x_grid = None
    aplot.y_grid = None

    # pan tool
    pan = cta.PanTool(aplot, drag_button="left")
    aplot.tools.append(pan)

    return aplot