KnowledgeBoat Logo
|

Informatics Practices

Anirudh is trying to write a code to plot line graph shown in the figure below. Help him fill in the blanks in the code and get the desired output.

Anirudh is trying to write a code to plot line graph shown in the figure below. Help him fill in the blanks in the code and get the desired output. Data Visualization using Matplotlib, Informatics Practices Preeti Arora Solutions CBSE Class 12
import matplotlib.pyplot as plt             # statement 1
x = [1, 2, 3]                               # statement 2
y = [2, 4, 1]                               # Statement 3
plt.plot(x, y, color = 'g')                 # statement 4
...............                             # statement 5
...............                             # statement 6
# giving a title to graph
plt. ............... ('My first graph!')    # statement 7
# Function to show the plot 
...............                             # statement 8

(i) Which of the above statements is responsible for plotting the values on canvas?

  1. Statement 8
  2. Statement 4
  3. Statement 1
  4. None of these

(ii) Statements 5 & 6 are used to give names to X-axis and Y-axis as shown in Fig.1. Which of the following can fill those two gaps?

1.

plt.xlabel('X - axis') 
plt.ylabel('Y - axis')

2.

plt.xtitle('x - axis')
plt.ytitle('y - axis')

3.

plt.xlable('x - axis')
pit.ylable('x - axis') 

4.

plt.xlabel('x axis')
plt.ylabel('y axis')

(iii) Raman has executed code with first 7 statements but no output is displayed. Which of the following statements will display the graph?

  1. plt.display()
  2. plt.show()
  3. matplotlib.pyplot.display()
  4. Both (b) & (c)

(iv) The number of markers in the above line chart are:

  1. Zero
  2. Three
  3. Infinite
  4. Not defined

(v) Which of the following methods will result in displaying 'My first graph!' in the above graph?

  1. legend()
  2. label()
  3. title()
  4. Both (a) & (c)

PyPlot

1 Like

Answer

(i) Statement 4

Reason — The plt.plot() statement is used to plot y versus x data on the canvas in Matplotlib.

(ii)

plt.xlabel('X - axis') 
plt.ylabel('Y - axis')

Reason — The xlabel() and ylabel() functions are used to give labels to x-axis and y-axis respectively.

(iii) plt.show()

Reason — The plt.show() statement is used to display the graph.

(iv) Three

Reason — There are three markers in the line chart, corresponding to the three data points (1, 2), (2, 4), and (3, 1).

(v) title()

Reason — The plt.title() method is used to set the title of the graph, which in this case is "My first graph!".

Answered By

3 Likes


Related Questions