2

Is there an easy way to round the xtick values in a pandas plot? I plot the quantiles and this is what I get:

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

enter image description here

user8270077
  • 4,621
  • 17
  • 75
  • 140

2 Answers2

4

It has something to do how float64 is calculated but you can solve your problem by adjusting and writing something like this , with some sample data:

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') 
milos.ai
  • 3,882
  • 7
  • 31
  • 33
1

If you want to do in one liner, this should work good:

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

output

enter image description here

BhishanPoudel
  • 15,974
  • 21
  • 108
  • 169