0% found this document useful (0 votes)
5 views12 pages

Matplotlib

The document contains a series of questions and answers related to the Matplotlib library, focusing on its functionalities for data visualization. It includes basic, intermediate, and hard level questions covering various aspects such as plotting functions, customization options, and specific features like creating subplots and handling different plot types. Each question is followed by the correct answer, providing a comprehensive overview of Matplotlib usage.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views12 pages

Matplotlib

The document contains a series of questions and answers related to the Matplotlib library, focusing on its functionalities for data visualization. It includes basic, intermediate, and hard level questions covering various aspects such as plotting functions, customization options, and specific features like creating subplots and handling different plot types. Each question is followed by the correct answer, providing a comprehensive overview of Matplotlib usage.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

1. **What is Matplotlib primarily used for?

**

- a) Data processing

- b) Data visualization

- c) Machine learning

- d) Statistical analysis

**Answer**: b) Data visualization

2. **Which function is used to create a simple line plot in Matplotlib?**

- a) plt.bar()

- b) plt.scatter()

- c) plt.plot()

- d) plt.hist()

**Answer**: c) plt.plot()

3. **What does the `plt.show()` function do?**

- a) Saves the plot to a file

- b) Displays the plot on the screen

- c) Closes the current plot

- d) Clears the current plot

**Answer**: b) Displays the plot on the screen

4. **Which function is used to create a scatter plot in Matplotlib?**

- a) plt.scatter()

- b) plt.plot()

- c) plt.line()

- d) plt.pie()

**Answer**: a) plt.scatter()

5. **In Matplotlib, what does the `xlabel()` function do?**


- a) Sets the title of the plot

- b) Sets the x-axis label

- c) Sets the y-axis label

- d) Adds a grid to the plot

**Answer**: b) Sets the x-axis label

6. **How can you save a Matplotlib figure to a file?**

- a) plt.save()

- b) plt.export()

- c) plt.savefig()

- d) plt.write()

**Answer**: c) plt.savefig()

7. **What is the default figure size of a Matplotlib plot?**

- a) 6x4 inches

- b) 8x6 inches

- c) 10x8 inches

- d) 5x5 inches

**Answer**: a) 6x4 inches

8. **Which command adds a grid to a Matplotlib plot?**

- a) plt.grid()

- b) plt.show_grid()

- c) plt.add_grid()

- d) plt.set_grid()

**Answer**: a) plt.grid()

9. **What type of chart is created with `plt.pie()`?**

- a) Bar chart

- b) Line chart

- c) Pie chart
- d) Scatter plot

**Answer**: c) Pie chart

10. **How do you change the color of a line in a plot?**

- a) plt.color()

- b) plt.line_color()

- c) plt.plot(color='red')

- d) plt.set_color('red')

**Answer**: c) plt.plot(color='red')

11. **What does `plt.legend()` do in a plot?**

- a) Displays the plot title

- b) Shows the figure size

- c) Displays labels for different plot elements

- d) Adds a grid to the plot

**Answer**: c) Displays labels for different plot elements

12. **Which of the following is used to create subplots in Matplotlib?**

- a) plt.subplot()

- b) plt.subplots()

- c) plt.grid()

- d) plt.add_subplot()

**Answer**: b) plt.subplots()

13. **What does the `plt.xticks()` function do?**

- a) Sets the limits for the x-axis

- b) Sets the ticks on the x-axis

- c) Hides the x-axis

- d) Changes the title of the x-axis

**Answer**: b) Sets the ticks on the x-axis


14. **Which of the following is a valid way to set the title of a plot?**

- a) plt.title('My Plot')

- b) plt.set_title('My Plot')

- c) plt.plot_title('My Plot')

- d) plt.title() = 'My Plot'

**Answer**: a) plt.title('My Plot')

15. **In Matplotlib, which function is used to create a histogram?**

- a) plt.scatter()

- b) plt.plot()

- c) plt.hist()

- d) plt.bar()

**Answer**: c) plt.hist()

---

### **Intermediate Level Questions (15)**

1. **Which Matplotlib function is used to create a box plot?**

