Skip to content Skip to sidebar Skip to footer

Bar Chart Using Matplotlib In Python

I have a list of pairs. Example: pair1=[(a,a),(b,b),(c,c),(x,y)....] In Python i need to generate a bar chart using matplotlib such that if x and y co-ordinates are same in a pair

Solution 1:

You first need to find out which pairs equal and generate a list of those results. This list can then be plotted using matplotlib.pyplot.bar.

import matplotlib.pyplot as plt

pair1=[("a","a"),("2",2),("b","b"),("c","c"),("x","y")]

f = lambda t: t[0] == t[1]
y= list(map(f, pair1))

plt.bar(range(len(y)), y)
plt.yticks([])
plt.show()

This code produces the following plot:

enter image description here

Post a Comment for "Bar Chart Using Matplotlib In Python"