CO2: implement the data visualization techniques using matplotlib.
Part - A (Two Marks)
1. How do you create multiple subplots in a single figure using Matplotlib?
2. Given two lists: x = [1, 2, 3, 4, 5] and y = [10, 20, 25, 30, 40], write the
Matplotlib command to create a simple line plot.
3. How can Basemap be used effectively to visualize geographical datasets?
4. Write the commands to set the title of a plot to "Annual Report" and label the X-axis as "Months".
5. Write the Python command used to add a legend to a plot?
6. Create a scatter plot using Matplotlib for the points (1,2),(2,4),(3,1),(4,3).
7. Suppose you are given experimental data with x=[1,2,3,4] and corresponding y=[2.1,3.9,6.2,7.8]
with an error margin of 0.2. Write a Matplotlib command to plot this data with error bars.
8. Given the function z=x2+y2, where x and y range from -5 to 5, how would you create a contour plot
in Matplotlib?
9. A dataset contains the following values: [10, 15, 20, 10, 25, 30, 15, 20, 30, 35]. Write a command to
plot a histogram with 5 bins in Matplotlib.
10. Write a command to plot a red dashed line for the equation y=3x+1 over the range x=0 to 10.
11. Write a command to set the title of a plot to "Sales Growth" and label the x-axis as "Years" and the
y-axis as "Revenue (in millions)".
12. Using Basemap, plot a map of India and mark the location of New Delhi at coordinates (28.61,
77.23).
13. Write a Seaborn command to create a scatter plot showing the relationship between these variables
with columns "Age" and "Salary,"
14. Why are error bars important in data visualization, and how do they improve data interpretation?
15. List out the significance of 3D plotting in data visualization.
PART-B(4 Marks)
1. Explain the key features of Matplotlib and how it differs from other visualization libraries.
2. A scientist records measurements from an experiment with associated errors:
i) x=[1,2,3,4,5]
ii) y=[10,20,30,40,50]
iii) Errors: [2,1.5,3,2.5,1]
Write a Python program to visualize this data using an error bar plot in Matplotlib.
3. Describe the role of line plots in data visualization and provide with an example.
4. Create a Matplotlib plot for a company’s profit margins over five years:
i) Years: [2018, 2019, 2020, 2021, 2022]
ii) Profit Margins (%): [5, 10, 15, 12, 18]
Customize the plot with a grid, different line styles, and axis labels.
5. How do scatter plots help in identifying relationships between variables? Give an example.
6. Illustrate the importance of error bars in scientific visualization. How it can be implemented in
Matplotlib?
7. Explain how histograms are used for data distribution analysis. How do bin sizes affect histogram
interpretation?
8. Given dataset contains the latitude, longitude, and recorded temperature for different locations.
Write a Python program to plot a scatter plot of temperature against latitude.
9. Create a bar chart using Matplotlib to display sales revenue across four quarters:
i) Quarters: [‘Q1’, ‘Q2’, ‘Q3’, ‘Q4’]
ii) Revenue: [120, 150, 180, 210]
Use different colors for each bar and customize the chart with labels.
10. Write a Python program using Matplotlib to create two subplots:
i) The first subplot shows a line graph of temperature changes over a week.
ii) The second subplot shows a bar chart of daily rainfall levels.
PART-B(12 Marks)
1. Write a Python program for the following
i)Create a 3D surface plot of the function z = sin(x) * cos(y) using Matplotlib.
ii)Customize the plot by adding title, X, Y, Z labels.
iii)Add a legend describing the plot as "Sine-Cosine Surface".
2. Write a Python program to create a scatter plot with:
i) A customized background color
ii) A different marker style
iii) Grid lines with dashed style
iv) Axis labels in bold font
3. Given the following dataset for (x, y, z) coordinates:
i) X values: [1, 2, 3, 4, 5]
ii) Y values: [2, 4, 6, 8, 10]
iii) Z values: [10, 20, 15, 25, 30]
Write a Python program using Matplotlib to create a 3D surface plot.
4. You are analyzing the scores of 200 students in three subjects: Math, Science, and English.
i) Create histograms to visualize the score distribution for each subject.
ii) Use different colors for each subject's histogram.
iii) Additionally, plot density plots to understand the concentration of scores.
iv) Add legends to differentiate between the subjects.
v) Customize titles, labels, and plot style for better clarity.
vi) Finally, visualize errors in average subject scores using error bars.
vii) Write Python code using Matplotlib to create the visualizations and explain how
these plots provide insights into students’ performance patterns.
5. Explain the importance of legends in plots. How can you customize legends using
Matplotlib? Provide an example with multiple line plots and a customized legend.
6. Analyzing the sales performance of different product categories over a year using Matplotlib
and Seaborn. The dataset below contains monthly sales revenue for four product categories:
Electronics, Clothing, Groceries, and Furniture.
Using Matplotlib and Seaborn, perform the following tasks to analyze the dataset:
(i)Create a grouped bar chart comparing monthly sales for all product categories.
(ii)Construct a histogram to visualize the distribution of total monthly [Link] how the
histogram helps in understanding seasonality in sales.
(iii)Generate a scatter plot with a regression line to explore the correlation between
Electronics and Clothing sales.
7. Explain different types of plots used for visualizing geographic data. Provide examples
where geographic visualization is essential.
8. Demonstrate how subplots can be effectively used for multi-variable analysis and explain the
concept of subplots in Matplotlib and their role in comparing multiple variables.
9. Describe the role of error bars and error visualization techniques in Matplotlib. How do
visualizing errors help in understanding data variability? Provide examples where error
visualization is crucial.
10. Compare histograms and density plots in Matplotlib and [Link] their advantages
and limitations with examples.