[英]Seaborn lineplot logarithmic scale
I'm having a problem with adding a logarithmic X-axis to my plot.我在向绘图中添加对数 X 轴时遇到问题。 I want to show results based on the sample size with methods
A
, B
and C
.我想显示基于样本大小的结果,方法
A
, B
和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:没有最后的
xscale
线,它看起来像这样,当然这是线性比例,但这次有正确的刻度:
What I want to achieve is something like this:我想要实现的是这样的:
I would appreciate your help with my problem.我很感激你对我的问题的帮助。
First set the scale for the x-axis to logarithmic and then set xticks and labels as you want.首先将 x 轴的比例设置为对数,然后根据需要设置 xticks 和标签。
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
:
sample_count = np.around(np.logspace(math.log10(15),math.log10(470),6))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.