Adrian
Adrian

Reputation: 163

How to set bar chart to use just the values passed into the bar function?

This code to display a simple bar chart:

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()

x = [1]
height = [8]
width = 1.0

plt.bar(x, height, width, color='b' )

plt.savefig('SimpleBar.png')
plt.show()

produces:

enter image description here

How to display a single value for the bar? In this case, display 1 instead of 0.6,0.8,1.0,1.2,1.4

Upvotes: 0

Views: 49

Answers (1)

gunsodo
gunsodo

Reputation: 175

Try this.

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()

x = [1]
height = [8]
width = 1.0

plt.bar(x, height, width, color='b')
plt.xticks([1])                                     # add this line
plt.show()

Output

There is the documentation for you to read more.

Upvotes: 2

Related Questions