Esempio n. 1
0
 def text_extents(self, text, font):
     # This is not completely accurate because it depends a lot
     # on the renderer used, but that is complicated under Mpl
     t = textpath.TextPath((0, 0), text, size=font.fontsize,
                           prop=font.fontname)
     bb = t.get_extents()
     wd, ht = bb.width, bb.height
     return (wd, ht)
Esempio n. 2
0
 def set_yspace_regiongroups(self):
     maxwidth = 0
     for key, val in self.dict_brain_areas.items():
         mx = val[0]
         t = tp.TextPath((0,0), mx, size=self.fontsize_area)
         w = t.get_extents().width
         if w > maxwidth:
             maxwidth = w
     self.yspace_regiongroups = np.cos(np.pi*self.rotregion_offset/180)*maxwidth/8
Esempio n. 3
0
 def set_xspace_middle(self):
     maxwidth = 0
     for s in self.list_subjects:
         t = tp.TextPath((0,0), s, size=self.fontsize_area)
         w = t.get_extents().width
         if w > maxwidth:
             maxwidth = w
     
     self.xspace_middle = maxwidth/8
Esempio n. 4
0
    def draw_bars(self, ax):
        xf = self.xmapping()
        yf = self.ymapping()
        factor = self.stretch / 4000.0
        print("Factor ", factor, "=", self.stretch, "/2000")
        for sp in self.spans:
            if sp["invisibleBar"]:
                ax.bar(xf(sp["start"]),
                       yf(sp["cat"], sp["half"])[1] -
                       yf(sp["cat"], sp["half"])[0],
                       xf(sp["end"]) - xf(sp["start"]),
                       color="white",
                       edgecolor="white",
                       bottom=yf(sp["cat"], sp["half"])[0])
            else:
                ax.bar(xf(sp["start"]),
                       yf(sp["cat"], sp["half"])[1] -
                       yf(sp["cat"], sp["half"])[0],
                       xf(sp["end"]) - xf(sp["start"]),
                       color=sp["color"],
                       bottom=yf(sp["cat"], sp["half"])[0])

            if xf(sp["start"]) >= pyplot.xlim()[0] and xf(sp["end"]) - xf(
                    sp["start"]) > .5 and sp["caption"] != "":
                t = textpath.TextPath((0, 0), " " + sp["caption"], size=40)
                if sp["invisibleBar"]:
                    pyplot.text(sp["start"] + .1,
                                yf(sp["cat"], sp["half"])[1],
                                sp["caption"],
                                ha='left',
                                va='top',
                                rotation=-25,
                                size=20)
                elif t.get_extents().width * factor < xf(sp["end"]) - xf(
                        sp["start"]):
                    pyplot.text(xf(sp["start"]) + 1,
                                yf(sp["cat"], sp["half"])[0] + .05,
                                sp["caption"],
                                ha='left',
                                va='bottom',
                                size=40)
                else:
                    pyplot.text(sp["start"] + .1,
                                yf(sp["cat"], sp["half"])[0] + .05,
                                sp["caption"],
                                ha='left',
                                va='bottom',
                                rotation='vertical',
                                size=16)
Esempio n. 5
0
    def render(self, ax=None):
        if ax is None:
            ax = self._ax
        else:
            self._ax = ax

        symbol = self.position[0].symbol
        tpath = textpath.TextPath((self.x, self.y),
                                  symbol,
                                  size=self.options.get('size'),
                                  prop=font_options)
        tpatch = mpatches.PathPatch(tpath,
                                    color=self.options.get('color', 'black'),
                                    lw=0.25)
        self._patch = tpatch
        ax.add_patch(tpatch)
        return ax
Esempio n. 6
0
 def draw_c_term_label(self,
                       index,
                       label,
                       height=0.25,
                       length=0.75,
                       size=0.45,
                       color='black',
                       **kwargs):
     x = self.next_between(index)
     y = (self.y * 2) + height
     length *= self.step_coefficient
     label_x = x + length / 10.
     label_y = y + 0.2
     tpath = textpath.TextPath((label_x, label_y),
                               label,
                               size=size,
                               prop=font_options)
     tpatch = mpatches.PathPatch(tpath, color='black', lw=0.25)
     self.ax.add_patch(tpatch)