0% found this document useful (0 votes)
63 views

Questions of Matpotlib and Seaborn

Uploaded by

OMKAR AGARWAL
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

Questions of Matpotlib and Seaborn

Uploaded by

OMKAR AGARWAL
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 31

1. Which of the following is used to display a plot in Matplotlib?

 a) plt.display()
 b) plt.show()
 c) plt.plot()
 d) plt.figure()
Answer: b) plt.show()
2. Which function is used to create a scatter plot in Matplotlib?
 a) plt.plot()
 b) plt.scatter()
 c) plt.bar()
 d) plt.line()
Answer: b) plt.scatter()
3. In Seaborn, which function would you use to create a box plot?
 a) sns.boxplot()
 b) sns.barplot()
 c) sns.violinplot()
 d) sns.histplot()
Answer: a) sns.boxplot()
4. How can you add a title to a plot in Matplotlib?
 a) plt.set_title()
 b) plt.add_title()
 c) plt.title()
 d) plt.text()
Answer: c) plt.title()
5. What is the default style of plots in Seaborn?
 a) whitegrid
 b) darkgrid
 c) ticks
 d) classic
Answer: b) darkgrid
6. How do you adjust the size of a figure in Matplotlib?
 a) plt.size()
 b) plt.figure(figsize=(x, y))
 c) plt.adjust_size()
 d) plt.set_size()
Answer: b) plt.figure(figsize=(x, y))
7. Which of the following is used to create a histogram in Matplotlib?
 a) plt.hist()
 b) plt.plot()
 c) plt.bar()
 d) plt.scatter()
Answer: a) plt.hist()
8. How do you change the color palette in Seaborn?
 a) sns.set_palette()
 b) sns.set_color()
 c) sns.palette()
 d) sns.set_color_palette()
Answer: a) sns.set_palette()
9. What function is used to create a line plot in Seaborn?
 a) sns.lineplot()
 b) sns.scatterplot()
 c) sns.barplot()
 d) sns.plot()
Answer: a) sns.lineplot()
10. What does the function sns.pairplot() create in Seaborn?
 a) Pairwise relationships between variables
 b) Distribution of variables
 c) A heatmap
 d) A bar plot
Answer: a) Pairwise relationships between variables

Intermediate Level (Matplotlib and Seaborn)


11. Which Seaborn function creates a heatmap?
 a) sns.heat_map()
 b) sns.heatmap()
 c) sns.heat()
 d) sns.heat_plot()
Answer: b) sns.heatmap()
12. What is the function to create a regression plot in Seaborn?
 a) sns.regplot()
 b) sns.lineplot()
 c) sns.scatterplot()
 d) sns.lmplot()
Answer: a) sns.regplot()
13. Which of the following Matplotlib methods is used to save a plot to a file?
 a) plt.save()
 b) plt.savefig()
 c) plt.export()
 d) plt.write()
Answer: b) plt.savefig()
14. In Seaborn, which plot is used to visualize a distribution?
 a) sns.scatterplot()
 b) sns.lineplot()
 c) sns.distplot()
 d) sns.plot()
Answer: c) sns.distplot()
15. Which of these Matplotlib functions allows you to plot a bar chart?
 a) plt.bar()
 b) plt.plot()
 c) plt.scatter()
 d) plt.pie()
Answer: a) plt.bar()
16. How do you set the figure size globally for Matplotlib?
 a) plt.rcParams['figure.figsize']
 b) plt.set_size()
 c) plt.figure(size=(x, y))
 d) plt.size()
Answer: a) plt.rcParams['figure.figsize']
17. Which of these functions in Seaborn is used to create a categorical plot?
 a) sns.catplot()
 b) sns.regplot()
 c) sns.heatmap()
 d) sns.lineplot()
Answer: a) sns.catplot()
18. Which function can be used in Seaborn to show a distribution with a KDE (Kernel Density Estimate)?
 a) sns.distplot()
 b) sns.kdeplot()
 c) sns.densityplot()
 d) sns.histplot()
Answer: b) sns.kdeplot()
19. In Matplotlib, which function is used to plot multiple subplots in one figure?
 a) plt.subplots()
 b) plt.subplot()
 c) plt.multi()
 d) plt.grid()
Answer: a) plt.subplots()
20. In Seaborn, which of the following would be used to add hue to a plot?
 a) sns.hue()
 b) sns.add_hue()
 c) hue='category'
 d) sns.set_hue()
Answer: c) hue='category'

Advanced Level (Matplotlib and Seaborn)


21. What is the default color palette in Seaborn for plots?
 a) muted
 b) dark
 c) deep
 d) colorblind
