Posted on:

11 Jun 2025

0

Import counters II

For question 5 in exercise under Import counters II, I need to create a bar graph. 
I am writing the code for plotting as such -
import matplotlib.pyplot as plt

x,y = zip(*d.items())
plt.bar(x,y)

However, when I execute this program, the console throws an error - 
  
  File c:\users\mohammadburairabbas\python coding.py:1015
    plt.bar(x,y)

TypeError: 'tuple' object is not callable

What is the reason for this error? And how to resolve it?

Is the code considering the parentheses for tuple as a function?

EDIT - After I rewrite the code again and adding the line 
      'plt.show()'
the error showing is the following, 

I can deselect the 'Mute inline plotting' to show it in the console, however my main question here is "Why I need to add plt.show()" in order for the code to plot the bar when in the exercise, the instructor did not mention this line of code? May I know the reason why I need to add this linwe while the instructor did not???






0 answers ( 0 marked as helpful)

Submit an answer