- a) plt.boxplot()

- b) plt.bplot()

- c) plt.scatter()

- d) plt.plot()

**Answer**: a) plt.boxplot()

2. **What is the purpose of the `figsize` parameter in `plt.subplots()`?**

- a) To specify the size of the title

- b) To set the size of the individual subplots

- c) To set the size of the entire figure

- d) To specify the number of subplots

**Answer**: c) To set the size of the entire figure


3. **What is the effect of setting `plt.ylim([0, 10])`?**

- a) Sets the y-axis limits from 0 to 10

- b) Hides the y-axis

- c) Changes the y-axis scale

- d) Displays the y-axis ticks

**Answer**: a) Sets the y-axis limits from 0 to 10

4. **How can you change the style of a plot to 'ggplot'?**

- a) plt.style.use('ggplot')

- b) plt.set_style('ggplot')

- c) plt.style('ggplot')

- d) plt.change_style('ggplot')

**Answer**: a) plt.style.use('ggplot')

5. **Which of the following is a method to customize markers in a plot?**

- a) marker='x' in plt.plot()

- b) plt.marker()

- c) plt.set_marker('x')

- d) marker_type='x' in plt.plot()

**Answer**: a) marker='x' in plt.plot()

6. **What is the default marker style in a Matplotlib line plot?**

- a) Circle

- b) Square

- c) No marker

- d) Triangle

**Answer**: c) No marker

7. **Which parameter would you use to set the transparency of a plot?**

- a) alpha
- b) transparency

- c) opacity

- d) set_alpha()

**Answer**: a) alpha

8. **How do you create a 3D plot in Matplotlib?**

- a) Using `mpl_toolkits.mplot3d`

- b) Using `plt.plot3d()`

- c) Using `plt.three_d()`

- d) Using `plt.show_3d()`

**Answer**: a) Using `mpl_toolkits.mplot3d`

9. **What does the `tight_layout()` function do?**

- a) Adjusts subplot parameters to give specified padding

- b) Changes the size of the figure

- c) Clears all plots

- d) Adds a grid to the plot

**Answer**: a) Adjusts subplot parameters to give specified padding

10. **Which command would you use to annotate a point in a plot?**

- a) plt.annotate()

- b) plt.text()

- c) plt.label()

- d) plt.point()

**Answer**: a) plt.annotate()

11. **How can you display multiple plots in a single figure?**

- a) By calling `plt.plot()` multiple times

- b) Using `plt.subplots()` to create multiple axes

- c) Using `plt.multi_plot()`

- d) By using a loop to create separate figures


**Answer**: b) Using `plt.subplots()` to create multiple axes

12. **In Matplotlib, what does the `set_xlim()` function do?**

- a) Sets the y-axis limits

- b) Sets the x-axis ticks

- c) Sets the x-axis limits

- d) Sets the plot title

**Answer**: c) Sets the x-axis limits

13. **What type of plot is best used for visualizing the relationship between two continuous
variables?**

- a) Bar plot

- b) Pie chart

- c) Line plot

- d) Scatter plot

**Answer**: d) Scatter plot

14. **Which function would you use to plot error bars in Matplotlib?**

- a) plt.errorbar()

- b) plt.bar()

- c) plt.scatter()

- d) plt.plot_error()

**Answer**: a) plt.errorbar()

15. **What is the purpose of the `linestyle` parameter in Matplotlib?**

-a

) To change the marker style

- b) To set the line style (e.g., solid, dashed)

- c) To set the figure size

- d) To change the color of the line


**Answer**: b) To set the line style (e.g., solid, dashed)

---

### **Hard Level Questions (20)**

1. **Which of the following commands can be used to modify the tick parameters in a plot?**

- a) plt.tick_params()

- b) plt.set_ticks()

- c) plt.modify_ticks()

- d) plt.adjust_ticks()

**Answer**: a) plt.tick_params()

2. **What is the function used to create a histogram with normalized values in Matplotlib?**

- a) plt.hist(normalize=True)

- b) plt.hist(density=True)

- c) plt.hist(scale=True)

