PYTHON DATA VISUALIZATION – 19 UNIQUE VVIP PROGRAMMING QUESTIONS
CLASS 10 SEE COMPUTER SCIENCE | CDC NEW CURRICULUM 2083
Most Important • Most Probable • Exam-Oriented Practice
A. BASIC MATPLOTLIB – 4 QUESTIONS
Q1. Basic Bar Chart – Students' Marks
Write a Python program using Matplotlib to draw a bar chart showing the marks obtained by five students: Ram (75), Sita (85), Hari (65), Gita (90) and Nita (80). Set the chart title as "Students' Marks", label the X-axis as "Students" and Y-axis as "Marks Obtained", and display the bars in blue.
Q2. Basic Pie Chart – Household Expenses
Write a Python program using Matplotlib to draw a pie chart showing a family's monthly expenditure: Food (Rs. 8,000), Rent (Rs. 12,000), Transport (Rs. 3,000), Education (Rs. 5,000) and Others (Rs. 2,000). Set the title as "Monthly Household Expenses", use red, blue, green, orange and purple respectively, display category names and percentages with one decimal place, and add a legend.
Q3. Basic Line Chart – Weekly Temperature
Write a Python program using Matplotlib to draw a line chart showing the temperatures recorded from Monday to Sunday: 22°C, 24°C, 26°C, 25°C, 28°C, 30°C and 27°C respectively. Set the title as "Weekly Temperature Variation", X-axis as "Days", Y-axis as "Temperature (°C)", line color as green, circle marker (o), and dashed line style (--).
Q4. Basic Scatter Plot – Height and Weight
Write a Python program using Matplotlib to draw a scatter plot showing the heights of five students as 150, 155, 160, 165 and 170 cm and their corresponding weights as 45, 50, 55, 60 and 65 kg. Set the title as "Height vs Weight", X-axis as "Height (cm)", Y-axis as "Weight (kg)", marker color as red, square marker (s), and marker size as 100.
B. BASIC SEABORN – 3 QUESTIONS
Q5. Basic Bar Chart – Product Sales
Write a Python program using Seaborn to draw a bar chart showing the units sold of five products: Pen (50), Pencil (70), Notebook (40), Eraser (30) and Ruler (60). Set the title as "Stationery Sales Comparison", X-axis as "Products", Y-axis as "Units Sold", display the bars in purple, and rotate the X-axis labels by 30 degrees.
Q6. Basic Line Chart – Monthly Rainfall
Write a Python program using Seaborn to draw a line chart showing rainfall recorded from June to October: 120, 180, 250, 200 and 100 mm respectively. Set the title as "Monthly Rainfall Trend", X-axis as "Months", Y-axis as "Rainfall (mm)", line color as blue, diamond markers (D), and dotted line style (:).
Q7. Basic Scatter Plot – Exercise and Calories
Write a Python program using Seaborn to draw a scatter plot showing daily exercise durations of 10, 20, 30, 40, 50 and 60 minutes and corresponding calories burned of 50, 100, 150, 210, 260 and 320 respectively. Set the title as "Exercise Duration vs Calories Burned", X-axis as "Exercise Duration (Minutes)", Y-axis as "Calories Burned", marker color as orange, triangle marker (^), and marker size as 120.
C. BASIC PLOTLY EXPRESS – 4 QUESTIONS
Q8. Interactive Bar Chart – School Library Books
Write a Python program using Plotly Express to draw an interactive bar chart showing the number of books available in five library categories: Fiction (120), Science (90), History (60), Technology (110) and Biography (50). Set the title as "School Library Book Collection", X-axis as "Book Categories", Y-axis as "Number of Books", display the bars in teal, and show the values on the bars.
Q9. Interactive Pie Chart – Internet Usage
Write a Python program using Plotly Express to draw an interactive pie chart showing students' daily internet usage by activity: Online Classes (35%), Social Media (30%), Gaming (15%), Research (10%) and Entertainment (10%). Set the title as "Students' Internet Usage", use blue, red, green, orange and purple respectively, and display activity names and percentages.
Q10. Interactive Line Chart – Company Profit
Write a Python program using Plotly Express to draw an interactive line chart showing quarterly profits of a company: Q1 (Rs. 25,000), Q2 (Rs. 35,000), Q3 (Rs. 30,000) and Q4 (Rs. 45,000). Set the title as "Quarterly Company Profit", X-axis as "Quarters", Y-axis as "Profit (Rs.)", line color as dark red, solid line style, and circle markers at each data point.
Q11. Interactive Scatter Plot – Advertising and Revenue
Write a Python program using Plotly Express to draw an interactive scatter plot showing advertising expenditure of Rs. 1,000, 2,000, 3,000, 4,000 and 5,000 and corresponding sales revenue of Rs. 8,000, 12,000, 15,000, 21,000 and 26,000. Set the title as "Advertising Expenditure vs Sales Revenue", X-axis as "Advertising Expenditure (Rs.)", Y-axis as "Sales Revenue (Rs.)", and use green circle markers of size 14.
D. DATA VISUALIZATION WITH PANDAS – 4 QUESTIONS
Q12. Pandas + Matplotlib Bar Chart – Subject-wise Marks
Write a Python program to create a Pandas DataFrame containing five subjects—English, Nepali, Mathematics, Science and Computer—and their respective marks of 78, 82, 95, 88 and 92. Draw a bar chart using Matplotlib. Set the title as "Subject-wise Academic Performance", X-axis as "Subjects", Y-axis as "Marks Obtained", display the bars in orange, and rotate the subject names by 30 degrees.
Q13. Pandas + Matplotlib Pie Chart – Sports Participation
Write a Python program to create a Pandas DataFrame containing the number of students participating in four sports: Football (40), Cricket (30), Volleyball (20) and Basketball (10). Draw a pie chart using Matplotlib. Set the title as "Students' Sports Participation", use red, blue, green and yellow respectively, highlight the Football sector using an explode value of 0.1, and display percentages with one decimal place.
Q14. Pandas + Seaborn Line Chart – Electricity Consumption
Write a Python program to create a Pandas DataFrame containing electricity consumption for six months—January, February, March, April, May and June—with values 120, 135, 150, 140, 165 and 180 units respectively. Draw a line chart using Seaborn. Set the title as "Monthly Electricity Consumption", X-axis as "Months", Y-axis as "Electricity Units (kWh)", line color as brown, square markers (s), and dash-dot line style (-.).
Q15. Pandas + Plotly Scatter Plot – Attendance and Results
Write a Python program to create a Pandas DataFrame containing attendance percentages of six students as 60, 65, 70, 80, 90 and 95 and their corresponding examination marks as 45, 52, 60, 72, 85 and 92. Draw an interactive scatter plot using Plotly Express. Set the title as "Attendance Percentage vs Examination Marks", X-axis as "Attendance (%)", Y-axis as "Examination Marks", and display blue diamond markers of size 12.
E. CSV + PANDAS – 4 QUESTIONS
Q16. CSV + Pandas + Matplotlib Bar Chart – District Population
A CSV file named population.csv contains two columns, District and Population. It contains five illustrative records: Kathmandu (2,000,000), Lalitpur (600,000), Bhaktapur (450,000), Kaski (650,000) and Chitwan (700,000). Write a Python program to read the CSV file using Pandas and draw a bar chart using Matplotlib. Set the title as "Population Comparison of Five Districts", X-axis as "Districts", Y-axis as "Population", display the bars in green, and rotate the district names by 30 degrees.
Q17. CSV + Pandas + Plotly Pie Chart – Tourism
A CSV file named tourists.csv contains two columns, Country and Visitors. The records are India (500), China (300), USA (200), Japan (150) and Australia (100). Write a Python program to read the CSV file using Pandas and draw an interactive pie chart using Plotly Express. Set the title as "Tourist Arrivals by Country", use red, blue, green, orange and purple respectively, and display country names and percentage shares.
Q18. CSV + Pandas + Seaborn Line Chart – Website Visitors
A CSV file named visitors.csv contains two columns, Day and Visitors. The records for Monday through Sunday are 150, 180, 220, 200, 260, 310 and 280 visitors respectively. Write a Python program to read the CSV file using Pandas and draw a line chart using Seaborn. Set the title as "Daily Website Visitor Trend", X-axis as "Days", Y-axis as "Number of Visitors", line color as purple, circle markers (o), solid line style (-), and display grid lines.
Q19. CSV + Pandas + Seaborn Scatter Plot – Sleep and Productivity
A CSV file named sleep.csv contains two columns, Sleep_Hours and Productivity_Score. The sleep durations are 4, 5, 6, 7, 8 and 9 hours and their corresponding productivity scores are 40, 50, 65, 80, 90 and 85. Write a Python program to read the CSV file using Pandas and draw a scatter plot using Seaborn. Set the title as "Sleep Duration vs Productivity", X-axis as "Sleep Duration (Hours)", Y-axis as "Productivity Score", marker color as dark blue, diamond marker (D), and marker size as 110.
PYTHON DATA VISUALIZATION – 19 VVIP PROGRAMMING ANSWERS
CLASS 10 SEE COMPUTER SCIENCE | CDC NEW CURRICULUM 2083
=============================================
A. BASIC MATPLOTLIB – 4 PROGRAMS
=============================================
Q1. Basic Bar Chart – Students' Marks
import matplotlib.pyplot as plt
students = ['Ram', 'Sita', 'Hari', 'Gita', 'Nita']
marks = [75, 85, 65, 90, 80]
plt.bar(students, marks, color='blue')
plt.title("Students' Marks")
plt.xlabel("Students")
plt.ylabel("Marks Obtained")
plt.show()
Q2. Basic Pie Chart – Household Expenses
import matplotlib.pyplot as plt
categories = ['Food', 'Rent', 'Transport',
'Education', 'Others']
expenses = [8000, 12000, 3000, 5000, 2000]
colors = ['red', 'blue', 'green', 'orange', 'purple']
plt.pie(
expenses,
labels=categories,
colors=colors,
autopct='%1.1f%%'
)
plt.title("Monthly Household Expenses")
plt.legend(
title="Expenses",
loc='upper left',
bbox_to_anchor=(1, 1)
)
plt.tight_layout()
plt.show()
Q3. Basic Line Chart – Weekly Temperature
import matplotlib.pyplot as plt
days = ['Mon', 'Tue', 'Wed', 'Thu',
'Fri', 'Sat', 'Sun']
temperature = [22, 24, 26, 25, 28, 30, 27]
plt.plot(
days,
temperature,
color='green',
marker='o',
linestyle='--'
)
plt.title("Weekly Temperature Variation")
plt.xlabel("Days")
plt.ylabel("Temperature (°C)")
plt.show()
Q4. Basic Scatter Plot – Height and Weight
import matplotlib.pyplot as plt
height = [150, 155, 160, 165, 170]
weight = [45, 50, 55, 60, 65]
plt.scatter(
height,
weight,
color='red',
marker='s',
s=100
)
plt.title("Height vs Weight")
plt.xlabel("Height (cm)")
plt.ylabel("Weight (kg)")
plt.show()
=============================================
B. BASIC SEABORN – 3 PROGRAMS
=============================================
Q5. Basic Bar Chart – Product Sales
import seaborn as sns
import matplotlib.pyplot as plt
products = ['Pen', 'Pencil', 'Notebook',
'Eraser', 'Ruler']
sales = [50, 70, 40, 30, 60]
sns.barplot(
x=products,
y=sales,
color='purple'
)
plt.title("Stationery Sales Comparison")
plt.xlabel("Products")
plt.ylabel("Units Sold")
plt.xticks(rotation=30)
plt.show()
Q6. Basic Line Chart – Monthly Rainfall
import seaborn as sns
import matplotlib.pyplot as plt
months = ['June', 'July', 'August',
'September', 'October']
rainfall = [120, 180, 250, 200, 100]
sns.lineplot(
x=months,
y=rainfall,
color='blue',
marker='D',
linestyle=':'
)
plt.title("Monthly Rainfall Trend")
plt.xlabel("Months")
plt.ylabel("Rainfall (mm)")
plt.show()
Q7. Basic Scatter Plot – Exercise and Calories
import seaborn as sns
import matplotlib.pyplot as plt
duration = [10, 20, 30, 40, 50, 60]
calories = [50, 100, 150, 210, 260, 320]
sns.scatterplot(
x=duration,
y=calories,
color='orange',
marker='^',
s=120
)
plt.title("Exercise Duration vs Calories Burned")
plt.xlabel("Exercise Duration (Minutes)")
plt.ylabel("Calories Burned")
plt.show()
=============================================
C. BASIC PLOTLY EXPRESS – 4 PROGRAMS
=============================================
Q8. Interactive Bar Chart – School Library Books
import plotly.express as px
categories = ['Fiction', 'Science', 'History',
'Technology', 'Biography']
books = [120, 90, 60, 110, 50]
fig = px.bar(
x=categories,
y=books,
title="School Library Book Collection",
labels={
'x': 'Book Categories',
'y': 'Number of Books'
},
color_discrete_sequence=['teal'],
text=books
)
fig.show()
Q9. Interactive Pie Chart – Internet Usage
import plotly.express as px
activities = ['Online Classes', 'Social Media',
'Gaming', 'Research', 'Entertainment']
usage = [35, 30, 15, 10, 10]
fig = px.pie(
names=activities,
values=usage,
title="Students' Internet Usage",
color=activities,
color_discrete_sequence=[
'blue', 'red', 'green', 'orange', 'purple'
]
)
fig.update_traces(textinfo='label+percent')
fig.show()
Q10. Interactive Line Chart – Company Profit
import plotly.express as px
quarters = ['Q1', 'Q2', 'Q3', 'Q4']
profit = [25000, 35000, 30000, 45000]
fig = px.line(
x=quarters,
y=profit,
title="Quarterly Company Profit",
labels={
'x': 'Quarters',
'y': 'Profit (Rs.)'
},
markers=True,
color_discrete_sequence=['darkred']
)
fig.update_traces(
line=dict(dash='solid'),
marker=dict(symbol='circle')
)
fig.show()
Q11. Interactive Scatter Plot – Advertising and Revenue
import plotly.express as px
advertising = [1000, 2000, 3000, 4000, 5000]
revenue = [8000, 12000, 15000, 21000, 26000]
fig = px.scatter(
x=advertising,
y=revenue,
title="Advertising Expenditure vs Sales Revenue",
labels={
'x': 'Advertising Expenditure (Rs.)',
'y': 'Sales Revenue (Rs.)'
},
color_discrete_sequence=['green']
)
fig.update_traces(
marker=dict(size=14, symbol='circle')
)
fig.show()
=============================================
D. DATA VISUALIZATION WITH PANDAS – 4 PROGRAMS
=============================================
Q12. Pandas + Matplotlib Bar Chart – Subject-wise Marks
import pandas as pd
import matplotlib.pyplot as plt
data = {
'Subject': ['English', 'Nepali', 'Mathematics',
'Science', 'Computer'],
'Marks': [78, 82, 95, 88, 92]
}
df = pd.DataFrame(data)
plt.bar(
df['Subject'],
df['Marks'],
color='orange'
)
plt.title("Subject-wise Academic Performance")
plt.xlabel("Subjects")
plt.ylabel("Marks Obtained")
plt.xticks(rotation=30)
plt.tight_layout()
plt.show()
Q13. Pandas + Matplotlib Pie Chart – Sports Participation
import pandas as pd
import matplotlib.pyplot as plt
data = {
'Sport': ['Football', 'Cricket',
'Volleyball', 'Basketball'],
'Students': [40, 30, 20, 10]
}
df = pd.DataFrame(data)
colors = ['red', 'blue', 'green', 'yellow']
explode = [0.1, 0, 0, 0]
plt.pie(
df['Students'],
labels=df['Sport'],
colors=colors,
explode=explode,
autopct='%1.1f%%'
)
plt.title("Students' Sports Participation")
plt.show()
Q14. Pandas + Seaborn Line Chart – Electricity Consumption
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
data = {
'Month': ['January', 'February', 'March',
'April', 'May', 'June'],
'Units': [120, 135, 150, 140, 165, 180]
}
df = pd.DataFrame(data)
sns.lineplot(
data=df,
x='Month',
y='Units',
color='brown',
marker='s',
linestyle='-.',
sort=False
)
plt.title("Monthly Electricity Consumption")
plt.xlabel("Months")
plt.ylabel("Electricity Units (kWh)")
plt.show()
Q15. Pandas + Plotly Scatter Plot – Attendance and Results
import pandas as pd
import plotly.express as px
data = {
'Attendance': [60, 65, 70, 80, 90, 95],
'Marks': [45, 52, 60, 72, 85, 92]
}
df = pd.DataFrame(data)
fig = px.scatter(
df,
x='Attendance',
y='Marks',
title="Attendance Percentage vs Examination Marks",
labels={
'Attendance': 'Attendance (%)',
'Marks': 'Examination Marks'
},
color_discrete_sequence=['blue']
)
fig.update_traces(
marker=dict(size=12, symbol='diamond')
)
fig.show()
=============================================
E. CSV + PANDAS – 4 PROGRAMS
=============================================
Q16. CSV + Pandas + Matplotlib Bar Chart – District Population
Sample population.csv:
District,Population
Kathmandu,2000000
Lalitpur,600000
Bhaktapur,450000
Kaski,650000
Chitwan,700000
Python Program:
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('population.csv')
plt.bar(
df['District'],
df['Population'],
color='green'
)
plt.title("Population Comparison of Five Districts")
plt.xlabel("Districts")
plt.ylabel("Population")
plt.xticks(rotation=30)
plt.tight_layout()
plt.show()
Q17. CSV + Pandas + Plotly Pie Chart – Tourism
Sample tourists.csv:
Country,Visitors
India,500
China,300
USA,200
Japan,150
Australia,100
Python Program:
import pandas as pd
import plotly.express as px
df = pd.read_csv('tourists.csv')
fig = px.pie(
df,
names='Country',
values='Visitors',
title="Tourist Arrivals by Country",
color='Country',
color_discrete_sequence=[
'red', 'blue', 'green', 'orange', 'purple'
]
)
fig.update_traces(
textinfo='label+percent'
)
fig.show()
Q18. CSV + Pandas + Seaborn Line Chart – Website Visitors
Sample visitors.csv:
Day,Visitors
Monday,150
Tuesday,180
Wednesday,220
Thursday,200
Friday,260
Saturday,310
Sunday,280
Python Program:
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
df = pd.read_csv('visitors.csv')
sns.lineplot(
data=df,
x='Day',
y='Visitors',
color='purple',
marker='o',
linestyle='-',
sort=False
)
plt.title("Daily Website Visitor Trend")
plt.xlabel("Days")
plt.ylabel("Number of Visitors")
plt.grid(True)
plt.xticks(rotation=30)
plt.tight_layout()
plt.show()
Q19. CSV + Pandas + Seaborn Scatter Plot – Sleep and Productivity
Sample sleep.csv:
Sleep_Hours,Productivity_Score
4,40
5,50
6,65
7,80
8,90
9,85
Python Program:
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
df = pd.read_csv('sleep.csv')
sns.scatterplot(
data=df,
x='Sleep_Hours',
y='Productivity_Score',
color='darkblue',
marker='D',
s=110
)
plt.title("Sleep Duration vs Productivity")
plt.xlabel("Sleep Duration (Hours)")
plt.ylabel("Productivity Score")
plt.show()
=============================================
END OF 19 VVIP PROGRAMS
=============================================
PREPARED BY: DEEPAK SHRESTHA
No comments:
Post a Comment