Matplotlib MCQs

There are different libraries present in Python; Matplotlib is one of them. Matplotlib is a popular Python library. It is used for data visualizations. It has different functions and tools that can be used to make charts, plots, and graphs. Matplotlib is most widely used in data science, analytics, scientific research, engineering, finance, and different other domains for data visualization and exploration.

Matplotlib MCQs with Answers and Explanation

Matplotlib MCQs: This section contains multiple-choice questions and answers on Matplotlib. These MCQs are written for beginners as well as advanced, practice these MCQs to enhance and test the knowledge of Matplotlib.

List of Matplotlib MCQs

1. Who created Matplotlib?

  1. John D. Hunter
  2. Pearu Peterson
  3. Robert Kern
  4. Stéfan van der Walt

Answer: A) John D. Hunter

Explanation:

Matplotlib was created by John D. Hunter. Who was an American neurobiologist and the original author of Matplotlib.

Discuss this question


2. Is Matplotlib open-source and free?

  1. Yes
  2. No

Answer: A) Yes

Explanation:

Yes. Matplotlib is open-source and free.

Discuss this question


3. Matplotlib is designed to be as usable as ____.

  1. SciPy
  2. MATLAB
  3. AI
  4. All of the above

Answer: B) MATLAB

Explanation:

Matplotlib is designed to be as usable as MATLAB, with the ability to use Python.

Discuss this question


4. Matplotlib is a ____ library for the Python programming language.

  1. data science
  2. mathematics
  3. numpy
  4. plotting

Answer: D) plotting

Explanation:

Matplotlib is a plotting library for the Python programming language.

Discuss this question


5. Matplotlib can be used in which GUI toolkits?

  1. Tkinter
  2. wxPython
  3. Qt
  4. All of the above

Answer: D) All of the above

Explanation:

The correct answer is all of the above. Matplotlib can be used in GUI toolkits like Tkinter, wxPython, Qt, or GTK.

Discuss this question


6. Which is the correct command to install Matplotlib?

  1. pip install matplotlib
  2. pip install matplotlib.pz
  3. pip install matplotlib.*
  4. All of the above

Answer: A) pip install matplotlib

Explanation:

If Python and PIP are installed in your system, then you can easily install the matplotlib library by using the below-given command –

pip install matplotlib

Discuss this question


7. Which is the correct import statement to import the matplotlib module?

  1. import matplotlib from mat
  2. import matplotlib
  3. import matplotlib from plotting
  4. import matplotlib from plots

Answer: B) import matplotlib

Explanation:

The correct import statement to import the matplotlib module is:

import matplotlib

Discuss this question


8. Which method/attribute is used to check the installed version of matplotlib?

  1. __version__
  2. version()
  3. Both A and B
  4. None of the above

Answer: A) __version__

Explanation:

The __version__ attribute of matplotlib can be used to check the currently installed version of the matplotlib module. Consider the below-given example –

import matplotlib
print(matplotlib.__version__)

Discuss this question


9. Which is the correct import statement to import pyplot?

  1. import matplotlib.pyplot as plt
  2. import pyplot from matplotlib
  3. Both A and B
  4. None of the above

Answer: A) import matplotlib.pyplot as plt

Explanation:

The pyplot is the most useful utility /submodule of matplotlib and the correct import statement to import pyplot is:

import matplotlib.pyplot as plt

Discuss this question


10. Which function is used to draw points (markers) in a diagram?

  1. write()
  2. draw()
  3. plot()
  4. paint()

Answer: C) plot()

Explanation:

The plot() function is used to draw points (markers) in a diagram. The syntax of plot() function is –

plot(x, y, scalex, scaley, data, **kwargs)

Discuss this question


11. Which is the correct code statement to draw a plot without a line?

  1. plt.plot(xpoints, ypoints)
  2. plt.plot(xpoints, ypoints, 0)
  3. plt.plot(xpoints, ypoints, False)
  4. plt.plot(xpoints, ypoints, 'o')

Answer: D) plt.plot(xpoints, ypoints, 'o')

