How to format seaborn/matplotlib axis tick labels from number to thousands or Millions? (125,436 to 125.4K)

前端 未结 4 1512
深忆病人
深忆病人 2020-11-29 08:21
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import seaborn as sns
import pandas as pd
sns.set(style="darkgrid")    
fig, ax = plt.su         


        
4条回答
  •  清酒与你
    2020-11-29 08:55

    Using Seaborn without importing matplotlib:

    import seaborn as sns
    sns.set()
    
    chart = sns.relplot(x="x_val", y="y_val", kind="line", data=my_data)
    
    ticks = chart.axes[0][0].get_xticks()
    
    xlabels = ['$' + '{:,.0f}'.format(x) for x in ticks]
    
    chart.set_xticklabels(xlabels)
    chart.fig
    

    Thank you to EdChum's answer above for getting me 90% there.

提交回复
热议问题