- d) plt.hist(norm=True)

**Answer**: b) plt.hist(density=True)

3. **In a heatmap, which function is primarily used to create the visualization?**

- a) plt.pcolor()

- b) plt.imshow()

- c) plt.heatmap()

- d) Both a and b

**Answer**: d) Both a and b

4. **Which Matplotlib feature allows for interactive data exploration?**

- a) plt.plot()

- b) mpld3

- c) plt.scatter()
- d) plt.show()

**Answer**: b) mpld3

5. **How do you add a secondary y-axis to a Matplotlib plot?**

- a) Using `plt.twiny()`

- b) Using `plt.twinx()`

- c) Using `plt.add_yaxis()`

- d) Using `plt.secondary_y()`

**Answer**: b) Using `plt.twinx()`

6. **What does the `plt.barh()` function do?**

- a) Creates a vertical bar plot

- b) Creates a horizontal bar plot

- c) Creates a pie chart

- d) Creates a line plot

**Answer**: b) Creates a horizontal bar plot

7. **How can you adjust the space between subplots in a figure?**

- a) Using `plt.subplots_adjust()`

- b) Using `plt.spacing()`

- c) Using `plt.tight_layout()`

- d) Both a and c

**Answer**: d) Both a and c

8. **Which of the following is NOT a valid colormap in Matplotlib?**

- a) viridis

- b) plasma

- c) coolwarm

- d) rainbowz

**Answer**: d) rainbowz
9. **What is the output of `plt.hist([1, 2, 1, 1, 3, 2], bins=3)`?**

- a) A line plot

- b) A bar plot

- c) A histogram with 3 bins

- d) An error

**Answer**: c) A histogram with 3 bins

10. **What method is used to modify the appearance of grid lines in a plot?**

- a) plt.grid_color()

- b) plt.set_grid()

- c) plt.grid() with parameters

- d) plt.modify_grid()

**Answer**: c) plt.grid() with parameters

11. **How do you set a logarithmic scale on the y-axis?**

- a) plt.yscale('log')

- b) plt.set_yscale('log')

- c) plt.yaxis_scale('log')

- d) plt.log_y()

**Answer**: a) plt.yscale('log')

12. **What is the purpose of `plt.errorbar()` function?**

- a) To plot errors in predictions

- b) To plot error bars for a dataset

- c) To handle exceptions in plotting

- d) To display error messages

**Answer**: b) To plot error bars for a dataset

13. **Which parameter can be adjusted to change the opacity of a plot?**

- a) transparency

- b) alpha
- c) opacity

- d) blend

**Answer**: b) alpha

14. **Which command would you use to create a contour plot?**

- a) plt.plot_contour()

- b) plt.contour()

- c) plt.line_contour()

- d) plt.fill_contour()

**Answer**: b) plt.contour()

15. **What does the `plt.annotate()` function return?**

- a) An annotation object

- b) A string

- c) A boolean value

- d) An integer

**Answer**: a) An annotation object

16. **Which Matplotlib function is used for creating polar plots?**

- a) plt.polar()

- b) plt.polarplot()

- c) plt.subplot(projection='polar')

- d) plt.polar_plot()

**Answer**: c) plt.subplot(projection='polar')

17. **What is the default linestyle of lines in Matplotlib plots?**

- a) Dashed

- b) Dotted

- c) Solid

- d) Dash-dot

**Answer**: c) Solid
18. **What does the `scatter()` function's `c` parameter specify?**

- a) Color of the markers

- b) Size of the markers

- c) Shape of the markers

- d) Type of plot

**Answer**: a) Color of the markers

19. **How can you hide the axes of a plot?**

- a) plt.hide_axes()

- b) plt.axis('off')

- c) plt.remove_axes()

- d) plt.clear_axes()

**Answer**: b) plt.axis('off')

20. **What does the `set_facecolor()` method do in Matplotlib?**

- a) Changes the background color of the plot

- b) Sets the color of the axes

- c) Changes the color of the grid

- d) Modifies the color of the markers

**Answer**: a) Changes the background color of the plot

You might also like