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()
Source: benalexkeen.com
bar plot matplotlib
import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_axes([0,0,1,1]) langs = ['C', 'C++', 'Java', 'Python', 'PHP'] students = [23,17,35,29,12] ax.bar(langs,students) plt.show()
Source: www.tutorialspoint.com
how to plotting bar on matplotlib
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.)
bar plot python
import matplotlib.pyplot as plt import numpy as np plt.bar(np.arange(0,100),np.arange(0,100))
matplotlib bar chart
import numpy as np import matplotlib.pyplot as plt # creating the dataset data = {'C':20, 'C++':15, 'Java':30, 'Python':35} courses = list(data.keys()) values = list(data.values()) fig = plt.figure(figsize = (10, 5)) # creating the bar plot # the format of the bar() method is: # plt.bar(x_value, y_value, color, width_of_bars_inches) plt.bar(courses, values, color ='maroon', width = 0.4) # x-axis label plt.xlabel("Courses offered") # y-axis label plt.ylabel("No. of students enrolled") # Title of the figure plt.title("Students enrolled in different courses") plt.show()
Source: www.geeksforgeeks.org