【问题标题】:How to set log scale minor ticks on xaxis for all relplot subplots after using .set如何为seaborn中的所有regplot子图在x轴上设置对数刻度小刻度
【发布时间】:2022-06-10 23:10:54
【问题描述】:
import pandas as pd
import seaborn as sns
tips = sns.load_dataset("tips")
tips['total_bill']=tips.total_bill*10**(tips.index/60+2)

sns.set(font_scale=2)
g=sns.relplot(data=tips,height=5, x="total_bill", y="tip", hue="day", col="time")
g.set(xscale='log')

根据不同的参数(font_scale,height等), plt 上的每 1/10 可能有一些小代码。

如何确保每个 1/10 的所有次要代码都显示在所有子图中?

像这样:

【问题讨论】:

    标签: seaborn axis ticker


    【解决方案1】:
    • answer 类似,除了遍历每个轴。
    • 这个answer 解释了seaborn .set() 默认关闭刻度,使用它的darkgrid 样式,它修改了matplotlib rc parameters,并将xtick.bottomytick.left 参数设置为False,但是答案中的选项不能解决问题。
    import matplotlib.ticker as mticker
    import seaborn as sns
    
    sns.set(font_scale=2)
    g=sns.relplot(data=tips, height=5, x="total_bill", y="tip", hue="day", col="time")
    g.set(xscale='log')
    
    # iterate through each axes
    for ax in g.axes.flat:
        ax.grid(True, which="both", axis='x', ls="--")
        locmin = mticker.LogLocator(base=10, subs=np.arange(0.1,1,0.1), numticks=10)  
        ax.xaxis.set_minor_locator(locmin)
    

    不使用.set

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-29
      • 2018-12-06
      • 1970-01-01
      • 2021-04-08
      • 1970-01-01
      • 2013-02-21
      • 2016-11-05
      相关资源
      最近更新 更多