Answer: c) deep
22. How do you create a subplot grid in Seaborn?
 a) sns.subplots()
 b) sns.gridplot()
 c) sns.FacetGrid()
 d) sns.subplotgrid()
Answer: c) sns.FacetGrid()
23. Which function is used to plot a Violin plot in Seaborn?
 a) sns.violinplot()
 b) sns.boxplot()
 c) sns.stripplot()
 d) sns.scatterplot()
Answer: a) sns.violinplot()
24. How can you rotate labels on the x-axis in Matplotlib?
 a) plt.set_xticks(rotation=45)
 b) plt.xticks(rotation=45)
 c) plt.rotate_xticks()
 d) plt.set_xlabels(rotation=45)
Answer: b) plt.xticks(rotation=45)
25. How can you change the style of Matplotlib plots globally?
 a) plt.style.use()
 b) sns.set_style()
 c) plt.set_style()
 d) plt.use_style()
Answer: a) plt.style.use()
26. What is the purpose of the sns.lmplot() function in Seaborn?
 a) Plot scatter with regression line
 b) Plot a heatmap with linear models
 c) Plot categorical data
 d) Plot only linear data
Answer: a) Plot scatter with regression line
27. In Matplotlib, what does the ax object refer to in a subplot?
 a) Axes object where the plot is drawn
 b) Axis title
 c) Plot label
 d) Figure object
Answer: a) Axes object where the plot is drawn
28. How do you customize the legend in Matplotlib?
 a) plt.legend()
 b) plt.set_legend()
 c) plt.add_legend()
 d) plt.custom_legend()
Answer: a) plt.legend()
29. How do you create a pairwise relationship plot in Seaborn for a DataFrame?
 a) sns.pairplot(df)
 b) sns.pairwise(df)
 c) sns.plotpair(df)
 d) sns.relationplot(df)
Answer: a) sns.pairplot(df)
30. Which Matplotlib function allows you to adjust the tight layout of a figure?
 a) plt.tight_layout()
 b) plt.adjust_layout()
 c) plt.set_layout()
 d) plt.layout()
Answer: a) plt.tight_layout()
31. What does the sns.FacetGrid() function in Seaborn allow you to do?
 a) Create multi-plot grids based on categorical data
 b) Apply grid lines to a plot
 c) Create a 3D scatter plot
 d) Create multiple regression plots
Answer: a) Create multi-plot grids based on categorical data
32. In Matplotlib, how can you remove the grid from the plot?
 a) plt.grid(False)
 b) plt.remove_grid()
 c) plt.set_grid(False)
 d) plt.no_grid()
Answer: a) plt.grid(False)
33. How can you control the size of ticks in Matplotlib?
 a) plt.tick_params()
 b) plt.set_ticks()
 c) plt.adjust_ticks()
 d) plt.tick_size()
Answer: a) plt.tick_params()
34. What is the purpose of sns.stripplot() in Seaborn?
 a) To visualize distribution of data with dots
 b) To create a violin plot
 c) To create a bar chart
 d) To create a regression line
Answer: a) To visualize distribution of data with dots
35. How do you handle missing data in Seaborn plotting?
 a) Use dropna()
 b) Use fillna()
 c) Both a) and b)
 d) None of the above
Answer: c) Both a) and b)

1. Which of the following is used to display a plot in Matplotlib?


 a) plt.display()
 b) plt.show()
 c) plt.plot()
 d) plt.figure()
Answer: b) plt.show()
2. Which function is used to create a scatter plot in Matplotlib?
 a) plt.plot()
 b) plt.scatter()
 c) plt.bar()
 d) plt.line()
Answer: b) plt.scatter()
3. In Seaborn, which function would you use to create a box plot?
 a) sns.boxplot()
 b) sns.barplot()
 c) sns.violinplot()
 d) sns.histplot()
Answer: a) sns.boxplot()
4. How can you add a title to a plot in Matplotlib?
 a) plt.set_title()
 b) plt.add_title()
 c) plt.title()
 d) plt.text()
Answer: c) plt.title()
5. What is the default style of plots in Seaborn?
 a) whitegrid
 b) darkgrid
 c) ticks
 d) classic
Answer: b) darkgrid
6. How do you adjust the size of a figure in Matplotlib?
 a) plt.size()
 b) plt.figure(figsize=(x, y))
 c) plt.adjust_size()
 d) plt.set_size()
Answer: b) plt.figure(figsize=(x, y))
7. Which of the following is used to create a histogram in Matplotlib?
 a) plt.hist()
 b) plt.plot()
 c) plt.bar()
 d) plt.scatter()
