Consider the following minimal working example:
JavaScript
x
15
15
1
import numpy as np
2
import pandas as pd
3
import seaborn as sns
4
5
df = pd.DataFrame({
6
"Area":[0.5, 0.05, 0.005]
7
})
8
9
sns.histplot(
10
data=df,
11
x="Area",
12
bins=3,
13
log_scale=True
14
)
15
The minimal working example above will produce
Now, let’s use our own breaks of the bins:
JavaScript
1
7
1
sns.histplot(
2
data=df,
3
x="Area",
4
bins=np.logspace(-3, 0, num=4),
5
log_scale=True
6
)
7
I expected to produce a histogram similar to the one before but I’m getting
What am I doing wrongly? Or is this a bug with Seaborn 0.11.2?
Advertisement
Answer
Apparently, you have to give the bins on the log scale. I.e. with bins=np.logspace(-3, 0, 4)
you’re getting bins at 10**np.logspace(-3, 0, 4)
. Use linspace
instead and you should be getting what you’re looking for. bins=np.linspace(-3, 0, 4)
gives breaks at 10**np.linspace(-3, 0, 4)
:
JavaScript
1
7
1
sns.histplot(
2
data=df,
3
x="Area",
4
bins=np.linspace(-3, 0, num=4),
5
log_scale=True
6
)
7