python bar charts code example
Example 1: bar labeling in matplotlib
import matplotlib.pyplot as plt
%matplotlib inline
plt.style.use('ggplot')
x = ['Nuclear', 'Hydro', 'Gas', 'Oil', 'Coal', 'Biofuel']
energy = [5, 6, 15, 22, 24, 8]
x_pos = [i for i, _ in enumerate(x)]
plt.bar(x_pos, energy, color='green')
plt.xlabel("Energy Source")
plt.ylabel("Energy Output (GJ)")
plt.title("Energy output from various fuel sources")
plt.xticks(x_pos, x)
plt.show()
Example 2: matplotlib bar chart
import matplotlib.pyplot as plt
names = ["Brad", "Bill", "Bob"]
ages = [9, 5, 10]
plt.bar(names, ages)
plt.show()
Example 3: bar chart in python
import numpy as npimport matplotlib.pyplot as plt
Example 4: bar chart in python
import matplotlib.pyplot as plt; plt.rcdefaults()import numpy as npimport matplotlib.pyplot as pltobjects = ('Python', 'C++', 'Java', 'Perl', 'Scala', 'Lisp')y_pos = np.arange(len(objects))performance = [10,8,6,4,2,1]plt.bar(y_pos, performance, align='center', alpha=0.5)plt.xticks(y_pos, objects)plt.ylabel('Usage')plt.title('Programming language usage')plt.show()