[英]Plain notation in seaborn plots
I started using seaborn and I just use pyplot.plot function, and whenever I use log scales the axis ticks are presented as 10 to some power. 我开始使用seaborn,然后只使用pyplot.plot函数,每当使用对数刻度时,轴刻度就会显示为10到一定的幂。 Before using seaborn, line
使用seaborn之前,先行
ax.xaxis.set_major_formatter(FormatStrFormatter('%.0f'))
was fixing the problem, but now with seaborn it does not. 在解决问题,但是现在有了seaborn,问题就没有了。 Any ideas how I can have plain notation on my axes?
有什么想法可以在轴上使用简单的符号吗?
Below is an example of the code. 下面是代码示例。 I would like the x axis to be of the form: 0.1, 1, 10 , 100 .. and not as it is now.
我希望x轴的形式为:0.1、1、10、100 ..而不是现在。
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style('ticks', {'font.family': 'sans-serif'})
sns.set_context("paper", font_scale=1.3)
plt.rc('text', usetex=True)
x_lim=[0.1,100]
y_lim=[1.2001, 2.2001]
f = plt.figure()
plt.xscale('log')
plt.ylim(y_lim)
plt.xlim(x_lim)
plt.hlines(1.5, *x_lim, color='grey')
plt.show()
The key thing is the placement of the formatter line. 关键是格式化程序行的位置。 It has to be after
ax.set_xscale('log')
. 它必须在
ax.set_xscale('log')
。
Rather than using %.0f
which removes all numbers after the decimal place (leaving 0
rather than 0.1
), use %g
, which will round to 1 significant figure. 不是使用
%.0f
删除小数点后的所有数字(保留0
而不是0.1
),而是使用%g
,它将舍入到1个有效数字。 I've extended your example to use a subplot so that the format can be set: 我已经将您的示例扩展为使用子图,以便可以设置格式:
import matplotlib.pyplot as plt
import matplotlib.ticker as tck
import seaborn as sns
sns.set_style('ticks', {'font.family': 'sans-serif'})
sns.set_context("paper", font_scale=1.3)
plt.rc('text', usetex=True)
x_lim=[0.1,100]
y_lim=[1.2001, 2.2001]
f = plt.figure()
ax = f.add_subplot(plt.subplot(1, 1, 1))
ax.set_xscale('log')
ax.set_ylim(y_lim)
ax.set_xlim(x_lim)
ax.hlines(1.5, *x_lim, color='grey')
ax.xaxis.set_major_formatter(tck.FormatStrFormatter('%g'))
plt.show()
This produces the image: 产生图像:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.