Exemple #1
0
 def draw_path(self, gc, path, transform, rgbFace=None):
     path = transform.transform_path(path)
     points = path.vertices
     codes = path.codes
     bbox = gc.get_clip_rectangle()
     if bbox is not None:
         x, y, w, h = bbox.bounds
         clrt = np.array([x, x + w, y, y + h])
     else:
         clrt = np.array([0, self.width, 0, self.height])
     gr.setviewport(*clrt / self.size)
     gr.setwindow(*clrt)
     if rgbFace is not None and len(points) > 2:
         color = gr.inqcolorfromrgb(rgbFace[0], rgbFace[1], rgbFace[2])
         gr.settransparency(rgbFace[3])
         gr.setcolorrep(color, rgbFace[0], rgbFace[1], rgbFace[2])
         gr.setfillintstyle(gr.INTSTYLE_SOLID)
         gr.setfillcolorind(color)
         gr.drawpath(points, codes, fill=True)
     lw = gc.get_linewidth()
     if lw != 0:
         rgba = gc.get_rgb()[:4]
         color = gr.inqcolorfromrgb(rgba[0], rgba[1], rgba[2])
         gr.settransparency(rgba[3])
         gr.setcolorrep(color, rgba[0], rgba[1], rgba[2])
         if isinstance(gc._linestyle, str):
             gr.setlinetype(linetype[gc._linestyle])
         gr.setlinewidth(lw)
         gr.setlinecolorind(color)
         gr.drawpath(points, codes, fill=False)
Exemple #2
0
 def draw_path(self, gc, path, transform, rgbFace=None):
     path = transform.transform_path(path)
     points = path.vertices
     codes = path.codes
     bbox = gc.get_clip_rectangle()
     if bbox is not None and not np.any(np.isnan(bbox.bounds)):
         x, y, w, h = bbox.bounds
         clrt = np.array([x, x + w, y, y + h])
     else:
         clrt = np.array([0, self.width, 0, self.height])
     gr.setviewport(*clrt / self.size)
     gr.setwindow(*clrt)
     if rgbFace is not None and len(points) > 2:
         color = gr.inqcolorfromrgb(rgbFace[0], rgbFace[1], rgbFace[2])
         gr.settransparency(rgbFace[3])
         gr.setcolorrep(color, rgbFace[0], rgbFace[1], rgbFace[2])
         gr.setfillintstyle(gr.INTSTYLE_SOLID)
         gr.setfillcolorind(color)
         gr.drawpath(points, codes, fill=True)
     lw = gc.get_linewidth()
     if lw != 0:
         rgba = gc.get_rgb()[:4]
         color = gr.inqcolorfromrgb(rgba[0], rgba[1], rgba[2])
         gr.settransparency(rgba[3])
         gr.setcolorrep(color, rgba[0], rgba[1], rgba[2])
         if isinstance(gc._linestyle, str):
             gr.setlinetype(linetype[gc._linestyle])
         gr.setlinewidth(lw)
         gr.setlinecolorind(color)
         gr.drawpath(points, codes, fill=False)