Answer: a) plt.hist()
8. How do you change the color palette in Seaborn?
 a) sns.set_palette()
 b) sns.set_color()
 c) sns.palette()
 d) sns.set_color_palette()
Answer: a) sns.set_palette()
9. What function is used to create a line plot in Seaborn?
 a) sns.lineplot()
 b) sns.scatterplot()
 c) sns.barplot()
 d) sns.plot()
Answer: a) sns.lineplot()
10. What does the function sns.pairplot() create in Seaborn?
 a) Pairwise relationships between variables
 b) Distribution of variables
 c) A heatmap
 d) A bar plot
Answer: a) Pairwise relationships between variables

Intermediate Level (Matplotlib and Seaborn)


11. Which Seaborn function creates a heatmap?
 a) sns.heat_map()
 b) sns.heatmap()
 c) sns.heat()
 d) sns.heat_plot()
Answer: b) sns.heatmap()
12. What is the function to create a regression plot in Seaborn?
 a) sns.regplot()
 b) sns.lineplot()
 c) sns.scatterplot()
 d) sns.lmplot()
Answer: a) sns.regplot()
13. Which of the following Matplotlib methods is used to save a plot to a file?
 a) plt.save()
 b) plt.savefig()
 c) plt.export()
 d) plt.write()
Answer: b) plt.savefig()
14. In Seaborn, which plot is used to visualize a distribution?
 a) sns.scatterplot()
 b) sns.lineplot()
 c) sns.distplot()
 d) sns.plot()
Answer: c) sns.distplot()
15. Which of these Matplotlib functions allows you to plot a bar chart?
 a) plt.bar()
 b) plt.plot()
 c) plt.scatter()
 d) plt.pie()
Answer: a) plt.bar()
16. How do you set the figure size globally for Matplotlib?
 a) plt.rcParams['figure.figsize']
 b) plt.set_size()
 c) plt.figure(size=(x, y))
 d) plt.size()
Answer: a) plt.rcParams['figure.figsize']
17. Which of these functions in Seaborn is used to create a categorical plot?
 a) sns.catplot()
 b) sns.regplot()
 c) sns.heatmap()
 d) sns.lineplot()
Answer: a) sns.catplot()
18. Which function can be used in Seaborn to show a distribution with a KDE (Kernel Density Estimate)?
 a) sns.distplot()
 b) sns.kdeplot()
 c) sns.densityplot()
 d) sns.histplot()
Answer: b) sns.kdeplot()
19. In Matplotlib, which function is used to plot multiple subplots in one figure?
 a) plt.subplots()
 b) plt.subplot()
 c) plt.multi()
 d) plt.grid()
Answer: a) plt.subplots()
20. In Seaborn, which of the following would be used to add hue to a plot?
 a) sns.hue()
 b) sns.add_hue()
 c) hue='category'
 d) sns.set_hue()
Answer: c) hue='category'

Advanced Level (Matplotlib and Seaborn)


21. What is the default color palette in Seaborn for plots?
 a) muted
 b) dark
 c) deep
 d) colorblind
Answer: c) deep
22. How do you create a subplot grid in Seaborn?
 a) sns.subplots()
 b) sns.gridplot()
 c) sns.FacetGrid()
 d) sns.subplotgrid()
Answer: c) sns.FacetGrid()
23. Which function is used to plot a Violin plot in Seaborn?
 a) sns.violinplot()
 b) sns.boxplot()
 c) sns.stripplot()
 d) sns.scatterplot()
Answer: a) sns.violinplot()
24. How can you rotate labels on the x-axis in Matplotlib?
 a) plt.set_xticks(rotation=45)
 b) plt.xticks(rotation=45)
 c) plt.rotate_xticks()
 d) plt.set_xlabels(rotation=45)
Answer: b) plt.xticks(rotation=45)
25. How can you change the style of Matplotlib plots globally?
 a) plt.style.use()
 b) sns.set_style()
 c) plt.set_style()
 d) plt.use_style()
Answer: a) plt.style.use()
26. What is the purpose of the sns.lmplot() function in Seaborn?
 a) Plot scatter with regression line
 b) Plot a heatmap with linear models
 c) Plot categorical data
 d) Plot only linear data
Answer: a) Plot scatter with regression line
27. In Matplotlib, what does the ax object refer to in a subplot?
 a) Axes object where the plot is drawn
 b) Axis title
 c) Plot label
 d) Figure object
Answer: a) Axes object where the plot is drawn
28. How do you customize the legend in Matplotlib?
 a) plt.legend()
 b) plt.set_legend()
 c) plt.add_legend()
 d) plt.custom_legend()
