Ejemplo n.º 1
0
def draw_box_with_text(ax, x, y, width, height, text, color='black', zorder=3, text_fontsize=15,
                       text_color="black", edgecolor='black', linewidth=4, linestyle=None):

    alignment = {'horizontalalignment': 'center', 'verticalalignment': 'center'}

    font_1 = font_0.copy()
    font_1.set_size(text_fontsize)
    font_1.set_weight('bold')

    codes = [Path.MOVETO] + [Path.LINETO] * 3 + [Path.CLOSEPOLY]
    vertices = [(x, y), (x + width, y), (x + width, y - height), (x, y - height), (0, 0)]
    vertices = np.array(vertices, float)
    path = Path(vertices, codes)
    pathpatch = PathPatch(
        path, #facecolor='None',
        edgecolor=edgecolor, zorder=zorder,# lw=linewidth,
        linewidth=linewidth, linestyle=linestyle
    )
    pathpatch.set_fill(False)
    ax.text(x + width / 2.0, y - height / 2.0,
            text,
            color=text_color,
            fontproperties=font_1,
            **alignment)
    ax.add_patch(pathpatch)
Ejemplo n.º 2
0
def join_lines(ax, min_idx, max_idx, y, color='black'):
    codes = [Path.MOVETO] + [Path.LINETO]
    vertices = [(min_idx, y), (max_idx, y)]
    vertices = np.array(vertices, float)
    path = Path(vertices, codes)
    pathpatch = PathPatch(path, facecolor='None', edgecolor=color, zorder=3, lw=4)
    pathpatch.set_fill(False)
    ax.add_patch(pathpatch)
Ejemplo n.º 3
0
def draw_line_1(ax, idx, y_min, y_max, color='black', zorder=3):
    codes = [Path.MOVETO] + [Path.LINETO]
    vertices = [(idx, y_max), (idx, y_min)]
    vertices = np.array(vertices, float)
    path = Path(vertices, codes)
    pathpatch = PathPatch(path, facecolor='None', edgecolor=color, zorder=zorder, lw=4)
    pathpatch.set_fill(False)
    ax.add_patch(pathpatch)
Ejemplo n.º 4
0
def make_path(d, style):
    items = []
    for c in d.split():
        if c.upper() in codemap:
            items.append(c)
        else:
            x, y = (float(v) for v in c.split(","))
            items.append((x, y))
    codes = []
    vertices = []            
    i = 0
    lx, ly = 0, 0
    last_code = "M"
    while i < len(items):
        code = items[i]
        if not isinstance(code, str):
            code = last_code
        else:
            i += 1
        ucode = code.upper()
        if code.isupper():
            relative = False
        else:
            relative = True
        if ucode in ("M", "L"):
            x, y = items[i]
            i += 1
            if relative:
                x += lx
                y += ly
            codes.append(codemap[ucode])
            vertices.append((x, y))
            lx, ly = x, y
        if ucode == "C":
            if not relative:
                points = items[i:i+3]
            else:
                points = [(_x + lx, _y + ly) for _x, _y in items[i:i+3]]
            codes.extend([codemap[ucode]]*3)
            vertices.extend(points)
            lx, ly = points[-1]
            i += 3
        if ucode == "Z":
            break
        last_code = code
        
    codes[0] = Path.MOVETO
    patch = PathPatch( Path(vertices, codes) )
    patch.set_linewidth( get_number(style.get("stroke-width", "1px") ) )
    fill =  style.get("fill", "none")
    if fill == "none":
        patch.set_fill( None )
    else:
        patch.set_facecolor( fill )
    edge = style.get("stroke", "none")
    patch.set_edgecolor(edge)

    return patch
def create_24_tachogram(gs1, row_number, timing, des1,
                    start_hour=None, stop_hour=None,
                    slice_color="black"):

    max_timing = np.max(timing)

    ax_24_tachogram = plt.subplot(gs1[row_number, :])
    ax_24_tachogram.set_color_cycle(['blue'])
    ax_24_tachogram.plot(timing, des1)
    ax_24_tachogram.ticklabel_format(style='sci', axis='x', scilimits=(0, max_timing))
    ax_24_tachogram.xaxis.set_ticks(np.arange(0, int(max_timing) + 1, 1))
    ax_24_tachogram.set_xlim(0, max_timing)

    font_1 = font_0.copy()
    font_1.set_size('11')
    font_1.set_weight('bold')

    y_lim = ax_24_tachogram.get_ylim()[1]
    if not start_hour == None:
        codes = [Path.MOVETO] + [Path.LINETO] * 3 + [Path.CLOSEPOLY]
        vertices = [(start_hour, y_lim - 20),
                    (stop_hour, y_lim - 20),
                    (stop_hour, 0),
                    (start_hour, 0), (0, 0)]
        vertices = np.array(vertices, float)
        path = Path(vertices, codes)
        pathpatch = PathPatch(path, facecolor='None', edgecolor=slice_color, zorder=3, lw=3)
        pathpatch.set_fill(False)
        ax_24_tachogram.add_patch(pathpatch)

    leg = ax_24_tachogram.legend(['$\mathbf{%s}$' % ("RR")], loc='upper left')
    #change legend font properties
    plt.setp(leg.get_texts(), fontsize='large')
    plt.setp(leg.get_texts(), fontweight='bold')

    ax_24_tachogram.set_xlabel(u"Czas [godziny]", fontproperties = font_1)
    ax_24_tachogram.set_ylabel(u"RR [ms]", fontproperties = font_1)

    tachogram_label_pos = 18
    font_1 = font_0.copy()
    font_1.set_size('18')
    font_1.set_weight('bold')
    ax_24_tachogram.text(tachogram_label_pos, y_lim - 200,
                      u"Tachogram - 24 godziny", fontproperties = font_1)
    bold_ticks_labels(ax_24_tachogram)


    return row_number + 1
