how to draw a bar graph in python 1

how to draw a bar graph in python

import matplotlib.pyplot as plt 

data = [5., 25., 50., 20.]
plt.bar(range(len(data)),data)
plt.show()

// to set the thickness of a bar, we can set 'width'
// plt.bar(range(len(data)), data, width = 1.)

Here is what the above code is Doing:
1. We create a list of numbers, data.
2. We call plt.bar() to create a bar chart.
3. We pass in the x-axis values and the y-axis values.
4. We call plt.show() to display the bar chart.

Similar Posts