Worksheet #24090801 Data Visualization
- What is the main purpose of data visualization?
- a) To make data more difficult to understand
- b) To summarize data in a visual format
- c) To delete unnecessary data
- d) To store data in a text format
- Which of the following is a valid Python library used for data visualization?
- a) NumPy
- b) Pandas
- c) Matplotlib
- d) Scikit-learn
- What function is used to create a line plot in Matplotlib?
- a)
plot()
- b)
bar()
- c)
hist()
- d)
line()
- a)
- In a Matplotlib plot, what does
xlabel()
do?- a) Sets the label for the x-axis
- b) Sets the label for the y-axis
- c) Sets the plot title
- d) Sets the label for the data points
- Which method is used to display a plot in Matplotlib?
- a)
show()
- b)
draw()
- c)
view()
- d)
save()
- a)
- What type of chart is typically used to show the frequency distribution of data?
- a) Line plot
- b) Bar graph
- c) Histogram
- d) Pie chart
- Which argument is used in the
plot()
function to customize the color of the line?- a)
color
- b)
label
- c)
legend
- d)
title
- a)
- What is the purpose of adding a legend to a plot?
- a) To add labels to the axes
- b) To add a title to the plot
- c) To explain the data represented by different elements in the plot
- d) To change the background color
- Which function in Matplotlib saves the plot to a file?
- a)
save()
- b)
savefig()
- c)
export()
- d)
store()
- a)
- In Matplotlib, which argument is used to set the width of the bars in a bar graph?
- a)
linewidth
- b)
barwidth
- c)
width
- d)
barheight
- a)
Programming Questions
- Write a Python program to create a simple line plot for the following data:
x = [1, 2, 3, 4, 5]
andy = [10, 20, 30, 40, 50]
. Customize the plot by adding a title, x-axis label, and y-axis label. - Write a program to create a bar graph showing the scores of students in three subjects (Math, Science, English). Use the following data:
- Names: [‘John’, ‘Alice’, ‘Bob’]
- Math: [85, 78, 92]
- Science: [90, 88, 80]
- English: [75, 85, 95]
- Create a histogram for the following data showing the distribution of ages:
[21, 22, 23, 22, 21, 24, 25, 22, 23, 23, 22]
. - Write a program to plot two lines on the same graph using the following data:
- Line 1:
x = [1, 2, 3, 4, 5]
,y = [2, 4, 6, 8, 10]
- Line 2:
x = [1, 2, 3, 4, 5]
,y = [1, 3, 5, 7, 9]
Add a legend to differentiate between the two lines.
- Line 1:
- Write a Python program that saves a plot (any plot of your choice) as a PNG image.
- Using Matplotlib, create a pie chart showing the percentage distribution of the following data:
Apples = 40
,Bananas = 30
,Cherries = 20
,Dates = 10
. - Write a Python program to create a bar graph showing the monthly sales of a store over 6 months:
Jan = 1500
,Feb = 1800
,Mar = 1700
,Apr = 1600
,May = 1900
,Jun = 2000
. - Create a Python program that generates a scatter plot using the following data points:
x = [1, 2, 3, 4, 5]
,y = [2, 3, 5, 7, 11]
.
- Write a Python program to plot a sine wave using Matplotlib. Use the
numpy
library to generate values for the sine function. - Create a histogram using the following data and set the number of bins to 5:
Data = [5, 10, 10, 15, 20, 20, 20, 25, 30, 35, 35, 40]
.