Answer: a) plt.legend()
29. How do you create a pairwise relationship plot in Seaborn for a DataFrame?
 a) sns.pairplot(df)
 b) sns.pairwise(df)
 c) sns.plotpair(df)
 d) sns.relationplot(df)
Answer: a) sns.pairplot(df)
30. Which Matplotlib function allows you to adjust the tight layout of a figure?
 a) plt.tight_layout()
 b) plt.adjust_layout()
 c) plt.set_layout()
 d) plt.layout()
Answer: a) plt.tight_layout()
31. What does the sns.FacetGrid() function in Seaborn allow you to do?
 a) Create multi-plot grids based on categorical data
 b) Apply grid lines to a plot
 c) Create a 3D scatter plot
 d) Create multiple regression plots
Answer: a) Create multi-plot grids based on categorical data
32. In Matplotlib, how can you remove the grid from the plot?
 a) plt.grid(False)
 b) plt.remove_grid()
 c) plt.set_grid(False)
 d) plt.no_grid()
Answer: a) plt.grid(False)
33. How can you control the size of ticks in Matplotlib?
 a) plt.tick_params()
 b) plt.set_ticks()
 c) plt.adjust_ticks()
 d) plt.tick_size()
Answer: a) plt.tick_params()
34. What is the purpose of sns.stripplot() in Seaborn?
 a) To visualize distribution of data with dots
 b) To create a violin plot
 c) To create a bar chart
 d) To create a regression line
Answer: a) To visualize distribution of data with dots
35. How do you handle missing data in Seaborn plotting?
 a) Use dropna()
 b) Use fillna()
 c) Both a) and b)
 d) None of the above
Answer: c) Both a) and b)

Conclusion
This collection of 25 MCQs each for Matplotlib and Seaborn covers a broad range of topics that would be useful in
hackathon challenges, ranging from beginner to advanced levels. These questions test practical knowledge and
understanding of data visualization techniques often used during data analysis competitions.
4o mini
You said:
givw me more mcqs
ChatGPT said:
ChatGPT
Certainly! Here are more MCQs on Matplotlib and Seaborn, continuing from the previous ones, to further test your
knowledge.

Matplotlib and Seaborn MCQs (More Advanced)


1. How do you plot multiple lines on a single plot in Matplotlib?
 a) plt.plot(line1, line2)
 b) plt.plot([line1, line2])
 c) plt.plot(line1)
 d) plt.plot(line1); plt.plot(line2)
Answer: d) plt.plot(line1); plt.plot(line2)
2. Which function is used in Matplotlib to create a pie chart?
 a) plt.piechart()
 b) plt.pie()
 c) plt.pietable()
 d) plt.pie_chart()
Answer: b) plt.pie()
3. In Seaborn, what is the purpose of the hue parameter?
 a) To set the style of the plot
 b) To separate the data by color
 c) To set the plot title
 d) To choose the color palette
Answer: b) To separate the data by color
4. Which method in Seaborn allows you to add a regression line to a scatter plot?
 a) sns.add_regression()
 b) sns.regplot()
 c) sns.regscatter()
 d) sns.add_line()
Answer: b) sns.regplot()
5. What is the default figure size when you create a plot using Matplotlib without specifying it?
 a) (5, 5)
 b) (8, 6)
 c) (6, 4)
 d) (10, 8)
Answer: c) (6, 4)
6. How do you specify the color of a plot in Matplotlib?
 a) plt.set_color('red')
 b) plt.plot(color='red')
 c) plt.color('red')
 d) plt.setColor('red')
Answer: b) plt.plot(color='red')
7. What does sns.set_style() do in Seaborn?
 a) It changes the color palette.
 b) It sets the style of the grid.
 c) It removes the grid lines.
 d) It sets the axis labels.
Answer: b) It sets the style of the grid.
8. Which function is used to create a scatter plot in Seaborn?
 a) sns.scatter()
 b) sns.scatterplot()
 c) sns.plot()
 d) sns.regplot()
Answer: b) sns.scatterplot()
9. How can you add annotations to a plot in Matplotlib?
 a) plt.text()
 b) plt.annotate()
 c) plt.add_annotations()
 d) Both a) and b)
Answer: d) Both a) and b)
10. In Seaborn, which function creates a violin plot?
 a) sns.violinplot()
 b) sns.boxplot()
 c) sns.histplot()
 d) sns.stripplot()
Answer: a) sns.violinplot()

More Intermediate to Advanced Level


11. Which Matplotlib function is used to create a logarithmic scale on the y-axis?
 a) plt.logscale()
 b) plt.set_ylog()
 c) plt.yscale('log')
 d) plt.set_yscale('log')