Exemple #3
0
def _draw_legend():
    global _plt
    viewport = _plt.kwargs['viewport']
    num_labels = len(_plt.kwargs['labels'])
    location = _plt.kwargs.get('location', 1)
    gr.savestate()
    gr.selntran(0)
    gr.setscale(0)
    w = 0
    for label in _plt.kwargs['labels']:
        tbx, tby = gr.inqtextext(0, 0, label)
        w = max(w, tbx[2])

    num_lines = len(_plt.args)
    h = (num_lines + 1) * 0.03
    if location in (8, 9, 10):
        px = 0.5 * (viewport[0] + viewport[1] - w)
    elif location in (2, 3, 6):
        px = viewport[0] + 0.11
    else:
        px = viewport[1] - 0.05 - w
    if location in (5, 6, 7, 10):
        py = 0.5 * (viewport[2] + viewport[3] + h) - 0.03
    elif location in (3, 4, 8):
        py = viewport[2] + h
    else:
        py = viewport[3] - 0.06

    gr.setfillintstyle(gr.INTSTYLE_SOLID)
    gr.setfillcolorind(0)
    gr.fillrect(px - 0.08, px + w + 0.02, py + 0.03, py - 0.03 * num_lines)
    gr.setlinetype(gr.LINETYPE_SOLID)
    gr.setlinecolorind(1)
    gr.setlinewidth(1)
    gr.drawrect(px - 0.08, px + w + 0.02, py + 0.03, py - 0.03 * num_lines)
    i = 0
    gr.uselinespec(" ")
    for (x, y, z, c, spec) in _plt.args:
        gr.savestate()
        mask = gr.uselinespec(spec)
        if mask in (0, 1, 3, 4, 5):
            gr.polyline([px - 0.07, px - 0.01], [py, py])
        if mask & 2:
            gr.polymarker([px - 0.06, px - 0.02], [py, py])
        gr.restorestate()
        gr.settextalign(gr.TEXT_HALIGN_LEFT, gr.TEXT_VALIGN_HALF)
        if i < num_labels:
            gr.textext(px, py, _plt.kwargs['labels'][i])
            i += 1
        py -= 0.03
    gr.selntran(1)
    gr.restorestate()
Exemple #4
0
def _draw_legend():
    global _plt
    viewport = _plt.kwargs['viewport']
    num_labels = len(_plt.kwargs['labels'])
    location = _plt.kwargs.get('location', 1)
    gr.savestate()
    gr.selntran(0)
    gr.setscale(0)
    w = 0
    for label in _plt.kwargs['labels']:
        tbx, tby = gr.inqtextext(0, 0, label)
        w = max(w, tbx[2])

    num_lines = len(_plt.args)
    h = (num_lines + 1) * 0.03
    if location in (8, 9, 10):
        px = 0.5 * (viewport[0] + viewport[1] - w)
    elif location in (2, 3, 6):
        px = viewport[0] + 0.11
    else:
        px = viewport[1] - 0.05 - w
    if location in (5, 6, 7, 10):
        py = 0.5 * (viewport[2] + viewport[3] + h) - 0.03
    elif location in (3, 4, 8):
        py = viewport[2] + h
    else:
        py = viewport[3] - 0.06

    gr.setfillintstyle(gr.INTSTYLE_SOLID)
    gr.setfillcolorind(0)
    gr.fillrect(px - 0.08, px + w + 0.02, py + 0.03, py - 0.03 * num_lines)
    gr.setlinetype(gr.LINETYPE_SOLID)
    gr.setlinecolorind(1)
    gr.setlinewidth(1)
    gr.drawrect(px - 0.08, px + w + 0.02, py + 0.03, py - 0.03 * num_lines)
    i = 0
    gr.uselinespec(" ")
    for (x, y, z, c, spec) in _plt.args:
        gr.savestate()
        mask = gr.uselinespec(spec)
        if mask in (0, 1, 3, 4, 5):
            gr.polyline([px - 0.07, px - 0.01], [py, py])
        if mask & 2:
            gr.polymarker([px - 0.06, px - 0.02], [py, py])
        gr.restorestate()
        gr.settextalign(gr.TEXT_HALIGN_LEFT, gr.TEXT_VALIGN_HALF)
        if i < num_labels:
            gr.textext(px, py, _plt.kwargs['labels'][i])
            i += 1
        py -= 0.03
    gr.selntran(1)
    gr.restorestate()
