Esempio n. 1
0
def plot_Parameterspace(figsize=(9, 6), cmap="RdBu"):
    user = getpass.getuser()

    # Obtain data sets
    tauLData = pd.read_pickle("data/TauSigmaConstMean_SampleSize250.pkl")
    tauNData = pd.read_pickle("data/TauSigmaN_SampleSize250.pkl")
    phiLData = pd.read_pickle("data/PhiSigmaConstMean_SampleSize250.pkl")
    phiNData = pd.read_pickle("data/PhiSigmaN_SampleSize250.pkl")

    # Obtain parameters
    tauLParams = {tauLData.index.names[i]: np.unique([x[i]
                  for x in tauLData.index.values]) for i in [0, 1]}
    tauNParams = {tauNData.index.names[i]: np.unique([x[i]
                  for x in tauNData.index.values]) for i in [0, 1]}
    phiLParams = {phiLData.index.names[i]: np.unique([x[i]
                  for x in phiLData.index.values]) for i in [0, 1]}
    phiNParams = {phiNData.index.names[i]: np.unique([x[i]
                  for x in phiNData.index.values]) for i in [0, 1]}

    tau = np.intersect1d(tauLParams["tau"], tauNParams["tau"])
    phi = np.intersect1d(phiLParams["phi"], phiNParams["phi"])
    sigmaL = np.intersect1d(phiLParams["sigma"], tauLParams["sigma"])
    sigmaN = np.intersect1d(phiNParams["sigma"], tauNParams["sigma"])

    # Figure
    fig, axes = plt.subplots(2, 2, figsize=figsize, sharex="col", sharey="row")

    T, S = ev._create_meshgrid(tau, sigmaL)
    tauLVals = tauLData["<<sus>>"].unstack(level="tau").loc[sigmaL, tau].values
    c = axes[0, 0].pcolormesh(T, S, tauLVals, cmap=cmap)
    axes[0, 0].set_xlim(np.min(T), np.max(T))
    axes[0, 0].set_ylim(np.min(S), np.max(S))
    axes[0, 0].set_ylabel(r"$\sigma$ for log-normal dist.")

    P, S = ev._create_meshgrid(phi, sigmaL)
    phiLVals = phiLData["<<sus>>"].unstack(level="phi").loc[sigmaL, phi].values
    c = axes[0, 1].pcolormesh(P, S, phiLVals, cmap=cmap)
    axes[0, 1].set_xlim(np.min(P), np.max(P))
    axes[0, 1].set_ylim(np.min(S), np.max(S))

    T, S = ev._create_meshgrid(tau, sigmaN)
    tauNVals = tauNData["<<sus>>"].unstack(level="tau").loc[sigmaN, tau].values
    c = axes[1, 0].pcolormesh(T, S, tauNVals, cmap=cmap)
    axes[1, 0].set_xlim(np.min(T), np.max(T))
    axes[1, 0].set_ylim(np.min(S), np.max(S))
    axes[1, 0].set_ylabel(r"$\sigma_\mathcal{N}$ for normal dist.")
    axes[1, 0].set_xlabel(r"Social interaction time scale $\tau$")

    P, S = ev._create_meshgrid(phi, sigmaN)
    phiNVals = phiNData["<<sus>>"].unstack(level="phi").loc[sigmaN, phi].values
    c = axes[1, 1].pcolormesh(P, S, phiNVals, cmap=cmap)
    axes[1, 1].set_xlim(np.min(P), np.max(P))
    axes[1, 1].set_ylim(np.min(S), np.max(S))
    axes[1, 1].set_xlabel(r"Rewiring probability $\phi$"+
                          "\ndegree of homophily")

    # Title
    fig.text(0.499, 0.95,
             "Average fraction of sustainable nodes at the consensus state",
             va="bottom", ha="center", fontsize=13, color="#444444")

    # Y label
    fig.text(0.02, 0.5,
             "Resource heterogeneity", rotation="vertical",
             va="center", ha="center", fontsize=13, color="#444444")

    #  Numbering
    fig.text(0.478, 0.91, "a", va="center", ha="center", fontsize=12,
             color="white")
    fig.text(0.868, 0.91, "b", va="center", ha="center", fontsize=12,
             color="#111111")
    fig.text(0.478, 0.49, "c", va="center", ha="center", fontsize=12,
             color="white")
    fig.text(0.868, 0.49, "d", va="center", ha="center", fontsize=12,
             color="#111111")

    # Colorbar with own axis
    sus_cax = fig.add_axes([0.92, 0.16, 0.025, 0.75])
    fig.colorbar(c, sus_cax, orientation='vertical')

    plt.subplots_adjust(left=0.12, top=0.93, right=0.878,
                        hspace=0.05, wspace=0.05, bottom=0.12)
