Gurkirat has to fill in the blanks in the given Python program that generates a line plot as shown below. The given line plot represents the temperature (in degree Celcius) over five days as given in the table:
| Days | Temperature |
|---|---|
| Day 1 | 30 |
| Day 2 | 32 |
| Day 3 | 31 |
| Day 4 | 29 |
| Day 5 | 28 |
import ______ as plt # Statement-1 days = ['Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5'] temp = [30, 32, 31, 29, 28] plt.(days, temp) # Statement-2 plt.xlabel('') # Statement-3 plt.ylabel('Temperature') plt.title('______') # Statement-4 plt.show() Write the missing statements according to the given specifications:
- Write the suitable code to import the required module in the blank space in the line marked as Statement-1.
- Fill in the blank in Statement-2 with a suitable Python function name to create a line plot.
- Refer to the graph shown and fill in the blank in Statement-3 to display the appropriate label for x-axis.
- Refer to the graph shown and fill in the blank in Statement-4 to display the suitable chart title.
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →The Python program uses the matplotlib.pyplot module to create a line plot, with plt.plot() drawing the graph, plt.xlabel() labeling the x-axis as 'Days', and plt.title() setting the chart title to 'Daily Temperature'.
Data visualization is a powerful technique for understanding and communicating insights from data. Instead of looking at raw numbers in a table, a visual representation like a line plot allows us to quickly spot trends, patterns, and anomalies. For Gurkirat's task, we are using Python's matplotlib library, which is a fundamental tool for creating static, animated, and interactive visualizations in Python.
A line plot is particularly effective for showing how a variable changes over a continuous range, such as time. In this case, we are tracking temperature changes across five consecutive days. Each point on the line plot represents the temperature on a specific day, and these points are connected by lines to illustrate the progression.
Let's break down the Python code statement by statement to understand its purpose and fill in the blanks.
-
Statement-1:
import ______ as pltTo use the plotting functionalities of Matplotlib, we need to import its
pyplotmodule. It is a common convention to importpyplotand give it the aliasplt, which makes the code shorter and easier to read. This module contains functions for creating various types of plots, including line plots, bar charts, and scatter plots.Importantmatplotlib.pyplotis the standard module for creating plots in Matplotlib, andpltis its widely accepted alias. -
Statement-2:
plt.______(days, temp)After importing the module, the next step is to actually create the line plot. The
pltobject, which refers tomatplotlib.pyplot, has a specific function for drawing line graphs. This function takes two main arguments: the data for the x-axis and the data for the y-axis. In Gurkirat's program,dayswill be plotted on the x-axis andtempon the y-axis. -
Statement-3:
plt.xlabel('______')…
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.