【问题标题】:How to use log scale for the axes of a seaborn relplot?如何对 seaborn relplot 的轴使用对数刻度?
【发布时间】:2020-09-13 16:58:05
【问题描述】:

我尝试绘制一个带有对数比例轴的 relplot。 利用之前的answers,我试过了:

import matplotlib.pyplot as plt
import seaborn as sns

f, ax = plt.subplots(figsize=(7, 7))
ax.set(xscale="log", yscale="log")

tips = sns.load_dataset("tips")
sns.relplot(x="total_bill", y="tip", hue='smoker', data=tips)
plt.show()

但是结果中的轴没有改变。

我该如何解决这个问题?

【问题讨论】:

    标签: python matplotlib seaborn


    【解决方案1】:

    对于sns.relplot,您可以按如下方式设置比例:

    g = sns.relplot(...)
    g.set(xscale="log")
    g.set(yscale="log")
    

    【讨论】:

      【解决方案2】:

      您可以使用scatterplot,并且不要忘记在您的情节中提及您的axes

      import matplotlib.pyplot as plt
      import seaborn as sns
      f, ax = plt.subplots(figsize=(7, 7))
      tips = sns.load_dataset("tips")
      ax.set(xscale="log", yscale="log")
      sns.scatterplot(x="total_bill", y="tip", hue='smoker', data=tips,ax=ax)
      plt.show()
      

      编辑 - relplot 是图形级函数,不接受 ax= paramter

      【讨论】:

      • 太好了,谢谢!知道为什么它对relplot 不起作用吗?
      猜你喜欢
      • 2020-01-10
      • 1970-01-01
      • 2018-12-06
      • 1970-01-01
      • 2021-02-22
      • 2017-05-11
      • 2015-12-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多