Issue
Below I have an example of a simple horizontal bar chart made in Python 3 with Matplotlib:
from matplotlib import pyplot as plt
labels = ['Dog', 'Cat', 'Dog', 'Mouse']
amounts = [5, 10, 12, 30]
plt.barh(labels, amounts)
plt.show()
Which produces the following graph:
As you can see, the default behavior is that the first "Dog" label and value gets ignored. However, I would like for two separate "Dog" points to be graphed, one at 5 and one at 12. How would I go about accomplishing this?
Solution
First plot by unique ticks and then rename
from matplotlib import pyplot as plt
labels = ['Dog', 'Cat', 'Dog', 'Mouse']
ticks = range(len(labels))
amounts = [5, 10, 12, 30]
fig = plt.barh(ticks, amounts)
plt.yticks(ticks, labels)
plt.show()
Answered By - user_na
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.