0

I have a list of arrays each with 1 row and 2 cols (list=array([1.3, 4.5]), array([1.4, 6.8]), array([2.5, 2.88]).

I want to plot bar graph, where each col values of each array(say they are array([x, y]) are plotted side by side, x has same color for all values and y has same color for all values.

How can I go about it?

like this:

enter image description here

Thanks!

Savannah
  • 45
  • 5

1 Answers1

0

Actually there is an similar answer in here.

I took it and made some changes for your problem:

import matplotlib.pyplot as plt

# List to plot
a = [1.3, 1.4, 2.5]
b = [4.5, 6.8, 2.88]
# Some properties for the plot
alpha = 0.7
bar_width = 0.35
# LAbels for the both axis
plt.xlabel('x-label')
plt.ylabel('y-label')
# bar-plot
bar1 = plt.bar(np.arange(len(a)) + bar_width, a, bar_width, align='center', alpha=opacity, color='b', label='a-List')
bar2 = plt.bar(range(len(b)), b, bar_width, align='center', alpha=alpha, color='g', label='b-List')

# Add numbers above the two bar graphs
for rect in bar1 + bar2:
    height = rect.get_height()
    plt.text(rect.get_x() + rect.get_width() / 2.0, height, f'{height}', ha='center', va='bottom')

plt.legend()
plt.tight_layout()
plt.show()
coco18
  • 836
  • 8
  • 18