Answer: c) plt.yscale('log')
12. How do you modify the line style in a Matplotlib plot?
 a) plt.set_lineStyle()
 b) plt.line(style='dashed')
 c) plt.plot(style='--')
 d) plt.set_style('dashed')
Answer: c) plt.plot(style='--')
13. What is the purpose of sns.lmplot() in Seaborn?
 a) To draw a line plot
 b) To plot categorical data
 c) To plot linear relationships with a scatter plot and regression line
 d) To show the distribution of data
Answer: c) To plot linear relationships with a scatter plot and regression line
14. How do you set a title for subplots in Matplotlib?
 a) plt.suptitle()
 b) plt.title()
 c) plt.set_title()
 d) plt.title_subplot()
Answer: a) plt.suptitle()
15. In Matplotlib, what is the function used to remove the ticks on both axes?
 a) plt.remove_ticks()
 b) plt.xticks([]); plt.yticks([])
 c) plt.set_ticks([])
 d) plt.hide_ticks()
Answer: b) plt.xticks([]); plt.yticks([])
16. How do you change the grid style in Seaborn?
 a) sns.set_style('grid')
 b) sns.grid(True)
 c) sns.set_grid(True)
 d) sns.set_context('grid')
Answer: a) sns.set_style('grid')
17. Which function is used to display the distribution of a dataset in Seaborn?
 a) sns.distplot()
 b) sns.densityplot()
 c) sns.barplot()
 d) sns.histplot()
Answer: a) sns.distplot()
18. How can you change the legend location in Matplotlib?
 a) plt.legend(location='upper left')
 b) plt.legend('upper left')
 c) plt.set_legend('upper left')
 d) plt.set_location('upper left')
Answer: a) plt.legend(location='upper left')
19. In Seaborn, how do you create a FacetGrid plot for a dataset?
 a) sns.FacetGrid(df)
 b) sns.gridplot(df)
 c) sns.plotfacet(df)
 d) sns.subfacetgrid(df)
Answer: a) sns.FacetGrid(df)
20. What does plt.subplots_adjust() do in Matplotlib?
 a) Adjusts the size of the plot
 b) Adjusts the spacing between subplots
 c) Adjusts the x and y-axis labels
 d) Adjusts the colors of the plot
Answer: b) Adjusts the spacing between subplots

Even More Advanced Topics


21. How do you combine multiple figures (subplots) into one in Matplotlib?
 a) plt.merge()
 b) plt.subplot()
 c) plt.combine()
 d) plt.subplot_grid()
Answer: b) plt.subplot()
22. How do you add multiple legends to a plot in Matplotlib?
 a) plt.add_legend()
 b) plt.legend()
 c) plt.legend(handles=[handle1, handle2])
 d) plt.set_legend()
Answer: c) plt.legend(handles=[handle1, handle2])
23. Which Seaborn plot is used to visualize a joint distribution of two variables?
 a) sns.jointplot()
 b) sns.scatterplot()
 c) sns.pairplot()
 d) sns.displot()
Answer: a) sns.jointplot()
24. What is the default Matplotlib plot style?
 a) ggplot
 b) seaborn
 c) default
 d) bmh
Answer: c) default
25. In Seaborn, how do you show multiple categorical variables in one plot?
 a) sns.catplot()
 b) sns.boxplot()
 c) sns.violinplot()
 d) sns.scatterplot()
Answer: a) sns.catplot()
26. How can you remove grid lines from Seaborn?
 a) sns.set_style('white')
 b) sns.set_style('ticks')
 c) sns.set_style('dark')
 d) sns.set_style('none')
Answer: d) sns.set_style('none')
27. How do you plot a 3D scatter plot in Matplotlib?
 a) plt.scatter3D()
 b) plt.scatter(x, y, z)
 c) ax.scatter(x, y, z)
 d) plt.plot3D()
Answer: c) ax.scatter(x, y, z)
28. In Matplotlib, how do you control the transparency of a plot?
 a) plt.set_alpha()
 b) plt.alpha()
 c) plt.plot(alpha=0.5)
 d) plt.set_opacity()
Answer: c) plt.plot(alpha=0.5)
29. What is the function in Seaborn to show a correlation matrix as a heatmap?
 a) sns.correlation_plot()
 b) sns.heatmap()
 c) sns.corrplot()
 d) sns.correlation_matrix()
Answer: b) sns.heatmap()
30. How can you add annotations to a heatmap in Seaborn?
 a) sns.heatmap(annot=True)
 b) sns.annotate_heatmap()
 c) sns.add_annotations()
 d) sns.set_annotation()
Answer: a) sns.heatmap(annot=True)

You might also like