Which of the following is the standard alias used to import matplotlib.pyplot?
Plotting using Matplotlib — Important Questions
SUMMARY: This chapter focuses on teaching students how to create and customize various types of plots using the Matplotlib library in Python.
KEY TOPICS: Matplotlib library, line plot, bar chart, histogram, scatter plot, pie chart, customizing plots, labels and titles, legends, plotting multiple datasets, saving plots
Which method is used to display a plot in matplotlib?
Check answerHide answer
Which type of plot is used to show frequency distribution of a continuous variable?
Check answerHide answer
Which method is used to create a bar chart in matplotlib?
Check answerHide answer
Which method is used to add a title to a plot?
Check answerHide answer
Differentiate between bar chart and histogram with two points.
List any three types of plots that can be created using matplotlib.
How do you add labels to x-axis and y-axis in matplotlib?
Differentiate between line plot and scatter plot.
Write Python code to draw a simple line plot of [1 2 3 4 5] vs [2 4 6 8 10].
Write a Python program using matplotlib to plot the sales of 5 months as a bar chart with proper labels and title.
Discuss the importance of data visualisation and list any five chart types provided by matplotlib.
Write a Python program to draw a pie chart showing the percentage of marks of 5 subjects.
Write a Python program to plot a histogram of student marks (random data of 50 values between 0 and 100).
Discuss customisation options in matplotlib (colours markers line style legend grid) with examples.
Differentiate between bar chart and histogram in tabular form on five features.
Assertion (A): Matplotlib is a popular Python plotting library.
Reason (R): It provides MATLAB-like plotting capabilities.
Show explanationHide explanation
Assertion (A): Histogram and bar chart are different.
Reason (R): Histogram represents continuous data; bar chart represents categorical data.
Show explanationHide explanation
Assertion (A): Pie charts are best for showing parts of a whole.
Reason (R): The slices total 100 percent.
Show explanationHide explanation
Assertion (A): Line plots show trends over time.
Reason (R): Each data point is connected to the next by a line.
Show explanationHide explanation
Assertion (A): plt.savefig() saves a plot to a file.
Reason (R): The format is determined by the file extension (png pdf svg etc).
Show explanationHide explanation
Statement 1: plt.plot() draws a line graph.
Statement 2: Multiple plot() calls produce multiple lines on the same figure.
Show answerHide answer
Statement 1: plt.bar() and plt.barh() create vertical and horizontal bar charts.
Statement 2: The first argument is the categories the second is the values.
Show answerHide answer
Statement 1: plt.title() sets the chart title.
Statement 2: plt.xlabel() and plt.ylabel() set axis labels.
Show answerHide answer
Statement 1: plt.legend() displays a legend on the plot.
Statement 2: Each line/series can be labelled using the label parameter.
Show answerHide answer
Statement 1: plt.scatter() creates a scatter plot.
Statement 2: It is used to show the relationship between two variables.
Show answerHide answer
-
Which method creates a line plot?Aplt.line()Bplt.plot()Cplt.bar()Dplt.pie()
-
Which method displays a plot?Aplt.show()Bplt.display()Cplt.render()Dplt.print()
-
Write Python code to create the three plots and discuss when each is appropriate.
Show answersHide answers
Match each matplotlib chart type with its best use.
| Chart | Best for |
|---|---|
| Line plot | ? |
| Bar chart | ? |
| Histogram | ? |
| Pie chart | ? |
| Scatter plot | ? |
| Box plot | ? |
Match each matplotlib function with its purpose.
| Function | Purpose |
|---|---|
| plt.plot() | ? |
| plt.bar() | ? |
| plt.pie() | ? |
| plt.hist() | ? |
| plt.title() | ? |
| plt.show() | ? |
Match each plot customisation with its parameter.
Study the matplotlib functions table and answer:
| Function | Purpose |
|---|---|
| plt.plot() | Line plot |
| plt.bar() | Vertical bar chart |
| plt.pie() | Pie chart |
| plt.hist() | Histogram |
| plt.scatter() | Scatter plot |
| plt.title() | Set title |
| plt.show() | Display plot |
-
Which is used for frequency distribution of continuous data?Aplt.bar()Bplt.hist()Cplt.line()Dplt.pie()
-
Which creates a horizontal bar chart?Aplt.bar()Bplt.barh()Cplt.pie()Dplt.scatter()
-
Discuss any five common chart types in matplotlib and when each is appropriate.
Show answersHide answers
Study the monthly sales bar chart and answer:
-
Which month has the highest sales?AJanBFebCMayDJun
-
Which matplotlib function is used to draw this chart?Aplt.line()Bplt.bar()Cplt.pie()Dplt.hist()
-
Discuss when a bar chart is appropriate and how to create one in matplotlib.
Show answersHide answers
Study the pie chart example and answer:
-
Which subject has the highest share?AMathsBScienceCEnglishDSST
-
Which matplotlib function creates this chart?Aplt.bar()Bplt.pie()Cplt.hist()Dplt.scatter()
-
Discuss when a pie chart is appropriate and how to create one in matplotlib.
Show answersHide answers
Study the histogram example and answer:
-
The chart shown is a:ABar chartBPie chartCHistogramDLine plot
-
Which matplotlib function creates a histogram?Aplt.bar()Bplt.hist()Cplt.pie()Dplt.scatter()
-
Differentiate between histogram and bar chart and explain when to use each.
Show answersHide answers
Make a full Informatics Practices paper on Plotting using Matplotlib.
Pick the question mix, set the marks, hit generate. You get a ready-to-print paper with an answer key.
Generate your paper — free