CBSE Class 12 Informatics Practices
Question 120 of 147
Plotting with Pyplot — Question 3
Back to all questionsThe code will produce an error because the variable Y is not defined.
The corrected code is:
X = np.arange(1, 18, 2.655)
B = np.log(X)
plt.scatter(X, B)
The line X = np.arange(1, 18, 2.655) creates an array X using NumPy's arange() function. It starts from 1, increments by 2.655, and generates values less than 18. The resulting array will look like [1., 3.655, 6.31, 8.965, 11.62, 14.275, 16.93]. Next, the line B = np.log(X) calculates the natural logarithm of each element in array X using NumPy's log() function. Finally, the line plt.scatter(X, Y) attempts to use Matplotlib's scatter() function to create a scatter plot. However, Y is not defined in code, leading to a NameError.