def plot_two(
        fig_id,
        x,
        y,
        x2,
        y2,
        linestyle='-',
        linestyle2='-',
        color='blue',
        color2='magenta',
        ylim=None,
        ylim2=None,
        xlabel='',
        ylabel='',
        ylabel2='',
        title='',
        figsize=(7, 3.5),
        markersize2=None,
        marker2=None,
):
    """Plot two quantities with a date x-axis"""
    xt = cxctime2plotdate(x)
    fig = plt.figure(fig_id, figsize=figsize)
    fig.clf()
    ax = fig.add_subplot(1, 1, 1)
    ax.plot_date(xt, y, fmt='-', linestyle=linestyle, color=color)
    ax.set_xlim(min(xt), max(xt))
    if ylim:
        ax.set_ylim(*ylim)
    ax.set_xlabel(xlabel)
    ax.set_ylabel(ylabel)
    ax.set_title(title)
    ax.grid()

    ax2 = ax.twinx()

    xt2 = cxctime2plotdate(x2)
    ax2.plot_date(xt2,
                  y2,
                  fmt='-',
                  linestyle=linestyle2,
                  color=color2,
                  markersize=markersize2,
                  marker=marker2)
    ax2.set_xlim(min(xt), max(xt))
    if ylim2:
        ax2.set_ylim(*ylim2)
    ax2.set_ylabel(ylabel2, color=color2)
    ax2.xaxis.set_visible(False)

    set_time_ticks(ax)
    [label.set_rotation(30) for label in ax.xaxis.get_ticklabels()]
    [label.set_color(color2) for label in ax2.yaxis.get_ticklabels()]

    fig.subplots_adjust(bottom=0.22)

    return {'fig': fig, 'ax': ax, 'ax2': ax2}
def plot_two(
    fig_id,
    x,
    y,
    x2,
    y2,
    linestyle="-",
    linestyle2="-",
    color="blue",
    color2="magenta",
    ylim=None,
    ylim2=None,
    xlabel="",
    ylabel="",
    ylabel2="",
    title="",
    figsize=(7, 3.5),
    markersize2=None,
    marker2=None,
):
    """Plot two quantities with a date x-axis"""
    xt = cxctime2plotdate(x)
    fig = plt.figure(fig_id, figsize=figsize)
    fig.clf()
    ax = fig.add_subplot(1, 1, 1)
    ax.plot_date(xt, y, fmt="-", linestyle=linestyle, color=color)
    ax.set_xlim(min(xt), max(xt))
    if ylim:
        ax.set_ylim(*ylim)
    ax.set_xlabel(xlabel)
    ax.set_ylabel(ylabel)
    ax.set_title(title)
    ax.grid()

    ax2 = ax.twinx()

    xt2 = cxctime2plotdate(x2)
    ax2.plot_date(xt2, y2, fmt="-", linestyle=linestyle2, color=color2, markersize=markersize2, marker=marker2)
    ax2.set_xlim(min(xt), max(xt))
    if ylim2:
        ax2.set_ylim(*ylim2)
    ax2.set_ylabel(ylabel2, color=color2)
    ax2.xaxis.set_visible(False)

    set_time_ticks(ax)
    [label.set_rotation(30) for label in ax.xaxis.get_ticklabels()]
    [label.set_color(color2) for label in ax2.yaxis.get_ticklabels()]

    fig.subplots_adjust(bottom=0.22)

    return {"fig": fig, "ax": ax, "ax2": ax2}
Exemple #3
0
def test_check_many_sizes():
    """Run through a multiplicative series of x-axis lengths and visually
    confirm that chosen axes are OK."""
    plt.ion()
    dt = 6
    while True:
        print dt
        t0 = np.random.uniform(3e7 * 10)
        times = np.linspace(t0, t0 + dt, 20)
        x = cxctime2plotdate(times)
        y = np.random.normal(size=len(times))

        fig = plt.figure(1)
        fig.clf()
        plt1 = fig.add_subplot(1, 1, 1)
        plt1.plot_date(x, y, fmt="b-")

        set_time_ticks(plt1)

        fig.autofmt_xdate()
        plt.savefig("test-{:09d}.png".format(dt))
        dt *= 2
        if dt > 1e9:
            break