2

Can anyone tell me how to move the grid of a matplotlib plot to the background, so that the bars are fully visible?

import matplotlib.pyplot as plt

data = [29, 45, 56]

plt.bar(range(len(data)), data)
plt.grid(axis='y')
plt.show()

Figure

tfv
  • 6,016
  • 4
  • 36
  • 67

1 Answers1

3

You can add ax.set_axisbelow(True)

import matplotlib.pyplot as plt

x = data = [29, 45, 56]
y = range(len(data))

fig, ax = plt.subplots()

plot = ax.bar(y,x)

ax.yaxis.grid(True, color ="green", lw = 1)
ax.set_axisbelow(True)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_title('Title', fontsize = 12, fontweight ='bold')
plt.show()

enter image description here

Hessamj
  • 46
  • 3