Ejemplo n.º 6
0
def draw_box_with_text(ax,
                       x,
                       y,
                       width,
                       height,
                       text,
                       color='black',
                       zorder=3,
                       text_fontsize=15,
                       text_color="black",
                       edgecolor='black',
                       linewidth=4,
                       linestyle=None):

    alignment = {
        'horizontalalignment': 'center',
        'verticalalignment': 'center'
    }

    font_1 = font_0.copy()
    font_1.set_size(text_fontsize)
    font_1.set_weight('bold')

    codes = [Path.MOVETO] + [Path.LINETO] * 3 + [Path.CLOSEPOLY]
    vertices = [(x, y), (x + width, y), (x + width, y - height),
                (x, y - height), (0, 0)]
    vertices = np.array(vertices, float)
    path = Path(vertices, codes)
    pathpatch = PathPatch(
        path,  #facecolor='None',
        edgecolor=edgecolor,
        zorder=zorder,  # lw=linewidth,
        linewidth=linewidth,
        linestyle=linestyle)
    pathpatch.set_fill(False)
    ax.text(x + width / 2.0,
            y - height / 2.0,
            text,
            color=text_color,
            fontproperties=font_1,
            **alignment)
    ax.add_patch(pathpatch)
Ejemplo n.º 7
0
    def _render_on_subplot(self, subplot):
        """
        Render this Bezier path in a subplot.  This is the key function that
        defines how this Bezier path graphics primitive is rendered in matplotlib's
        library.

        TESTS::

            sage: bezier_path([[(0,1),(.5,0),(1,1)]])
            Graphics object consisting of 1 graphics primitive

        ::

            sage: bezier_path([[(0,1),(.5,0),(1,1),(-3,5)]])
            Graphics object consisting of 1 graphics primitive
        """
        from matplotlib.patches import PathPatch
        from matplotlib.path import Path
        from sage.plot.misc import get_matplotlib_linestyle

        options = dict(self.options())

        del options['alpha']
        del options['thickness']
        del options['rgbcolor']
        del options['zorder']
        del options['fill']
        del options['linestyle']

        bpath = Path(self.vertices, self.codes)
        bpatch = PathPatch(bpath, **options)
        options = self.options()
        bpatch.set_linewidth(float(options['thickness']))
        bpatch.set_fill(options['fill'])
        bpatch.set_zorder(options['zorder'])
        a = float(options['alpha'])
        bpatch.set_alpha(a)
        c = to_mpl_color(options['rgbcolor'])
        bpatch.set_edgecolor(c)
        bpatch.set_facecolor(c)
        bpatch.set_linestyle(get_matplotlib_linestyle(options['linestyle'], return_type='long'))
        subplot.add_patch(bpatch)
Ejemplo n.º 8
0
    def _render_on_subplot(self, subplot):
        """
        Render this Bezier path in a subplot.  This is the key function that
        defines how this Bezier path graphics primitive is rendered in matplotlib's
        library.

        TESTS::

            sage: bezier_path([[(0,1),(.5,0),(1,1)]])

        ::

            sage: bezier_path([[(0,1),(.5,0),(1,1),(-3,5)]])
        """
        from matplotlib.patches import PathPatch
        from matplotlib.path import Path
        from sage.plot.misc import get_matplotlib_linestyle

        options = dict(self.options())

        del options['alpha']
        del options['thickness']
        del options['rgbcolor']
        del options['zorder']
        del options['fill']
        del options['linestyle']

        bpath = Path(self.vertices, self.codes)
        bpatch = PathPatch(bpath, **options)
        options = self.options()
        bpatch.set_linewidth(float(options['thickness']))
        bpatch.set_fill(options['fill'])
        bpatch.set_zorder(options['zorder'])
        a = float(options['alpha'])
        bpatch.set_alpha(a)
        c = to_mpl_color(options['rgbcolor'])
        bpatch.set_edgecolor(c)
        bpatch.set_facecolor(c)
        bpatch.set_linestyle(
            get_matplotlib_linestyle(options['linestyle'], return_type='long'))
        subplot.add_patch(bpatch)
Ejemplo n.º 9
0
def create_zoom_plot(gs1, row_number, timing,
                     start_hour=None, stop_hour=None,
                     slice_color="black"):

    max_timing = np.max(timing)

    ax_zoom = plt.subplot(gs1[row_number, :])
    ax_zoom.set_axis_off()
    ax_zoom.set_frame_on(False)
    ax_zoom.set_xlim(0, max_timing)

    alignment = {'horizontalalignment': 'center', 'verticalalignment': 'center'}
    text_fontsize = 18

    font_1 = font_0.copy()
    font_1.set_size(text_fontsize)
    font_1.set_weight('bold')

    codes = [Path.MOVETO] + [Path.LINETO]
    vertices = [(start_hour, 1.0), (0, 0)]
    vertices = np.array(vertices, float)
    path = Path(vertices, codes)
    pathpatch = PathPatch(path, facecolor='None', edgecolor=slice_color, zorder=3, lw=3)
    pathpatch.set_fill(False)
    ax_zoom.add_patch(pathpatch)

    codes = [Path.MOVETO] + [Path.LINETO]
    vertices = [(stop_hour, 1.0), (max_timing, 0)]
    vertices = np.array(vertices, float)
    path = Path(vertices, codes)
    pathpatch = PathPatch(path, facecolor='None', edgecolor=slice_color, zorder=3, lw=3)
    pathpatch.set_fill(False)
    ax_zoom.add_patch(pathpatch)

#     ax_zoom.text(stop_hour-1, 0.3, u"2-godzinny wycinek tachogramu",
#                       fontproperties=font_1,
#                       **alignment
#                       #size=20
#                       )

    return row_number + 1
Ejemplo n.º 10
0
first_lw = 0.5
lws = np.linspace(first_lw, 4, max_idx + 1 + first_lw)[::-1]


