Пример #1
0
def draw_labels(figure: Figure,
                axes: Axes,
                y_label: str,
                label_rotation=90,
                axes_position='bottom'):

    # text and text parameters
    xlabel_text = r'$incubation\ time\ \slash\ days$'
    ylabel_text = y_label

    ylabel_rotation = label_rotation

    is_bottom = True if ('bottom' in axes_position
                         or axes_position == 'single') else False
    # MRE notation,
    if is_bottom:
        MRE_notation_marks(axes)  # add arrows where MRE was applied

    # remove x axis from top and middle axes
    if not is_bottom:
        axes.get_xaxis().set_visible(False)

    # x label
    figure.text(0.5, 0.03, xlabel_text, ha='center')
    # y label
    figure.text(0.05, 0.5, ylabel_text, va='center', rotation=ylabel_rotation)

    # legend
    axes.get_lines()
    handles = axes.get_lines()
    labels = SOILS
    figure.legend(handles, labels, 'center right')
Пример #2
0
def shift(vis_data: ndarray, ax: Axes, gap: float = 0, inplace: bool = False):
    """Shift the data so that the max(data[n-1]) - max(data[n]) = line_spacing for n > 1.

    Parameters
    ----------
    vis_data : ndarray
        The data to visualize. The first row is independent variables and the later rows are dependent variables.

    ax : Axes
        The axes to plot the data on.

    gap : float
        The spacing between two adjacent lines.

    inplace : bool
        If True, shift the data inplace. Else, shift the copied data.
    """
    if not inplace:
        vis_data = np.copy(vis_data)
    lines = ax.get_lines()
    if len(lines) > 0:
        last_y = lines[-1].get_ydata()
        y = vis_data[1:]
        vis_data[1:] += np.min(last_y) - np.max(y) - gap
    return vis_data
Пример #3
0
def auto_text(text: str, ax: Axes, text_xy: tuple = None, index: int = -1):
    """
    Automatically add the text.

    Parameters
    ----------
    text : str
        The content of the text.

    ax : Axes
        The axes to plot the data on.

    text_xy : tuple
        The relative position. The horizontal bound is the xlim. The vertical is the two curves.

    index : int
        The index of the lines to add text. Default -1 (the last line).
    """
    lines = ax.get_lines()
    if len(lines) == 0:
        return ax
    vis_data = lines[index].get_data()
    color = lines[index].get_color()
    if text_xy is None:
        text_xy = _TEXT_XY
    xy = text_position(vis_data, text_xy)
    ax.annotate(text, xy, ha="left", va="center", color=color)
    return ax
Пример #4
0
def use_dynamic_x(ax: Axes, data: FrameOrSeriesUnion) -> bool:
    freq = _get_index_freq(data.index)
    ax_freq = _get_ax_freq(ax)

    if freq is None:  # convert irregular if axes has freq info
        freq = ax_freq
    else:  # do not use tsplot if irregular was plotted first
        if (ax_freq is None) and (len(ax.get_lines()) > 0):
            return False

    if freq is None:
        return False

    freq = _get_period_alias(freq)

    if freq is None:
        return False

    # FIXME: hack this for 0.10.1, creating more technical debt...sigh
    if isinstance(data.index, ABCDatetimeIndex):
        base = to_offset(freq)._period_dtype_code
        x = data.index
        if base <= FreqGroup.FR_DAY.value:
            return x[:1].is_normalized
        return Period(x[0], freq).to_timestamp().tz_localize(x.tz) == x[0]
    return True
Пример #5
0
def use_dynamic_x(ax: Axes, data: DataFrame | Series) -> bool:
    freq = _get_index_freq(data.index)
    ax_freq = _get_ax_freq(ax)

    if freq is None:  # convert irregular if axes has freq info
        freq = ax_freq
    else:  # do not use tsplot if irregular was plotted first
        if (ax_freq is None) and (len(ax.get_lines()) > 0):
            return False

    if freq is None:
        return False

    freq_str = _get_period_alias(freq)

    if freq_str is None:
        return False

    # FIXME: hack this for 0.10.1, creating more technical debt...sigh
    if isinstance(data.index, ABCDatetimeIndex):
        # error: "BaseOffset" has no attribute "_period_dtype_code"
        base = to_offset(freq_str)._period_dtype_code  # type: ignore[attr-defined]
        x = data.index
        if base <= FreqGroup.FR_DAY.value:
            return x[:1].is_normalized
        period = Period(x[0], freq_str)
        assert isinstance(period, Period)
        return period.to_timestamp().tz_localize(x.tz) == x[0]
    return True
Пример #6
0
def get_all_lines(ax: Axes) -> list[Line2D]:
    lines = ax.get_lines()

    if hasattr(ax, "right_ax"):
        lines += ax.right_ax.get_lines()

    if hasattr(ax, "left_ax"):
        lines += ax.left_ax.get_lines()

    return lines