Q. Given an ndarray p as ([1, 2, 3, 4]).

Write code to plot a bar chart having bars for p and p**2 (with red colour) and another bar for p vs p 2 (with blue colour). (assume that libraries have been imported)


Answer :-

import matplotlib.pyplot as plt

p =[1, 2, 3, 4]

for i in p:
    plt.bar (p[i-1], p[i-1]**2, color = 'r', width = 0.3)
    plt.bar (p[i-1] + 0.3, p[i-1]*2, color = 'b', width = 0.3)

plt.show()


Output :-

Post a Comment

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

Previous Post Next Post