在 pandas 图中舍入 xtick 值
Rounding the xtick values in a pandas plot
是否有一种简单的方法可以在 pandas 图中舍入 xtick 值?我绘制了分位数,这就是我得到的:
pd.Series(argmax_indexes).quantile(np.arange(0,1.05, 0.05))
0.00 500.0
0.05 560.8
0.10 582.8
0.15 589.0
0.20 593.0
0.25 595.0
0.30 596.0
0.35 597.0
0.40 598.0
0.45 598.0
0.50 599.0
0.55 599.0
0.60 599.0
0.65 600.7
0.70 602.0
0.75 603.0
0.80 606.0
0.85 608.0
0.90 616.0
0.95 634.1
1.00 699.0
pd.Series(argmax_indexes).quantile(np.arange(0,1.05, 0.05)).plot(kind = 'bar')
它与 float64 的计算方式有关,但您可以通过调整和编写类似这样的内容以及一些示例数据来解决您的问题:
s = pd.Series([1,10,20,30,50]).quantile(np.arange(0,1.05, 0.05))
s.index = s.index.map(lambda l : np.around(l,2))
s.plot(kind = 'bar')
如果你想在一个衬里做,这应该很好用:
import numpy as np
import pandas as pd
import seaborn as sns
df = sns.load_dataset('tips')
df['tip'].quantile(np.arange(0,1.05,0.05)).reset_index().round(2).plot(kind='bar',x='index',y='tip')
输出
是否有一种简单的方法可以在 pandas 图中舍入 xtick 值?我绘制了分位数,这就是我得到的:
pd.Series(argmax_indexes).quantile(np.arange(0,1.05, 0.05))
0.00 500.0
0.05 560.8
0.10 582.8
0.15 589.0
0.20 593.0
0.25 595.0
0.30 596.0
0.35 597.0
0.40 598.0
0.45 598.0
0.50 599.0
0.55 599.0
0.60 599.0
0.65 600.7
0.70 602.0
0.75 603.0
0.80 606.0
0.85 608.0
0.90 616.0
0.95 634.1
1.00 699.0
pd.Series(argmax_indexes).quantile(np.arange(0,1.05, 0.05)).plot(kind = 'bar')
它与 float64 的计算方式有关,但您可以通过调整和编写类似这样的内容以及一些示例数据来解决您的问题:
s = pd.Series([1,10,20,30,50]).quantile(np.arange(0,1.05, 0.05))
s.index = s.index.map(lambda l : np.around(l,2))
s.plot(kind = 'bar')
如果你想在一个衬里做,这应该很好用:
import numpy as np
import pandas as pd
import seaborn as sns
df = sns.load_dataset('tips')
df['tip'].quantile(np.arange(0,1.05,0.05)).reset_index().round(2).plot(kind='bar',x='index',y='tip')