10

I tried drawing a relplot with log scaled axes. Making use of previous answers, I tried:

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()

However the axes were not changed in the result.

enter image description here

How can I remedy this?

2 Answers 2

21

For sns.relplot you can set the scale as follows:

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

This will set the scales for all sub-graphs.

1

You can use scatterplot and dont forget to mention your axes in your plot

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()

Edit - relplot is a figure-level function and does not accept the ax= paramter

1
  • Great, thanks! Any idea why it didn't work for relplot?
    – Lafayette
    Commented Sep 13, 2020 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.