Esempio n. 2
0
def plot_TauPhiSpace(figsize=(11, 3.5), cmap="RdBu"):
    user = getpass.getuser()

    # Obtain data sets
    data0o01 = pd.read_pickle("data/" +
                              "TauPhi_Sigma0o01ConstMean_SampleSize250.pkl")
    data0o6 = pd.read_pickle("data/TauPhi_Sigma0o6ConstMean_SampleSize250.pkl")
    data0o9 = pd.read_pickle("data/TauPhi_Sigma0o9ConstMean_SampleSize250.pkl")
    data1o2 = pd.read_pickle("data/TauPhi_Sigma1o2ConstMean_SampleSize250.pkl")

    tau = np.unique([x[0] for x in data0o01.index.values])
    phi = np.unique([x[1] for x in data0o01.index.values])

    # Figure
    fig, axes = plt.subplots(1, 4, figsize=figsize, sharey="row")

    T, P = ev._create_meshgrid(tau, phi)
    val0o01 = data0o01["<<sus>>"].unstack(level="tau").values
    c = axes[0].pcolormesh(T, P, val0o01, cmap=cmap, vmin=0, vmax=1)
    axes[0].set_xlim(np.min(T), np.max(T))
    axes[0].set_ylim(np.min(P), np.max(P))
    axes[0].set_ylabel(r"Rewiring probability $\phi$"+"\ndegree of homophily")
#    axes[0].set_xlabel(r"Update time scale $\tau$")
    axes[0].set_title(r"for $\sigma=0.01$",
                      fontdict={"fontsize": 11, "color": "#444444"})

    val0o6 = data0o6["<<sus>>"].unstack(level="tau").values
    c = axes[1].pcolormesh(T, P, val0o6, cmap=cmap, vmin=0, vmax=1)
    axes[1].set_xlim(np.min(T), np.max(T))
    axes[1].set_ylim(np.min(P), np.max(P))
#    axes[1].set_xlabel(r"Update time scale $\tau$")
    axes[1].set_title(r"for $\sigma=0.6$",
                      fontdict={"fontsize": 11, "color": "#444444"})

    val0o9 = data0o9["<<sus>>"].unstack(level="tau").values
    c = axes[2].pcolormesh(T, P, val0o9, cmap=cmap, vmin=0, vmax=1)
    axes[2].set_xlim(np.min(T), np.max(T))
    axes[2].set_ylim(np.min(P), np.max(P))
#   axes[2].set_xlabel(r"Update time scale $\tau$")
    axes[2].set_title(r"for $\sigma=0.9$",
                      fontdict={"fontsize": 11, "color": "#444444"})

    val1o2 = data1o2["<<sus>>"].unstack(level="tau").values
    c = axes[3].pcolormesh(T, P, val1o2, cmap=cmap, vmin=0, vmax=1)
    axes[3].set_xlim(np.min(T), np.max(T))
    axes[3].set_ylim(np.min(P), np.max(P))
#    axes[3].set_xlabel(r"Update time scale $\tau$")
    axes[3].set_title(r"for $\sigma=1.2$",
                      fontdict={"fontsize": 11, "color": "#444444"})

    #  Title
    fig.text(0.5, 0.92,
             "Average fraction of sustainable nodes at the consensus state",
             va="bottom", ha="center", fontsize=13, color="#444444")

    #  X label
    fig.text(0.5, 0.09, r"Social interaction time scale $\tau$",
             va="top", ha="center", fontsize=12, color="#444444")

    #  Numbering
    fig.text(0.274, 0.79, "a", va="center", ha="center", fontsize=12,
             color="#111111")
    fig.text(0.483, 0.79, "b", va="center", ha="center", fontsize=12,
             color="#111111")
    fig.text(0.693, 0.79, "c", va="center", ha="center", fontsize=12,
             color="#111111")
    fig.text(0.903, 0.79, "d", va="center", ha="center", fontsize=12,
             color="#111111")

    # Colorbar with own axis
    sus_cax = fig.add_axes([0.93, 0.2, 0.02, 0.62])
    fig.colorbar(c, sus_cax, orientation='vertical')

    plt.subplots_adjust(wspace=0.04, bottom=0.2, right=0.91, top=0.82,
                        left=0.08)