Responsive Navbar with Google Search
☰ Menu
Home
Python
LaTeX
GNUPlot
Arduino
Feedback
Contact Us
Plotting in Python: Bar Plot
Plotting in Python
Basic Plot and formatting
Subplot, Multiplot
Colormaps in Plots
Bar Plot
Pie Chart
Histogram
Quiver plot to show Vector Fields
Stream plot to Visualize Flow Data
Polar, Parametric Plot
Contour Plot
3D Plot
Density Plot
Animated Plot
Miscellaneous
Bar Plot: Program 1
Basic Bar Plot
import matplotlib.pyplot as plt import numpy as np x = [1,2,3,4,5,6,7,8,9,10] y = [4,5,2,5,6,8,6,4,1,2] plt.bar(x, y, color='blue') plt.title('Basic Bar Plot') plt.xlabel('Category') plt.ylabel('Value') plt.savefig('barplot_1.png') plt.show()
Run Code
Output 1
Bar Plot: Program 2
import matplotlib.pyplot as plt import numpy as np x = [1,2,3,4,5,6,7,8,9,10] y = [4,5,2,5,6,8,6,4,1,2] plt.barh(x, y, color='green') plt.title('Horizontal Bar Plot') plt.xlabel('Value') plt.ylabel('Category') plt.savefig('barplot_2.png') plt.show()
Run Code
Output 2
Bar Plot: Program 3
Stacked Bar Plot
import matplotlib.pyplot as plt import numpy as np x = [1,2,3,4,5,6,7,8,9,10] y1 = [4,5,2,5,6,8,6,4,1,2] y2 = [1,4,5,6,2,3,6,8,4,5] plt.bar(x, y1, color='blue', label='Series 1') plt.bar(x, y2, bottom=y1, color='orange', label='Series 2') plt.title('Stacked Bar Plot') plt.xlabel('Category') plt.ylabel('Value') plt.legend() plt.savefig('barplot_3.png')
Run Code
Output 3
Bar Plot: Program 4
Group Bar Plot
import matplotlib.pyplot as plt import numpy as np x = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) y1 = [4,5,2,5,6,8,6,4,1,2] y2 = [1,4,5,6,2,3,6,8,4,5] width = 0.35 plt.bar(x - width/2, y1, width, color='blue', label='Group 1') plt.bar(x + width/2, y2, width, color='green', label='Group 2') plt.title('Grouped Bar Plot') plt.xlabel('Category') plt.ylabel('Value') plt.legend() plt.savefig('barplot_4.png')
Run Code
Output 4