1

When I pass a simple list to ax.bar(), it plots it just fine. But I have a several lists within a list. This is greatly simplified, but something like:

data = [[5,10], [7,11], [3,9]]

What I would like to do is plot a grouped bar graph so that at 0 on the x-axis I have two vertical bars, one going to 5, the other to 10. At x=1 I'd have two bars going to 7 and 11, x=2 has two bars going to 3 and 9.

My question is, is there any simple way to pass in just data? Or do I need to extract out two new lists from the master and then plot those as follows:

data_a = [5,7,3]
data_b = [10,11,9]

ax.bar(3, data_a, tick_label=range(3))
ax.bar(3, data_b, tick_label=range(3))

1 Answer 1

1

There's no built-in function for that. If you are open to other packages, you can use Pandas:

import pandas as pd
pd.DataFrame(data).plot.bar()

Output:

enter image description here

Or you need to draw them separately as you pointed out.

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

Comments

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.