Explanation:

You can draw a plot without lines by specifying the string notation parameter 'o', which means 'rings'. The correct code statement to draw a plot without a line is:

plt.plot(xpoints, ypoints, 'o')

Discuss this question


12. Which argument keyword can be used to emphasize each point with a specified marker in plotting?

  1. marker_points
  2. marker
  3. ring
  4. types

Answer: B) marker

Explanation:

When you want to highlight each point with a specified marker, you can use the keyword argument marker with the specified value. Consider the below code statement that can be used to highlight the points with rings –

plt.plot(ypoints, marker = 'o')

Here is the list of the values to highlight the point with a special marker: Reference

Marker Description
'o' Circle
'*' Star
'.' Point
',' Pixel
'x' X
'X' X (filled)
'+' Plus
'P' Plus (filled)
's' Square
'D' Diamond
'd' Diamond (thin)
'p' Pentagon
'H' Hexagon
'h' Hexagon
'v' Triangle Down
'^' Triangle Up
'<' Triangle Left
'>' Triangle Right
'1' Tri Down
'2' Tri Up
'3' Tri Left
'4' Tri Right
'|' Vline
'_' Hline

Discuss this question


13. Which argument keyword can be used to change the style of the plotted line?

  1. line
  2. lines
  3. linestyles
  4. linestyle

Answer: D) linestyle

Explanation:

When you want to change the style of the plotted line, you can use the keyword argument linestyle with the specified value. Consider the below code statement that can be used to change the style of the plotted line –

plt.plot(ypoints, linestyle = 'dotted')

Discuss this question


14. What is the shorter keyword for the keyword argument 'linestyle' to change the style of the plotted line?

  1. line
  2. lines
  3. style
  4. ls

Answer: D) ls

Explanation:

The shorter keyword for the keyword argument linestyle to change the style of the plotted line is: ls.

plt.plot(ypoints, ls = 'dotted')

Discuss this question


15. Which function is used to set a label for the x-axis in pyplot?

  1. xlabel()
  2. set_x()
  3. x-axis()
  4. xaxi()

Answer: A) xlabel()

Explanation:

The xlabel() function is used to set a label for the x-axis. Consider the below code statement to set the x-axis.

plt.xlabel("Average Salary")

Discuss this question


16. Which function is used to set a label for the y-axis in the pyplot?

  1. ylabel()
  2. set_y()
  3. y-axis()
  4. yaxis()

Answer: A) ylabel()

Explanation:

The ylabel() function is used to set a label for the y-axis. Consider the below code statement to set the y-axis.

plt.ylabel("Year")

Discuss this question


17. Which function is used to set a title for the plot?

  1. desc()
  2. title()
  3. head()
  4. None of the above

Answer: B) title()

Explanation:

The title() function is used to set a title for the plot. Consider the below code statement to set a title for the plot –

plt.title("Employee Details")

Discuss this question


18. Which parameter is used to set the font properties for the plot?

  1. fontdict
  2. fonts
  3. fontfamily
  4. plotfonts

Answer: A) fontdict

Explanation:

The fontdict parameter is used to set the font properties for the plot. Consider the below syntax of using fontdict parameter –

# define font properties
font1 = {'family':'Arial','color':'Red','size':17}
# Apply font properties to title
plt.title("Employee Data", fontdict = font1)

Discuss this question


19. The 'fontdict' parameter can be used with which function(s)?

  1. xlabel()
  2. ylabel()
  3. title()
  4. All of the above

Answer: D) All of the above

Explanation:

The fontdict parameter is used with xlabel(), ylabel(), and title() functions to set font properties for the title and labels.

Discuss this question


20. Which parameter is used to define the position/alignment of the plot title in the title() function?

  1. pos
  2. align
  3. loc
  4. All of the above

Answer: C) loc

Explanation:

The loc parameter is used to define the position/alignment of the plot title in the title() function with the following values –

  • left
  • right
  • center

Where "center" is the default value.

Consider the below code statement –

plt.title("Employee Data", loc = 'left')

