0
import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns

tips = sns.load_dataset("tips")
tips['total_bill'] = tips['total_bill']*1000000 
tips['tip'] = tips['tip']*1000000 
ax = sns.scatterplot(x="total_bill", y="tip", data=tips)

So this is my code and this is the graph it outputs:

enter image description here

How can I change the X-axis and Y-axis so that it shows 1,000,000 instead of 1.0?

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158

1 Answers1

2

You can use plt.ticklabel_format(style = 'plain') ax.get_xaxis().set_major_formatter(mpl.ticker.StrMethodFormatter('{x:,.0f}')) ax.get_yaxis().set_major_formatter(mpl.ticker.StrMethodFormatter('{x:,.0f}'))

Below is the updated code

import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns

tips = sns.load_dataset("tips")
tips['total_bill'] = tips['total_bill']*1000000 
tips['tip'] = tips['tip']*1000000 
plt.ticklabel_format(style = 'plain')

ax = sns.scatterplot(x="total_bill", y="tip", data=tips)
ax.get_xaxis().set_major_formatter(mpl.ticker.StrMethodFormatter('{x:,.0f}'))
ax.get_yaxis().set_major_formatter(mpl.ticker.StrMethodFormatter('{x:,.0f}'))`

Output :

enter image description here

Tihom_Rahtus
  • 106
  • 6