I'm having a problem with adding a logarithmic X-axis to my plot. I want to show results based on the sample size with methods A
, B
and C
.
My dataframe:
A B C
15 0.733333 0.613333 0.733333
30 0.716667 0.693333 0.766667
59 0.733684 0.678485 0.745763
118 0.796667 0.726087 0.779661
236 0.817862 0.788333 0.838983
470 0.832125 0.814468 0.836170
What I'm trying to make work:
sample_count = np.around(np.logspace(math.log10(15),math.log10(470),6))
sample_count = sample_count.astype(int)
sns.set_style('whitegrid')
g_results=sns.lineplot(data=results,dashes=0,markers=['o','o','o'])
g_results.set(xticks=sample_count)
g_results.set(xscale='log')
However the result is not what I exactly want, as the ticks are completely gone:
Without the last xscale
line it looks like this, which is the linear scale of course, but this time with the correct ticks:
What I want to achieve is something like this:
I would appreciate your help with my problem.
To make the x-axis to log scale, we first the make the scatter plot with Seaborn and save it to a variable and then use set function to specify 'xscale=log'. We see a linear pattern between lifeExp and gdpPercap. Now, the scatter plot makes more sense.
lineplot() Draw a line plot with the possibility of several semantic groupings. The relationship between x and y can be shown for different subsets of the data using the hue, size, and style parameters. These parameters control what visual semantics are used to identify the different subsets.
The semi-transparent region that you see around the line in a seaborn line plot shows the confidence interval. By default, seaborn line plots show confidence intervals for the dataset. You can remove the confidence interval by setting the ci parameter of the lineplot() function to None as shown below.
The seaborn ci code you posted simply computes the percentile limits. This interval has a defined mean of 50 (median) and a default range of 95% confidence interval. The actual mean, the standard deviation, etc. will appear in the percentiles routine.
First set the scale for the x-axis to logarithmic and then set xticks and labels as you want.
sns.set_style('whitegrid')
g_results=sns.lineplot(data=results,dashes=0,markers=['o','o','o'])
g_results.set(xscale='log')
g_results.set(xticks=sample_count)
g_results.set(xticklabels=sample_count)
This gives you this result:
Note that I'm using sample_count
as defined with the logarithmic scale:
sample_count = np.around(np.logspace(math.log10(15),math.log10(470),6))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With