Discuss this question


21. Which function is used to add grid lines to the plot?

  1. gridlines()
  2. grids()
  3. grid()
  4. gridmarks()

Answer: C) grid()

Explanation:

The grid() function is used to add grid lines to the plot. The syntax of the gird() function is –

# import statement
import matplotlib.pyplot as plt
...
...
plt.plot(x, y) # Draw plot
plt.grid() # Add grids
plt.show() # Show plot with grids

Discuss this question


22. Which is/are the parameter(s) that can be used in grid() function to specify the line properties?

  1. color
  2. linestyle
  3. linewidth
  4. All of the above

Answer: D) All of the above

Explanation:

The all of the above parameters (color, linestyle, and linewidth) can be used in grid() function to set the various line properties.

plt.grid(color = 'Yellow', linestyle = '--', linewidth = 0.9)

Discuss this question


23. Which function is used to draw multiple figures in one plot?

  1. subplot()
  2. subplots()
  3. pyplots()
  4. subpyplot()

Answer: A) subplot()

Explanation:

The subplot() function is used to draw multiple figures in one plot. This function takes three arguments to specify the layout of the figure.

Discuss this question


24. In the case of multiple figures drawn by using the subplot() function, which function is used to set the title to the entire figure?

  1. subplot()
  2. subplots()
  3. pyplots()
  4. subpyplot()

Answer: A) subplot()

Explanation:

If you have drawn multiple figures in one plot by using the subplot() function and want to set the title of the entire figure. You can use suptitle() function. The suptitle() function sets the title of the entire figure having multiple figures.

Discuss this question


25. Which function is used to draw a scatter plot?

  1. scatterplot()
  2. pyscatter()
  3. scatters()
  4. scatter()

Answer: D) scatter()

Explanation:

To draw a scatter plot, you can simply use the scatter() function. This function is used to plot one dot for each observation. It accepts two arrays of the same length for the x and y-axis.

plt.scatter(x, y)

Where x and y can be the NumPy arrays.

Discuss this question


26. Which parameter(s) is/are used to define the color of the points in a scatter plot?

  1. color
  2. c
  3. Both A and B
  4. None of the above

Answer: C) Both A and B

Explanation:

The color and its shorter c both can be used to define the color of the points in a scatter plot.

plt.scatter(x, y, color = 'Blue')

Where x and y can be the NumPy arrays.

Discuss this question


27. Which function is used to draw bar graphs?

  1. bar()
  2. bars()
  3. barchat()
  4. barplot()

Answer: A) bar()

Explanation:

To draw a bar graph, you can use the bar() function. Consider the below code statement to draw a bar graph –

name = ["Alvin", "Alex"]
age = [21, 23]
plt.bar(name, age)

Discuss this question


28. Why barh() function is used in plotting?

  1. To draw a bar graph with a specified height
  2. To draw a bar graph to print the highest values of a NumPy array
  3. To draw a horizontal bar graph
  4. None of the above

Answer: C) To draw a horizontal bar graph

Explanation:

The barh() function is used to draw a horizontal bar graph. The barh() function takes the same arguments as the "bar()" function. Consider the below code statement to draw a horizontal bar graph –

name = ["Alvin", "Alex"]
age = [21, 23]
plt.barh(name, age)

Discuss this question


29. In a horizontal bar graph, which parameter is used to set the height of the bars?

  1. height
  2. barheight
  3. hgt
  4. bheight

Answer: A) height

Explanation:

In a horizontal bar graph, the height parameter is used to set the height of the bars. Consider the below code statement –

name = ["Alvin", "Alex"]
age = [21, 23]
plt.barh(name, age , height = 0.1)

Discuss this question


30. Which function is used to create histograms in matplotlib?

  1. histograms()
  2. histogram()
  3. histgraph()
  4. hist()

Answer: D) hist()

Explanation:

In Matplotlib, the hist() function is used to create histograms. A histogram is a graph showing frequency distributions.

Discuss this question