for idx, lw in zip(range(max_idx - 1, -1, -1), lws):
    vertices = []
    codes = []
    codes = [Path.MOVETO] + [Path.LINETO] * 3 + [Path.CLOSEPOLY]
    vertices = [(idx, des1_max - des1_max / 10),
                (idx + 1, des1_max - des1_max / 10),
                (idx + 1, des1_min + des1_max / 10),
                (idx, des1_min + des1_max / 10), (0, 0)]
    vertices = np.array(vertices, float)
    path = Path(vertices, codes)
    pathpatch = PathPatch(path, facecolor='None', edgecolor='red', zorder=3, lw=lw)
    pathpatch.set_fill(False)
    ax_right_tachogram.add_patch(pathpatch)

leg = ax_right_tachogram.legend([u"$\mathbf{%s}$" % ("RR"), "Okno danych - 5 minut"],
                                 loc='upper left', numpoints=5)
plt.setp(leg.get_texts(), fontsize='large')
plt.setp(leg.get_texts(), fontweight='bold')

bold_ticks_labels(ax_right_tachogram, fontsize=15)

arrow_size = 4
arrow_window_right = mpatches.Arrow(max_idx / 2 - arrow_size / 2,
                                    des1_max - des1_max / 35,
                                    4, 0,
                                    width=100, color="red") #, zorder=3)
arrow_window_right.set_fill(True)
Ejemplo n.º 11
0
for idx, lw in zip(range(max_idx - 1, -1, -1), lws):
    vertices = []
    codes = []
    codes = [Path.MOVETO] + [Path.LINETO] * 3 + [Path.CLOSEPOLY]
    vertices = [(idx, des1_max - des1_max / 10),
                (idx + 1, des1_max - des1_max / 10),
                (idx + 1, des1_min + des1_max / 10),
                (idx, des1_min + des1_max / 10), (0, 0)]
    vertices = np.array(vertices, float)
    path = Path(vertices, codes)
    pathpatch = PathPatch(path,
                          facecolor='None',
                          edgecolor='red',
                          zorder=3,
                          lw=lw)
    pathpatch.set_fill(False)
    ax_right_tachogram.add_patch(pathpatch)

leg = ax_right_tachogram.legend(
    [u"$\mathbf{%s}$" % ("RR"), "Okno danych - 5 minut"],
    loc='upper left',
    numpoints=5)
plt.setp(leg.get_texts(), fontsize='large')
plt.setp(leg.get_texts(), fontweight='bold')

bold_ticks_labels(ax_right_tachogram, fontsize=15)

