2

I am just wondering, how do I add a percentage (%) symbol after each value in my plot along the X axis, not converting the values to a percentage?

For example: Say I have the values 5, 10, 15, 20... How would I make them appear as 5%, 10%, 15%, 20% etc., along the X axis, but not converting them to 0.05%, 0.1%, 0.15%, 0.2% etc.

Code for my plot:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
sns.set(
  • What needs to be added to my plot code to make the percentage (%) symbol appear after each value in my X axis?
sns.displot(data=df, x="column_name", kde=True)

1 Answers1

2

PercentFormatter() should work for you as shown in the working example below:

import seaborn as sns
import numpy as np
import matplotlib.ticker as mtick
import matplotlib.pyplot as plt
np.random.seed(0)
x = np.random.randn(100)
fig, ax = plt.subplots(figsize=(16,8))
sns.distplot(x, vertical=True)

enter image description here

Then, at the end do:

ax.xaxis.set_major_formatter(mtick.PercentFormatter())

enter image description here

David Erickson
  • 16,433
  • 2
  • 19
  • 35