Q. Consider the code given below (all required libraries are imported) and the output produced by it. Why is the chart showing one bar only while we are plotting four values on the chart?


import matplotlib.pyplot as plt

a = [3, 6, 9, 12]
b = [30, 48, 54, 48]
plt.xlim(-3, 5)
plt.bar(a,b)
plt.show()


Answer :-

The given chart is showing a single bar as the limits of x-axis have been set as -3 to 5. On this range, only one value from the data range being plotted falls i.e., only a[0] and b[0] fall on this range. Thus only a single value b[0] i.e., 30 is plotted against a[0] i.e., 3.

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post