arrow_size = 4
arrow_window_right = mpatches.Arrow(max_idx / 2 - arrow_size / 2,
                                    des1_max - des1_max / 35,
                                    4,
Ejemplo n.º 12
0
def create_24_tachogram(gs1, row_number, timing, des1,
                        slice_color="black"):

    max_timing = np.max(timing)

    ax_24_tachogram = plt.subplot(gs1[row_number, :])
    ax_24_tachogram.set_color_cycle(['blue'])
    ax_24_tachogram.plot(timing, des1)
    ax_24_tachogram.ticklabel_format(style='sci', axis='x', scilimits=(0, max_timing))
    ax_24_tachogram.xaxis.set_ticks(np.arange(0, int(max_timing) + 1, 1))
    ax_24_tachogram.set_xlim(0, max_timing)

    font_1 = font_0.copy()
    font_1.set_size('13')
    font_1.set_weight('bold')

    alignment = {'horizontalalignment': 'center', 'verticalalignment': 'center'}

    y_lim_min = ax_24_tachogram.get_ylim()[0]
    y_lim_max = ax_24_tachogram.get_ylim()[1]
    shift = 50
    for position in positions:
        codes = [Path.MOVETO] + [Path.LINETO] * 3 + [Path.CLOSEPOLY]
        start_pos = position - 0.5
        stop_pos = position + 0.5
        vertices = [(start_pos, y_lim_max - shift),
                    (stop_pos, y_lim_max - shift),
                    (stop_pos, y_lim_min + shift),
                    (start_pos, y_lim_min + shift), (0, 0)]
        vertices = np.array(vertices, float)
        path = Path(vertices, codes)
        pathpatch = PathPatch(path, facecolor='None', edgecolor=slice_color, zorder=3, lw=3)
        pathpatch.set_fill(False)
        ax_24_tachogram.add_patch(pathpatch)

        ax_24_tachogram.text(position, y_lim_min + 2 * shift, u"5 min.", fontproperties=font_1,
                             **alignment)  # size=15)

    leg = ax_24_tachogram.legend(['$\mathbf{%s}$' % ("RR")], loc='upper left')
    # change legend font properties
    plt.setp(leg.get_texts(), fontsize='large')
    plt.setp(leg.get_texts(), fontweight='bold')

    ax_24_tachogram.set_xlabel(u"Czas [godziny]", fontproperties=font_1)
    ax_24_tachogram.set_ylabel(u"RR [ms]", fontproperties=font_1)

    tachogram_label_pos = 18
    font_1 = font_0.copy()
    font_1.set_size('18')
    font_1.set_weight('bold')
    ax_24_tachogram.text(0.85, 0.9, u"Tachogram - 24 godziny", fontproperties=font_1, transform=ax_24_tachogram.transAxes)  # size=15)

    arrow_size = 4.5
    head_width = 45
    tail_width = 25
    head_length = 40
    arrow_shift = 100
    pos_start = positions[2] + 0.75
    pos_stop = positions[3] - 0.75
    draw_simple_arrow(ax_24_tachogram,
                      # posA=(pos_x - arrow_size / 2.0, y_lim_max - head_width - arrow_shift),
                      # posB=(pos_x + arrow_size / 2.0, y_lim_max - head_width - arrow_shift),
                      posA=(pos_start, y_lim_max - head_width - arrow_shift),
                      posB=(pos_stop, y_lim_max - head_width - arrow_shift),
                      tail_width=tail_width, head_width=head_width,
                      head_length=head_length, color="red",
                      text=u"Kierunek przesuwania okna",
                      text_fontsize=12,
                      lw=2.0,
                      )

    # ax_24_tachogram.text(tachogram_label_pos, y_lim - 200,
    #                  u"Tachogram - 24 godziny", fontproperties = font_1)
    bold_ticks_labels(ax_24_tachogram, fontsize=13)

    return row_number + 1
Ejemplo n.º 13
0
def create_windowed_descriptors_tachogram(gs1, row_number, timing, des1, max_idx,
                                          sym_indexes, start_hour=None, stop_hour=None,
                                          sym_color="brown", asym_color="green"):

    first_lw = 0.5
    lws = np.linspace(first_lw, 4, max_idx + 1 + first_lw)[::-1]
    max_lws = max(lws)
    lws = [max_lws] * len(lws)

    only_2_hours = is_only_2_hours(start_hour, stop_hour)

    asym_indexes = [idx for idx in range(max_idx) if idx not in sym_indexes]

    max_timing = np.max(timing)
    des1_max = np.max(des1)
    des1_min = np.min(des1)

    # RIGHT TACHOGRAM START
    ax_windowed_desc = plt.subplot(gs1[row_number, 0])
    ax_windowed_desc.set_color_cycle(['blue', 'red'])
    ax_windowed_desc.plot(timing, des1)
    ax_windowed_desc.ticklabel_format(style='sci', axis='x', scilimits=(0, max_timing))
    ax_windowed_desc.xaxis.set_ticks(np.arange(0, int(max_timing)+1, 1))
    ax_windowed_desc.xaxis.set_ticks_position('top')
    ax_windowed_desc.xaxis.set_label_position('top')
    ax_windowed_desc.set_xlim(0, max_timing)

    font_1 = font_0.copy()
    font_1.set_size('11')
    font_1.set_weight('bold')

    if start_hour == None:
        x_label = u"Czas [godziny]"
    else:
        x_label = u"Czas [minuty]"
    ax_windowed_desc.set_xlabel(x_label, fontproperties=font_1)
    ax_windowed_desc.set_ylabel(u"Wartość [ms]", fontproperties=font_1)

    font_1 = font_0.copy()
    font_1.set_size('18')
    font_1.set_weight('bold')

    if start_hour == None:
        tach_label = u"Tachogram - 24 godziny"
        tachogram_label_pos = 19
    else:
        tach_label = u"Tachogram - fragment 2 godziny"
        tachogram_label_pos = 17

    y_lim = ax_windowed_desc.get_ylim()[1]
    ax_windowed_desc.text(tachogram_label_pos, y_lim - 100,
                          tach_label, fontproperties=font_1)

    for idx, lw in zip(range(max_idx - 1, -1, -1), lws):
        # if idx % window_step == 1:
        if not (idx % window_step == 0):
            continue
        vertices = []
        codes = []
        codes = [Path.MOVETO] + [Path.LINETO] * 3 + [Path.CLOSEPOLY]
        vertices = [(idx, des1_max - des1_max / 10),
                    (idx + window_step, des1_max - des1_max / 10),
                    (idx + window_step, des1_min + des1_max / 10),
                    (idx, des1_min + des1_max / 10), (0, 0)]
        vertices = np.array(vertices, float)
        path = Path(vertices, codes)
        pathpatch = PathPatch(path, facecolor='None', edgecolor='red', zorder=3, lw=lw)
        pathpatch.set_fill(False)
        ax_windowed_desc.add_patch(pathpatch)

    min_y = 50
    max_y = 400

    zero_ones = [("0" if idx in sym_indexes else "A") for idx in range(max_idx)]

    zero_one_y = des1_min - 50

    alignment = {'horizontalalignment': 'center', 'verticalalignment': 'center'}
    # zero_one_font_size = 20

    font_1 = font_0.copy()
    font_1.set_size('20')
    font_1.set_weight('bold')

    for idx, lw in zip(range(max_idx - 1, -1, -1), lws):
        if not (idx % window_step == 0):
            continue
        codes = [Path.MOVETO] + [Path.LINETO] * 3 + [Path.CLOSEPOLY]

        vertices = [(idx, max_y),
                    (idx + window_step, max_y),
                    (idx + window_step, min_y),
                    (idx, min_y), (0, 0)]
        vertices = np.array(vertices, float)
        path = Path(vertices, codes)
        pathpatch = PathPatch(path, facecolor='None', edgecolor='black', zorder=3, lw=0)
        pathpatch.set_fill(False)

        ax_windowed_desc.text(idx+window_step/2.0, zero_one_y,
                              u"%s" % (zero_ones[idx]),
                              # size=zero_one_font_size,
                              color=asym_color if idx in asym_indexes else sym_color,
                              fontproperties=font_1,
                              **alignment)
        ax_windowed_desc.add_patch(pathpatch)

    leg = ax_windowed_desc.legend(['$\mathbf{%s}$' % ("RR"), "Okno danych - 5 minut"],
                                  loc='upper left', numpoints=5)
    ax_windowed_desc.add_artist(leg)
    # change legend font properties
    plt.setp(leg.get_texts(), fontsize='large')
    plt.setp(leg.get_texts(), fontweight='bold')

    lines = [3] * Line2D(range(1), range(1), linestyle='None', marker='None', color="blue")
    labels = ['G: - godzina', 'M: - minuta', 'S: - sekunda']
    leg = ax_windowed_desc.legend([lines], [labels], loc='upper right')
    plt.setp(leg.get_texts(), fontsize='large')
    plt.setp(leg.get_texts(), fontweight='bold')
    ax_windowed_desc.add_artist(leg)

    if not start_hour == None:
        change_ticks_for_5_minutes(ax_windowed_desc)
    bold_ticks_labels(ax_windowed_desc)

    if only_2_hours == True:
        change_xtickslabels_2_hours(ax_windowed_desc)

    return row_number + 1
Ejemplo n.º 14
0
def create_windowed_tachogram(gs1, row_number, timing, des1, max_idx,
                              start_hour=None, stop_hour=None):
    # RIGHT TACHOGRAM START
    ax_windowed_tachogram = plt.subplot(gs1[row_number, 0])
    ax_windowed_tachogram.set_color_cycle(['blue', 'red'])

    max_timing = np.max(timing)
    des1_max = np.max(des1)
    des1_min = np.min(des1)

    only_2_hours = is_only_2_hours(start_hour, stop_hour)

    ax_windowed_tachogram.plot(timing, des1)
    ax_windowed_tachogram.ticklabel_format(style='sci', axis='x', scilimits=(0, max_timing))
    ax_windowed_tachogram.xaxis.set_ticks(np.arange(0, int(max_timing)+1, 1))
    ax_windowed_tachogram.set_xlim(0, max_timing)

    font_1 = font_0.copy()
    font_1.set_size('11')
    font_1.set_weight('bold')

    if start_hour == None:
        x_label = u"Czas [godziny]"
    else:
        x_label = u"Czas [minuty]"
    ax_windowed_tachogram.set_xlabel(x_label, fontproperties=font_1)
    ax_windowed_tachogram.set_ylabel(u"Wartość [ms]", fontproperties=font_1)

    font_1 = font_0.copy()
    font_1.set_size('18')
    font_1.set_weight('bold')

    y_lim = ax_windowed_tachogram.get_ylim()[1]
    if start_hour == None:
        tachogram_label_pos = 19
        tach_label = u"Tachogram - 24 godziny"
    else:
        tachogram_label_pos = 17
        tach_label = u"Tachogram - fragment 2 godziny"
    ax_windowed_tachogram.text(tachogram_label_pos, y_lim - 100,
                               tach_label, fontproperties=font_1
                               # size=20
                               )

    first_lw = 0.5
    lws = np.linspace(first_lw, 4, max_idx + 1 + first_lw)[::-1]

    for idx, lw in zip(range(max_idx - 1, -1, -1), lws):
        if not (idx % window_step == 0):
            continue
        codes = [Path.MOVETO] + [Path.LINETO] * 3 + [Path.CLOSEPOLY]
        vertices = [(idx, des1_max - des1_max / 10),
                    (idx + window_step, des1_max - des1_max / 10),
                    (idx + window_step, des1_min + des1_max / 10),
                    (idx, des1_min + des1_max / 10), (0, 0)]
        vertices = np.array(vertices, float)
        path = Path(vertices, codes)
        pathpatch = PathPatch(path, facecolor='None', edgecolor='red', zorder=3, lw=lw)
        pathpatch.set_fill(False)
        ax_windowed_tachogram.add_patch(pathpatch)
    leg = ax_windowed_tachogram.legend(['$\mathbf{%s}$' % ("RR"), "Okno danych - 5 minut"], loc='upper left', numpoints=5)
    # change legend font properties
    plt.setp(leg.get_texts(), fontsize='large')
    plt.setp(leg.get_texts(), fontweight='bold')

    arrow_size = 4.5
    head_width = 45
    tail_width = 25
    head_length = 40
    arrow_shift = 100 if start_hour == None else 40
    draw_simple_arrow(ax_windowed_tachogram,
                      posA=(max_idx / 2.0 - arrow_size / 2.0, y_lim - head_width - arrow_shift),
                      posB=(max_idx / 2.0 + arrow_size / 2.0, y_lim - head_width - arrow_shift),
                      tail_width=tail_width, head_width=head_width,
                      head_length=head_length, color="red",
                      text=u"Kierunek przesuwania okna",
                      text_fontsize=12,
                      lw=2.0,
                      )
    if not start_hour == None:
        change_ticks_for_5_minutes(ax_windowed_tachogram)
    bold_ticks_labels(ax_windowed_tachogram)
    if only_2_hours == True:
        change_xtickslabels_2_hours(ax_windowed_tachogram)
    return row_number + 1
Ejemplo n.º 15
0
def create_simple_tachogram(gs1, row_number, timing, des1,
                            slice_color="black", show_window=False,
                            start_hour=None, stop_hour=None):

    max_timing = np.max(timing)
    only_2_hours = is_only_2_hours(start_hour, stop_hour)

    ax_tachogram = plt.subplot(gs1[row_number, :])
    ax_tachogram.set_color_cycle(['blue'])
    ax_tachogram.plot(timing, des1)
    ax_tachogram.ticklabel_format(style='sci', axis='x', scilimits=(0, max_timing))
    ax_tachogram.xaxis.set_ticks(np.arange(0, int(max_timing) + 1, 1))
    ax_tachogram.set_xlim(0, max_timing)

    font_1 = font_0.copy()
    font_1.set_size('11')
    font_1.set_weight('bold')

    y_lim = ax_tachogram.get_ylim()[1]
    if show_window and not start_hour == None:
        codes = [Path.MOVETO] + [Path.LINETO] * 3 + [Path.CLOSEPOLY]
        vertices = [(start_hour, y_lim - 20),
                    (stop_hour, y_lim - 20),
                    (stop_hour, 0),
                    (start_hour, 0), (0, 0)]
        vertices = np.array(vertices, float)
        path = Path(vertices, codes)
        pathpatch = PathPatch(path, facecolor='None', edgecolor=slice_color, zorder=3, lw=3)
        pathpatch.set_fill(False)
        ax_tachogram.add_patch(pathpatch)

    if only_2_hours:
        tachogram_label_pos = 17
        tachogram_title = u"Tachogram - fragment 2 godziny"
        x_label = u"Czas [minuty]"
    else:
        tachogram_label_pos = 19
        tachogram_title = u"Tachogram - 24 godziny"
        x_label = u"Czas [godziny]"

    leg = ax_tachogram.legend(['$\mathbf{%s}$' % ("RR")], loc='upper left')
    # change legend font properties
    plt.setp(leg.get_texts(), fontsize='large')
    plt.setp(leg.get_texts(), fontweight='bold')

    ax_tachogram.set_xlabel(x_label, fontproperties=font_1)
    ax_tachogram.set_ylabel(u"Wartość [ms]", fontproperties=font_1)

    font_1 = font_0.copy()
    font_1.set_size('18')
    font_1.set_weight('bold')

    ax_tachogram.text(tachogram_label_pos, y_lim - 100,
                      tachogram_title, fontproperties=font_1)

    if not start_hour == None:
        change_ticks_for_5_minutes(ax_tachogram)
    bold_ticks_labels(ax_tachogram)
    if only_2_hours == True:
        change_xtickslabels_2_hours(ax_tachogram)

    return row_number + 1
def create_simple_tachogram(gs1,
                            row_number,
                            timing,
                            des1,
                            slice_color="black",
                            show_window=False,
                            start_hour=None,
                            stop_hour=None):

    max_timing = np.max(timing)
    only_2_hours = is_only_2_hours(start_hour, stop_hour)

    ax_tachogram = plt.subplot(gs1[row_number, :])
    ax_tachogram.set_color_cycle(['blue'])
    ax_tachogram.plot(timing, des1)
    ax_tachogram.ticklabel_format(style='sci',
                                  axis='x',
                                  scilimits=(0, max_timing))
    ax_tachogram.xaxis.set_ticks(np.arange(0, int(max_timing) + 1, 1))
    ax_tachogram.set_xlim(0, max_timing)

    font_1 = font_0.copy()
    font_1.set_size('11')
    font_1.set_weight('bold')

    y_lim = ax_tachogram.get_ylim()[1]
    if show_window and not start_hour == None:
        codes = [Path.MOVETO] + [Path.LINETO] * 3 + [Path.CLOSEPOLY]
        vertices = [(start_hour, y_lim - 20), (stop_hour, y_lim - 20),
                    (stop_hour, 0), (start_hour, 0), (0, 0)]
        vertices = np.array(vertices, float)
        path = Path(vertices, codes)
        pathpatch = PathPatch(path,
                              facecolor='None',
                              edgecolor=slice_color,
                              zorder=3,
                              lw=3)
        pathpatch.set_fill(False)
        ax_tachogram.add_patch(pathpatch)

    if only_2_hours:
        tachogram_label_pos = 17
        tachogram_title = u"Tachogram - fragment 2 godziny"
        x_label = u"Czas [minuty]"
    else:
        tachogram_label_pos = 19
        tachogram_title = u"Tachogram - 24 godziny"
        x_label = u"Czas [godziny]"

    leg = ax_tachogram.legend(['$\mathbf{%s}$' % ("RR")], loc='upper left')
    #change legend font properties
    plt.setp(leg.get_texts(), fontsize='large')
    plt.setp(leg.get_texts(), fontweight='bold')

    ax_tachogram.set_xlabel(x_label, fontproperties=font_1)
    ax_tachogram.set_ylabel(u"RR [ms]", fontproperties=font_1)

    font_1 = font_0.copy()
    font_1.set_size('18')
    font_1.set_weight('bold')

    ax_tachogram.text(tachogram_label_pos,
                      y_lim - 100,
                      tachogram_title,
                      fontproperties=font_1)

    if not start_hour == None:
        change_ticks_for_5_minutes(ax_tachogram)
    bold_ticks_labels(ax_tachogram)
    if only_2_hours == True:
        change_xtickslabels_2_hours(ax_tachogram)

    return row_number + 1
Ejemplo n.º 17
0
def create_24_tachogram(gs1, row_number, timing, des1, slice_color="black"):

    max_timing = np.max(timing)

    ax_24_tachogram = plt.subplot(gs1[row_number, :])
    ax_24_tachogram.set_color_cycle(['blue'])
    ax_24_tachogram.plot(timing, des1)
    ax_24_tachogram.ticklabel_format(style='sci',
                                     axis='x',
                                     scilimits=(0, max_timing))
    ax_24_tachogram.xaxis.set_ticks(np.arange(0, int(max_timing) + 1, 1))
    ax_24_tachogram.set_xlim(0, max_timing)

    font_1 = font_0.copy()
    font_1.set_size('13')
    font_1.set_weight('bold')

    alignment = {
        'horizontalalignment': 'center',
        'verticalalignment': 'center'
    }

    y_lim_min = ax_24_tachogram.get_ylim()[0]
    y_lim_max = ax_24_tachogram.get_ylim()[1]
    shift = 50
    for position in positions:
        codes = [Path.MOVETO] + [Path.LINETO] * 3 + [Path.CLOSEPOLY]
        start_pos = position - 0.5
        stop_pos = position + 0.5
        vertices = [(start_pos, y_lim_max - shift),
                    (stop_pos, y_lim_max - shift),
                    (stop_pos, y_lim_min + shift),
                    (start_pos, y_lim_min + shift), (0, 0)]
        vertices = np.array(vertices, float)
        path = Path(vertices, codes)
        pathpatch = PathPatch(path,
                              facecolor='None',
                              edgecolor=slice_color,
                              zorder=3,
                              lw=3)
        pathpatch.set_fill(False)
        ax_24_tachogram.add_patch(pathpatch)

        ax_24_tachogram.text(position,
                             y_lim_min + 2 * shift,
                             u"5 min.",
                             fontproperties=font_1,
                             **alignment)  # size=15)

    leg = ax_24_tachogram.legend(['$\mathbf{%s}$' % ("RR")], loc='upper left')
    # change legend font properties
    plt.setp(leg.get_texts(), fontsize='large')
    plt.setp(leg.get_texts(), fontweight='bold')

    ax_24_tachogram.set_xlabel(u"Czas [godziny]", fontproperties=font_1)
    ax_24_tachogram.set_ylabel(u"RR [ms]", fontproperties=font_1)

    tachogram_label_pos = 18
    font_1 = font_0.copy()
    font_1.set_size('18')
    font_1.set_weight('bold')
    ax_24_tachogram.text(0.85,
                         0.9,
                         u"Tachogram - 24 godziny",
                         fontproperties=font_1,
                         transform=ax_24_tachogram.transAxes)  # size=15)

    arrow_size = 4.5
    head_width = 45
    tail_width = 25
    head_length = 40
    arrow_shift = 100
    pos_start = positions[2] + 0.75
    pos_stop = positions[3] - 0.75
    draw_simple_arrow(
        ax_24_tachogram,
        # posA=(pos_x - arrow_size / 2.0, y_lim_max - head_width - arrow_shift),
        # posB=(pos_x + arrow_size / 2.0, y_lim_max - head_width - arrow_shift),
        posA=(pos_start, y_lim_max - head_width - arrow_shift),
        posB=(pos_stop, y_lim_max - head_width - arrow_shift),
        tail_width=tail_width,
        head_width=head_width,
        head_length=head_length,
        color="red",
        text=u"Kierunek przesuwania okna",
        text_fontsize=12,
        lw=2.0,
    )

    # ax_24_tachogram.text(tachogram_label_pos, y_lim - 200,
    #                  u"Tachogram - 24 godziny", fontproperties = font_1)
    bold_ticks_labels(ax_24_tachogram, fontsize=13)

    return row_number + 1
def create_windowed_tachogram(gs1,
                              row_number,
                              timing,
                              des1,
                              max_idx,
                              start_hour=None,
                              stop_hour=None):
    # RIGHT TACHOGRAM START
    ax_windowed_tachogram = plt.subplot(gs1[row_number, 0])
    ax_windowed_tachogram.set_color_cycle(['blue', 'red'])

    max_timing = np.max(timing)
    des1_max = np.max(des1)
    des1_min = np.min(des1)

    only_2_hours = is_only_2_hours(start_hour, stop_hour)

    ax_windowed_tachogram.plot(timing, des1)
    ax_windowed_tachogram.ticklabel_format(style='sci',
                                           axis='x',
                                           scilimits=(0, max_timing))
    ax_windowed_tachogram.xaxis.set_ticks(np.arange(0, int(max_timing) + 1, 1))
    ax_windowed_tachogram.set_xlim(0, max_timing)

    font_1 = font_0.copy()
    font_1.set_size('11')
    font_1.set_weight('bold')

    if start_hour == None:
        x_label = u"Czas [godziny]"
    else:
        x_label = u"Czas [minuty]"
    ax_windowed_tachogram.set_xlabel(x_label, fontproperties=font_1)
    ax_windowed_tachogram.set_ylabel(u"RR [ms]", fontproperties=font_1)

    font_1 = font_0.copy()
    font_1.set_size('18')
    font_1.set_weight('bold')

    y_lim = ax_windowed_tachogram.get_ylim()[1]
    if start_hour == None:
        tachogram_label_pos = 19
        tach_label = u"Tachogram - 24 godziny"
    else:
        tachogram_label_pos = 17
        tach_label = u"Tachogram - fragment 2 godziny"
    ax_windowed_tachogram.text(tachogram_label_pos,
                               y_lim - 100,
                               tach_label,
                               fontproperties=font_1
                               #size=20
                               )

    first_lw = 0.5
    lws = np.linspace(first_lw, 4, max_idx + 1 + first_lw)[::-1]

    for idx, lw in zip(range(max_idx - 1, -1, -1), lws):
        if not (idx % window_step == 0):
            continue
        codes = [Path.MOVETO] + [Path.LINETO] * 3 + [Path.CLOSEPOLY]
        vertices = [(idx, des1_max - des1_max / 10),
                    (idx + window_step, des1_max - des1_max / 10),
                    (idx + window_step, des1_min + des1_max / 10),
                    (idx, des1_min + des1_max / 10), (0, 0)]
        vertices = np.array(vertices, float)
        path = Path(vertices, codes)
        pathpatch = PathPatch(path,
                              facecolor='None',
                              edgecolor='red',
                              zorder=3,
                              lw=lw)
        pathpatch.set_fill(False)
        ax_windowed_tachogram.add_patch(pathpatch)
    leg = ax_windowed_tachogram.legend(
        ['$\mathbf{%s}$' % ("RR"), "Okno danych - 5 minut"],
        loc='upper left',
        numpoints=5)
    #change legend font properties
    plt.setp(leg.get_texts(), fontsize='large')
    plt.setp(leg.get_texts(), fontweight='bold')

    arrow_size = 4.5
    head_width = 45
    tail_width = 25
    head_length = 40
    arrow_shift = 100 if start_hour == None else 40
    draw_simple_arrow(
        ax_windowed_tachogram,
        posA=(max_idx / 2.0 - arrow_size / 2.0,
              y_lim - head_width - arrow_shift),
        posB=(max_idx / 2.0 + arrow_size / 2.0,
              y_lim - head_width - arrow_shift),
        tail_width=tail_width,
        head_width=head_width,
        head_length=head_length,
        color="red",
        text=u"Kierunek przesuwania okna",
        text_fontsize=12,
        lw=2.0,
    )
    if not start_hour == None:
        change_ticks_for_5_minutes(ax_windowed_tachogram)
    bold_ticks_labels(ax_windowed_tachogram)
    if only_2_hours == True:
        change_xtickslabels_2_hours(ax_windowed_tachogram)
    return row_number + 1
def create_windowed_descriptors_tachogram(gs1,
                                          row_number,
                                          timing,
                                          des1,
                                          max_idx,
                                          sym_indexes,
                                          start_hour=None,
                                          stop_hour=None,
                                          sym_color="brown",
                                          asym_color="green"):

    first_lw = 0.5
    lws = np.linspace(first_lw, 4, max_idx + 1 + first_lw)[::-1]
    max_lws = max(lws)
    lws = [max_lws] * len(lws)

    only_2_hours = is_only_2_hours(start_hour, stop_hour)

    asym_indexes = [idx for idx in range(max_idx) if idx not in sym_indexes]

    max_timing = np.max(timing)
    des1_max = np.max(des1)
    des1_min = np.min(des1)

    # RIGHT TACHOGRAM START
    ax_windowed_desc = plt.subplot(gs1[row_number, 0])
    ax_windowed_desc.set_color_cycle(['blue', 'red'])
    ax_windowed_desc.plot(timing, des1)
    ax_windowed_desc.ticklabel_format(style='sci',
                                      axis='x',
                                      scilimits=(0, max_timing))
    ax_windowed_desc.xaxis.set_ticks(np.arange(0, int(max_timing) + 1, 1))
    ax_windowed_desc.xaxis.set_ticks_position('top')
    ax_windowed_desc.xaxis.set_label_position('top')
    ax_windowed_desc.set_xlim(0, max_timing)

    font_1 = font_0.copy()
    font_1.set_size('11')
    font_1.set_weight('bold')

    if start_hour == None:
        x_label = u"Czas [godziny]"
    else:
        x_label = u"Czas [minuty]"
    ax_windowed_desc.set_xlabel(x_label, fontproperties=font_1)
    ax_windowed_desc.set_ylabel(u"RR [ms]", fontproperties=font_1)

    font_1 = font_0.copy()
    font_1.set_size('18')
    font_1.set_weight('bold')

    if start_hour == None:
        tach_label = u"Tachogram - 24 godziny"
        tachogram_label_pos = 19
    else:
        tach_label = u"Tachogram - fragment 2 godziny"
        tachogram_label_pos = 17

    y_lim = ax_windowed_desc.get_ylim()[1]
    ax_windowed_desc.text(tachogram_label_pos,
                          y_lim - 100,
                          tach_label,
                          fontproperties=font_1)

    for idx, lw in zip(range(max_idx - 1, -1, -1), lws):
        #if idx % window_step == 1:
        if not (idx % window_step == 0):
            continue
        vertices = []
        codes = []
        codes = [Path.MOVETO] + [Path.LINETO] * 3 + [Path.CLOSEPOLY]
        vertices = [(idx, des1_max - des1_max / 10),
                    (idx + window_step, des1_max - des1_max / 10),
                    (idx + window_step, des1_min + des1_max / 10),
                    (idx, des1_min + des1_max / 10), (0, 0)]
        vertices = np.array(vertices, float)
        path = Path(vertices, codes)
        pathpatch = PathPatch(path,
                              facecolor='None',
                              edgecolor='red',
                              zorder=3,
                              lw=lw)
        pathpatch.set_fill(False)
        ax_windowed_desc.add_patch(pathpatch)

    min_y = 50
    max_y = 400

    zero_ones = [("0" if idx in sym_indexes else "A")
                 for idx in range(max_idx)]

    zero_one_y = des1_min - 50

    alignment = {
        'horizontalalignment': 'center',
        'verticalalignment': 'center'
    }
    #zero_one_font_size = 20

    font_1 = font_0.copy()
    font_1.set_size('20')
    font_1.set_weight('bold')

    for idx, lw in zip(range(max_idx - 1, -1, -1), lws):
        if not (idx % window_step == 0):
            continue
        codes = [Path.MOVETO] + [Path.LINETO] * 3 + [Path.CLOSEPOLY]

        vertices = [(idx, max_y), (idx + window_step, max_y),
                    (idx + window_step, min_y), (idx, min_y), (0, 0)]
        vertices = np.array(vertices, float)
        path = Path(vertices, codes)
        pathpatch = PathPatch(path,
                              facecolor='None',
                              edgecolor='black',
                              zorder=3,
                              lw=0)
        pathpatch.set_fill(False)

        ax_windowed_desc.text(
            idx + window_step / 2.0,
            zero_one_y,
            u"%s" % (zero_ones[idx]),
            #size=zero_one_font_size,
            color=asym_color if idx in asym_indexes else sym_color,
            fontproperties=font_1,
            **alignment)
        ax_windowed_desc.add_patch(pathpatch)

    leg = ax_windowed_desc.legend(
        ['$\mathbf{%s}$' % ("RR"), "Okno danych - 5 minut"],
        loc='upper left',
        numpoints=5)
    ax_windowed_desc.add_artist(leg)
    #change legend font properties
    plt.setp(leg.get_texts(), fontsize='large')
    plt.setp(leg.get_texts(), fontweight='bold')

    line = Line2D(range(1),
                  range(1),
                  linestyle='None',
                  marker='None',
                  color="blue")
    label = 'Oznaczenia: %s - asymetria, %s - brak asymetrii' % ("A", "0")
    leg = ax_windowed_desc.legend([line], [label], loc='upper center')
    #change legend font properties
    plt.setp(leg.get_texts(), fontsize='large')
    plt.setp(leg.get_texts(), fontweight='bold')
    ax_windowed_desc.add_artist(leg)

    if not start_hour == None:
        change_ticks_for_5_minutes(ax_windowed_desc)
    bold_ticks_labels(ax_windowed_desc)

    if only_2_hours == True:
        change_xtickslabels_2_hours(ax_windowed_desc)

    return row_number + 1