0

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 the bar chart should come to the maximum extent or else in case of (x,y) they are different and hence the bar chart should be at the 0 level. So please do help me out with the code in Python.

1

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

5 Comments

how to add scrolling bar to this if the series is long, equal spacing between 2 adjacent bars, same colour and printing the x value exaclty below its bar and removing the y ticks....do help me ..since I m new to Python
This is not a code writing service. While the code already has most of those features in, for each of the questions there are answers around somewhere. Scrollbars are not easy, you may start looking at a scrollbar for QT, wxpython or using a SliderWidget
WTF if you dont know please .. @ImportanceOfBeingErnest
Sure I know it. I wrote for example this answer. You may copy it and use it if you like.
but where can i include the above code of urs there

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.