Exemple #5
0
Fichier : mlab.py Projet : j-fu/gr
def _draw_legend():
    global _plt
    viewport = _plt.kwargs['viewport']
    num_labels = len(_plt.kwargs['labels'])
    gr.savestate()
    gr.selntran(0)
    gr.setscale(0)
    w = 0
    for label in _plt.kwargs['labels']:
        tbx, tby = gr.inqtextext(0, 0, label)
        w = max(w, tbx[2])

    px = viewport[1] - 0.05 - w
    py = viewport[3] - 0.06
    gr.setfillintstyle(gr.INTSTYLE_SOLID)
    gr.setfillcolorind(0)
    gr.fillrect(px - 0.08, px + w + 0.02, py + 0.03, py - 0.03 * num_labels)
    gr.setlinetype(1)
    gr.setlinecolorind(1)
    gr.setlinewidth(1)
    gr.drawrect(px - 0.08, px + w + 0.02, py + 0.03, py - 0.03 * num_labels)
    i = 0
    gr.uselinespec(" ")
    for (x, y, z, c, spec) in _plt.args:
        gr.savestate()
        mask = gr.uselinespec(spec)
        if mask in (0, 1, 3, 4, 5):
            gr.polyline([px - 0.07, px - 0.01], [py, py])
        if mask & 2:
            gr.polymarker([px - 0.06, px - 0.02], [py, py])
        gr.restorestate()
        gr.settextalign(gr.TEXT_HALIGN_LEFT, gr.TEXT_VALIGN_HALF)
        if i < num_labels:
            gr.textext(px, py, _plt.kwargs['labels'][i])
            i += 1
        py -= 0.03
    gr.selntran(1)
    gr.restorestate()
Exemple #6
0
def _draw_polar_axes():
    global _plt
    viewport = _plt.kwargs['viewport']
    diag = ((viewport[1]-viewport[0])**2 + (viewport[3]-viewport[2])**2)**0.5
    charheight = max(0.018 * diag, 0.012)


    window = _plt.kwargs['window']
    r_min, r_max = window[2], window[3]

    gr.savestate()
    gr.setcharheight(charheight)
    gr.setlinetype(gr.LINETYPE_SOLID)

    tick = 0.5 * gr.tick(r_min, r_max)
    n = int(round((r_max - r_min) / tick + 0.5))
    for i in range(n+1):
        r = i / n
        if i % 2 == 0:
            gr.setlinecolorind(88)
            if i > 0:
                gr.drawarc(-r, r, -r, r, 0, 359)
            gr.settextalign(gr.TEXT_HALIGN_LEFT, gr.TEXT_VALIGN_HALF)
            x, y = gr.wctondc(0.05, r)
            gr.text(x, y, "%g" % (r_min + i * tick))
        else:
            gr.setlinecolorind(90)
            gr.drawarc(-r, r, -r, r, 0, 359)
    for alpha in range(0, 360, 45):
        sinf = np.sin(np.radians(alpha+90))
        cosf = np.cos(np.radians(alpha+90))
        gr.polyline([sinf, 0], [cosf, 0])
        gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_HALF)
        x, y = gr.wctondc(1.1 * sinf, 1.1 * cosf)
        gr.textext(x, y, "%d^o" % alpha)
    gr.restorestate()
Exemple #7
0
def _draw_polar_axes():
    global _plt
    viewport = _plt.kwargs['viewport']
    diag = ((viewport[1]-viewport[0])**2 + (viewport[3]-viewport[2])**2)**0.5
    charheight = max(0.018 * diag, 0.012)


    window = _plt.kwargs['window']
    r_min, r_max = window[2], window[3]

    gr.savestate()
    gr.setcharheight(charheight)
    gr.setlinetype(gr.LINETYPE_SOLID)

    tick = 0.5 * gr.tick(r_min, r_max)
    n = int(round((r_max - r_min) / tick + 0.5))
    for i in range(n+1):
        r = i / n
        if i % 2 == 0:
            gr.setlinecolorind(88)
            if i > 0:
                gr.drawarc(-r, r, -r, r, 0, 359)
            gr.settextalign(gr.TEXT_HALIGN_LEFT, gr.TEXT_VALIGN_HALF)
            x, y = gr.wctondc(0.05, r)
            gr.text(x, y, "%g" % (r_min + i * tick))
        else:
            gr.setlinecolorind(90)
            gr.drawarc(-r, r, -r, r, 0, 359)
    for alpha in range(0, 360, 45):
        sinf = np.sin(np.radians(alpha+90))
        cosf = np.cos(np.radians(alpha+90))
        gr.polyline([sinf, 0], [cosf, 0])
        gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_HALF)
        x, y = gr.wctondc(1.1 * sinf, 1.1 * cosf)
        gr.textext(x, y, "%d^o" % alpha)
    gr.restorestate()