【发布时间】:2018-08-05 18:06:05
【问题描述】:
我正在尝试在数据帧上使用 seaborn factorplot 绘制对数图,如下所示
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
l1 = [0.476, 0.4427, 0.378, 0.2448, 0.13, 0.004, 0.012, 0.0933, 3.704e-05,
1.4762e-06, 4.046e-08, 2.99e-10, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
df = pd.DataFrame(l1, columns=["y"])
df.reset_index(inplace=True)
g = sns.factorplot(x='index',y='y', data=df, aspect=2, size=8)
g.fig.get_axes()[0].set_yscale('log')
plt.grid(True,which="both",ls="--",c='gray')
plt.show()
尽管我将 Y 轴刻度更改为对数并使用了两条网格线,但最终数字没有对数刻度刻度。但是,当与另一组值一起使用时,相同的代码给了我下图。在这种情况下,最小值限制为 10^-7
l2 = [0.29, 0.111, 0.0285, 0.0091, 0.00045, 5.49759e-05, 1.88819e-06, 0.0, 0.0, 0.0]
df = pd.DataFrame(l2, columns=["y"])
# same code as above
知道我哪里错了吗?
更新 1
我按照 Diziet 的回答,并按如下方式强制了主要和次要刻度
g.ax.yaxis.set_minor_locator(tkr.LogLocator(base=10, subs='all'))
g.ax.yaxis.set_minor_formatter(tkr.NullFormatter())
g.ax.set_yscale('log')
g.ax.grid(True,which="both",ls="--",c='gray')
但还是没有解决问题
【问题讨论】:
-
请查看minimal reproducible example 并确保您的问题包含此类示例。
-
@ImportanceOfBeingErnest:完成。修改了问题以包含可重复性的最小数据集
-
我将您的问题编辑为使用minimal reproducible example,因此可以理解。
-
好像和this question一样。
标签: python pandas matplotlib seaborn