Informatics Practices
Execute the following codes and find out what happens ? (Libraries have been imported already ; plt is the alias name for matplotlib.pyplot)
A = np.arange(2, 20, 2)
B = np.log(A)
plt.bar(A, B)
Will this code produce error ? Why/Why not ?
Answer
Executing the provided code will not produce an error. However, the resulting plot might not be as expected because the x-axis values are discrete and categorical, not continuous.
Output

Explanation
The line A = np.arange(2, 20, 2) creates an array A using NumPy's arange() function. It starts from 2, increments by 2, and includes values up to 20. This results in the array [2, 4, 6, 8, 10, 12, 14, 16, 18]. Next, the line B = np.log(A) calculates the natural logarithm of each element in array A using NumPy's log() function and stores the results in array B. Finally, plt.bar(A, B) creates a bar plot using Matplotlib's bar() function. It plots the values in array A along the x-axis and the corresponding values in array B along the y-axis.
Related Questions
What is Boxplot ? How do you create it in Pyplot ?
Execute the following codes and find out what happens ? (Libraries have been imported already ; plt is the alias name for matplotlib.pyplot)
A = np.arange(2, 20, 2) B = np.log(A) plt.plot(A, B)Will this code produce error ? Why/Why not ?
Execute the following codes and find out what happens ? (Libraries have been imported already ; plt is the alias name for matplotlib.pyplot)
X = np.arange(1, 18, 2.655) B = np.log(X) plt.scatter(X, Y)Will this code produce error ? Why/Why not ?
Write the output from the given python code :
import matplotlib.pyplot as plt Months = ['Dec', 'Jan', 'Feb', 'Mar'] Attendance = [70, 90, 75, 95] plt.bar(Months, Attendance) plt.show()