31. How to print a list of styles available in Matplotlib in order to let you tailor your visualization based on your needs?

  1. print(plt.style)
  2. print(plt.style.available)
  3. print(plt.styles)
  4. print(plt.styles.available)

Answer: B) print(plt.style.available)

Explanation:

To print a list of styles available in Matplotlib in order to let you tailor your visualization based on your needs, you can use plt.style.available. Consider the below print statement –

print(plt.style.available)

The output would be –

['Solarize_Light2', '_classic_test_patch', '_mpl-gallery', '_mpl-gallery-nogrid', 'bmh', 'classic', 'dark_background', 'fast', 'fivethirtyeight', 'ggplot', 'grayscale', 'seaborn-v0_8', 'seaborn-v0_8-bright', 'seaborn-v0_8-colorblind', 'seaborn-v0_8-dark', 'seaborn-v0_8-dark-palette', 'seaborn-v0_8-darkgrid', 'seaborn-v0_8-deep', 'seaborn-v0_8-muted', 'seaborn-v0_8-notebook', 'seaborn-v0_8-paper', 'seaborn-v0_8-pastel', 'seaborn-v0_8-poster', 'seaborn-v0_8-talk', 'seaborn-v0_8-ticks', 'seaborn-v0_8-white', 'seaborn-v0_8-whitegrid', 'tableau-colorblind10']

Discuss this question


32. How to activate a style (for example, you want to activate 'fivethirtyeight' style) in Matplotlib?

  1. plt.style.use('fivethirtyeight')
  2. plt.style.apply('fivethirtyeight')
  3. plt.style('fivethirtyeight')
  4. plt.style.activate('fivethirtyeight')

Answer: A) plt.style.use('fivethirtyeight')

Explanation:

To activate a style in Matplotlib, you can use plt.style.use() function. Consider the below code statement to apply a style named "fivethirtyeight" –

plt.style.use('fivethirtyeight')

Discuss this question


33. Which plot is also known as the 'Whisker plot' in Matplotlib?

  1. Bar
  2. Pie
  3. Histogram
  4. Box plot

Answer: D) Box plot

Explanation:

The Box plot is also known as the Whisker plot.

Discuss this question


34. Which is used for plotting a horizontal line?

  1. hline()
  2. ahline()
  3. xhline()
  4. axhline()

Answer: D) axhline()

Explanation:

For plotting a horizontal line, you can simply use the axhline() function.

Syntax:
matplotlib.pyplot.axhline(y, color, xmin, xmax, linestyle)

Discuss this question


35. Which function is used to save a Matplotlib plot as an image file?

  1. saveimage()
  2. saveimg()
  3. savefig()
  4. exportimgfig()

Answer: C) savefig()

Explanation:

The savefig() function is used to save a Matplotlib plot as an image file.

Discuss this question


36. Which color is the default color of a Matplotlib plot?

  1. Red
  2. Green
  3. Blue
  4. Black

Answer: C) Blue

Explanation:

Blue is the default color of a Matplotlib plot.

Discuss this question


37. What is referred to as the graphical representation of data?

  1. Data Visualization
  2. Data Analysis
  3. Data Handling
  4. Data Plotting

Answer: A) Data Visualization

Explanation:

Data Visualization is referred to as a graphical representation of data.

Discuss this question


38. What is the default type of a histogram in Matplotlib?

  1. Line
  2. Bar
  3. Dotted lines
  4. Dashed lines

Answer: B) Bar

Explanation:

The default type of a histogram is Bar in Matplotlib.

Discuss this question


39. Which function is used to create a box plot in Matplotlib?

  1. plt.plot(type='box')
  2. plt.createbox()
  3. plt.plotbox()
  4. plt.boxplot()

Answer: D) plt.boxplot()

Explanation:

The plt.boxplot() function is used to create a box plot in Matplotlib.

Discuss this question


40. What is Pyplot is Matplotlib?

  1. Function
  2. Collection
  3. Class
  4. Module

Answer: D) Module

Explanation:

Pyplot is a Matplotlib module that provides a MATLAB-like interface.

Discuss this question


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.