简体   繁体   中英

How to use log scale for the axes of a seaborn relplot?

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.

在此处输入图片说明

How can I remedy this?

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM