1
votes

First, I apologize if this questions has already been asked, I couldn't find a solution at StackOverflow.

I'm plotting ECDFs using Seaborn, but for the latency my ECDFs does not show much information using the regular axis.

Example: non-log-axis

So I changed my script to make the x-axis logarithmic using ax.set_xscale('log'), but the result was cutoff.

cutoff-log-axis

I read this issue on GitHub, but since it's from a few years ago I wonder if it was solved.

Here's my code for completeness:

def plot_cdfs(df, legend, nodes, axes):
    ax1, ax2, ax3, ax4 = axes
    # redirecting subplot according to the number of nodes
    if nodes == '25':
        sns.kdeplot(df[header], cumulative=True, legend=False, ax=ax1)
        ax1.set_ylabel('ECDF', fontsize=16)
        ax1.set_title('25 Nodes')
        ax1.set_xlabel(label)
        ax1.set_xscale('log')
        leg_handles = ax1.get_legend_handles_labels()[0]
        ax1.legend(leg_handles, legend[::4])
    elif nodes == '50':
        sns.kdeplot(df[header], cumulative=True, legend=False, ax=ax2)
        ax2.set_title('50 Nodes')
        ax2.set_xlabel(label)
        ax2.set_xscale('log')
    elif nodes == '100':
        sns.kdeplot(df[header], cumulative=True, legend=False, ax=ax3)
        ax3.set_title('100 Nodes')
        ax3.set_xlabel(label)
        ax3.set_xscale('log')
    else:
        sns.kdeplot(df[header], cumulative=True, legend=False, ax=ax4)
        ax4.set_title('150 Nodes')
        ax4.set_xlabel(label)
        ax4.set_xscale('log')
1
I suppose the issue is that you have negative/zero data (or at least the density curve extents to negative/zero values). One might question how useful such a curve is if all values are supposed to be positive, but in any case concerning the plotting you would need to set the lower limit manually, maybe ax.set_xlim(1e-2, None). - ImportanceOfBeingErnest

1 Answers

0
votes

One approach that worked for me is to calculate the cdf and pass the results to the sns.lineplot() function:

data_sorted = np.sort(df[header])

# calculate the proportional values of samples
p = 1. * np.arange(len(df[header])) / (len(df[header]) - 1)

ax = sns.lineplot(data_sorted, p)
ax.set_xscale('log')