Esempio n. 1
0
def format_figure(fig: plt.Figure,
                  title: str = None,
                  x_label: str = None,
                  y_label: str = None,
                  title_y_position: float = 0.93):
    fig.set_figwidth(12)
    fig.set_figheight(8)
    fig.set_facecolor("white")
    if title is not None:
        fig.suptitle(title,
                     y=title_y_position,
                     verticalalignment='top',
                     fontsize=24)

    axes = fig.axes
    for ax in axes:
        ax.spines['top'].set_color('white')
        ax.spines['right'].set_color('white')
        ax.set_facecolor("white")
        ax.xaxis.grid(which="both", linewidth=0.5)
        ax.yaxis.grid(which="both", linewidth=0.5)
        ax.xaxis.label.set_fontsize(18)
        ax.yaxis.label.set_fontsize(18)
        ax.title.set_fontsize(20)

    if x_label is not None:
        fig.text(0.5, 0.04, x_label, ha='center', fontdict={'size': 18})

    if y_label is not None:
        fig.text(0.04,
                 0.5,
                 y_label,
                 va='center',
                 rotation='vertical',
                 fontdict={'size': 18})
Esempio n. 2
0
def save(fig: plt.Figure, ax: plt.Axes):
    print("saving")

    ax.set_xlim([-0.05, 1.05])
    ax.set_ylim([-0.05, 1.05])

    plt.subplots_adjust(
        left=0,
        right=1,
        bottom=0,
        top=1,
        wspace=0,
        hspace=0,
    )
    fig.text(0.98,
             0.03,
             s="github.com/ufukty",
             color="#888888",
             size=4,
             ha="right")

    output_filename = datetime.now().strftime(dir_path +
                                              "/output %Y.%m.%d %H.%M.%S.png")
    plt.axis("off")
    plt.savefig(
        output_filename,
        dpi=1200,
        bbox_inches='tight',
        facecolor="#000000",
    )
Esempio n. 3
0
def _plot_updated_timestamp(timestamp: dt.datetime,
                            fig: plt.Figure = None) -> None:
    if fig is None:
        fig = plt.gcf()
    fig.text(
        0.5,
        0.03,
        f"Updated {timestamp.isoformat()}",
        color="gray",
        horizontalalignment="center",
    )
Esempio n. 4
0
def draw_text(ax: plt.Figure,
              coords: Tuple[List[int], List[int]],
              txt: str,
              sz: int = 14,
              c: str = 'white',
              val: str = 'top',
              hal: str = 'left',
              outline: bool = True):
    '''
    Draws a text on ax and returns text object
    :param ax: (matplotlib.axes._subplots.AxesSubplot) object
    :param coords: tuple(int) coordinates of top-left corner of text object
    :param txt: (str) text to draw
    :param sz: (int) font size
    :param c: (str) color
    :param val: (str) vertical alignment
    :param hal: (str) horizontal alignment
    :param outline: (bool) draw or not black outline with lw=4
    :return: text object
    '''
    text = ax.text(*coords,
                   txt,
                   fontsize=sz,
                   color=c,
                   verticalalignment=val,
                   horizontalalignment=hal,
                   weight='bold')
    if outline:
        draw_outline(text, 4, c='black')
    return text
Esempio n. 5
0
def _plot_ecg_text(
    data: dict,
    fig: plt.Figure,
    w: float,
    h: float,
) -> None:
    # top text
    dt = datetime.strptime(data["datetime"], ECG_DATETIME_FORMAT)
    dob = str(data["dateofbirth"], 'utf-8')
    if dob != "":
        dob = datetime.strptime(dob, ECG_DATE_FORMAT)
        dob = f"{dob:%d-%b-%Y}".upper()
    try:
        age = int(data["patientage"])
    except:
        age = -1

    fig.text(
        0.17 / w,
        8.04 / h,
        f"{data['patientlastname']}, {data['patientfirstname']}",
        weight="bold",
    )
    fig.text(3.05 / w, 8.04 / h, f"ID:{data['patientid']}", weight="bold")
    fig.text(4.56 / w,
             8.04 / h,
             f"{dt:%d-%b-%Y %H:%M:%S}".upper(),
             weight="bold")
    fig.text(6.05 / w, 8.04 / h, f"{data['sitename']}", weight="bold")

    fig.text(0.17 / w, 7.77 / h, f"{dob} ({age} yr)", weight="bold")
    fig.text(0.17 / w, 7.63 / h, f"{data['gender']}".title(), weight="bold")
    fig.text(0.17 / w, 7.35 / h, "Room: ", weight="bold")
    fig.text(0.17 / w, 7.21 / h, f"Loc: {data['location']}", weight="bold")

    fig.text(2.15 / w, 7.77 / h, "Vent. rate", weight="bold")
    fig.text(2.15 / w, 7.63 / h, "PR interval", weight="bold")
    fig.text(2.15 / w, 7.49 / h, "QRS duration", weight="bold")
    fig.text(2.15 / w, 7.35 / h, "QT/QTc", weight="bold")
    fig.text(2.15 / w, 7.21 / h, "P-R-T axes", weight="bold")

    fig.text(
        3.91 / w,
        7.77 / h,
        f"{int(data['ventricularrate_md'])}",
        weight="bold",
        ha="right",
    )
    fig.text(3.91 / w,
             7.63 / h,
             f"{int(data['printerval_md'])}",
             weight="bold",
             ha="right")
    fig.text(3.91 / w,
             7.49 / h,
             f"{int(data['qrsduration_md'])}",
             weight="bold",
             ha="right")
    fig.text(
        3.91 / w,
        7.35 / h,
        f"{int(data['qtinterval_md'])}/{int(data['qtcorrected_md'])}",
        weight="bold",
        ha="right",
    )
    fig.text(
        3.91 / w,
        7.21 / h,
        f"{int(data['paxis_md'])}   {int(data['raxis_md'])}",
        weight="bold",
        ha="right",
    )

    fig.text(4.30 / w, 7.77 / h, "BPM", weight="bold", ha="right")
    fig.text(4.30 / w, 7.63 / h, "ms", weight="bold", ha="right")
    fig.text(4.30 / w, 7.49 / h, "ms", weight="bold", ha="right")
    fig.text(4.30 / w, 7.35 / h, "ms", weight="bold", ha="right")
    fig.text(4.30 / w,
             7.21 / h,
             f"{int(data['taxis_md'])}",
             weight="bold",
             ha="right")

    fig.text(4.75 / w,
             7.21 / h,
             f"{data['read_md_clean']}",
             wrap=True,
             weight="bold")

    fig.text(1.28 / w, 6.65 / h, f"Technician: {''}", weight="bold")
    fig.text(1.28 / w, 6.51 / h, f"Test ind: {''}", weight="bold")
    fig.text(4.75 / w, 6.25 / h, f"Referred by: {''}", weight="bold")
    fig.text(7.63 / w,
             6.25 / h,
             f"Electronically Signed By: {''}",
             weight="bold")