Saturday, October 31, 2026

๐Ÿ“Š Python Data Visualization เคจेเคชाเคฒीเคฎा | Matplotlib vs Plotly | SEE Computer Science

 

๐Ÿ“Š Python Data Visualization เคจेเคชाเคฒीเคฎा | Matplotlib vs Plotly | SEE Computer Science

Data Visualization เคญเคจेเค•ो เค•े เคนो? Python เค•ो เคฎเคฆ्เคฆเคคเคฒे เคธाเคฎाเคจ्เคฏ เคกाเคŸाเคฒाเคˆ เค•เคธเคฐी เค†เค•เคฐ्เคทเค• เคฐ เคฌुเค्เคจ เคธเคœिเคฒो เคšाเคฐ्เคŸ เคคเคฅा เค—्เคฐाเคซเคฎा เคช्เคฐเคธ्เคคुเคค เค—เคฐ्เคจ เคธเค•िเคจ्เค›?



เคฏเคธ เคญिเคกिเคฏोเคฎा เคนाเคฎी Python Data Visualization เค•ा เค†เคงाเคฐเคญूเคค เค…เคตเคงाเคฐเคฃाเคนเคฐू เคธเคฐเคฒ เคจेเคชाเคฒी เคญाเคทाเคฎा เคฌुเค्เคจेเค›ौँ।

๐ŸŽฏ What You'll Learn:
✅ Introduction to Data Visualization
✅ Importance of Data Visualization in Data Analysis
✅ Matplotlib Library and its Features
✅ Plotly Library and Interactive Graphs
✅ Bar Chart, Line Chart and Scatter Plot Concepts
✅ Difference Between Static and Interactive Charts
✅ How Visualization Helps Identify Patterns, Trends and Relationships

๐ŸŽ“ Who Should Watch?

• Class 10 SEE Computer Science Students
• Python Beginners
• Students Learning Data Analysis
• Computer Science Teachers
• Anyone Interested in Data Visualization

๐Ÿ“š Subject: Computer Science
๐Ÿ“Œ Topic: Python Data Visualization
๐Ÿ—ฃ️ Language: Nepali
⏱️ Duration: 5 Minutes 33 Seconds

๐Ÿ‘ เคฏเคฆि เคญिเคกिเคฏो เค‰เคชเคฏोเค—ी เคฒाเค—्เคฏो เคญเคจे LIKE เค—เคฐ्เคจुเคนोเคธ्, เคธाเคฅीเคนเคฐूเคธँเค— SHARE เค—เคฐ्เคจुเคนोเคธ् เคฐ เคฏเคธ्เคคै Computer Science เคธเคฎ्เคฌเคจ्เคงी เคถैเค•्เคทिเค• เคญिเคกिเคฏोเค•ा เคฒाเค—ि SUBSCRIBE เค—เคฐ्เคจुเคนोเคธ्।

๐Ÿ’ฌ Comment Question: Matplotlib เคฐ Plotly เคฌीเคšเค•ो เคฎुเค–्เคฏ เคซเคฐเค• เค•े เคนो?

#Python #DataVisualization #Matplotlib #Plotly #SEEComputerScience #PythonInNepali #Class10ComputerScience



PYTHON DATA VISUALIZATION – 19 UNIQUE VVIP PROGRAMMING QUESTIONS

 

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

4.7 Introduction to Data Visualization - Python Programs

 

4.7 Introduction to Data Visualization

1. Write a Python program to draw a vertical bar chart showing the marks obtained by five students using Matplotlib. Give a suitable title and label both axes.

 

import matplotlib.pyplot as plt

students = ['Ram', 'Sita', 'Hari', 'Gita', 'Rita']

marks = [85, 90, 75, 95, 80]

plt.bar(students, marks, color='skyblue')

plt.xlabel('Students')

plt.ylabel('Marks')

plt.title('Marks Obtained by Students')

plt.show()

 

2. Write a Python program to display the marks obtained by five students using a Seaborn bar chart.

 

import seaborn as sns

import matplotlib.pyplot as plt

students = ['Ram', 'Sita', 'Hari', 'Gita', 'Rita']

marks = [85, 90, 75, 95, 80]

sns.barplot(x=students, y=marks, color='skyblue')

plt.xlabel('Students')

plt.ylabel('Marks')

plt.title('Marks Obtained by Students')

plt.show()

 

3. Write a Python program to draw an interactive bar chart showing the marks obtained by five students using Plotly Express.

 

import plotly.express as px

students = ['Ram', 'Sita', 'Hari', 'Gita', 'Rita']

marks = [85, 90, 75, 95, 80]

fig = px.bar(x=students, y=marks, title='Marks Obtained by Students', labels={'x': 'Students', 'y': 'Marks'})

fig.show()

 

4. Write a Python program to read student names and marks from a CSV file using Pandas and draw a vertical bar chart using Matplotlib.

 

import pandas as pd

import matplotlib.pyplot as plt

df = pd.read_csv('marks.csv')

plt.bar(df['Name'], df['Marks'], color='skyblue')

plt.xlabel('Students')

plt.ylabel('Marks')

plt.title('Student Marks from CSV')

plt.show()

5. Write a Python program to create a Pandas DataFrame containing student names and marks and draw a vertical bar chart using Matplotlib.

import pandas as pd

import matplotlib.pyplot as plt

data = {

    'Name': ['Ram', 'Sita', 'Hari', 'Gita', 'Rita'],

    'Marks': [85, 90, 75, 95, 80]

}

df = pd.DataFrame(data)

plt.bar(df['Name'], df['Marks'], color='skyblue')

plt.xlabel('Students')

plt.ylabel('Marks')

plt.title('Marks Obtained by Students')

plt.show()

 

6. Write a Python program to read student marks from a CSV file using Pandas and draw a bar chart using Seaborn.

import pandas as pd

import seaborn as sns

import matplotlib.pyplot as plt

df = pd.read_csv('marks.csv')

sns.barplot(data=df, x='Name', y='Marks', color='skyblue')

plt.xlabel('Students')

plt.ylabel('Marks')

plt.title('Student Marks from CSV')

plt.show()

 

7. Write a Python program to read student marks from a CSV file using Pandas and create an interactive bar chart using Plotly Express.

import pandas as pd

import plotly.express as px

df = pd.read_csv('marks.csv')

fig = px.bar(df, x='Name', y='Marks', title='Student Marks from CSV')

fig.show()

 

8. Write a Python program to draw a bar chart showing the marks of five students using different colors for each bar.

import matplotlib.pyplot as plt

students = ['Ram', 'Sita', 'Hari', 'Gita', 'Rita']

marks = [85, 90, 75, 95, 80]

colors = ['red', 'blue', 'green', 'orange', 'purple']

plt.bar(students, marks, color=colors)

plt.xlabel('Students')

plt.ylabel('Marks')

plt.title('Marks Obtained by Students')

plt.show()

9. Write a Python program to draw a line chart showing the monthly sales of a shop for five months: January (10000), February (15000), March (12000), April (18000) and May (22000). Use Matplotlib and give suitable labels and a title.

import matplotlib.pyplot as plt

months = ['Jan', 'Feb', 'Mar', 'Apr', 'May']

sales = [10000, 15000, 12000, 18000, 22000]

plt.plot(months, sales, marker='o', color='blue')

plt.xlabel('Months')

plt.ylabel('Sales (Rs.)')

plt.title('Monthly Sales with Markers')

plt.show()

 

10. Write a Python program to draw a line chart showing the monthly sales of a shop for five months using Seaborn. Give a suitable title and label both axes.

import seaborn as sns

import matplotlib.pyplot as plt

months = ['Jan', 'Feb', 'Mar', 'Apr', 'May']

sales = [10000, 15000, 12000, 18000, 22000]

sns.lineplot(x=months, y=sales, marker='o')

plt.xlabel('Months')

plt.ylabel('Sales (Rs.)')

plt.title('Monthly Sales Using Seaborn')

plt.show()

 

11. Write a Python program to draw an interactive line chart showing the monthly sales of a shop using Plotly Express. Include a suitable title, labels and markers.

import plotly.express as px

months = ['Jan', 'Feb', 'Mar', 'Apr', 'May']

sales = [10000, 15000, 12000, 18000, 22000]

fig = px.line(x=months,y=sales,markers=True,title='Monthly Sales',labels={'x': 'Months', 'y': 'Sales (Rs.)'})

fig.show()

 

12. A CSV file named sales.csv contains the monthly sales of a shop. Write a Python program to read the CSV file using Pandas and draw a line chart using Matplotlib. Give a suitable title and label both axes.

import pandas as pd

import matplotlib.pyplot as plt

df = pd.read_csv('sales.csv')

plt.plot(df['Month'], df['Sales'], marker='o')

plt.xlabel('Months')

plt.ylabel('Sales (Rs.)')

plt.title('Monthly Sales from CSV')

plt.show()

 

 

 

13. Write a Python program to read monthly sales data from a CSV file named sales.csv using Pandas and display a line chart using Seaborn. Include a suitable title and labels.

 

import pandas as pd

import seaborn as sns

import matplotlib.pyplot as plt

df = pd.read_csv('sales.csv')

sns.lineplot(data=df, x='Month', y='Sales', marker='o')

plt.xlabel('Months')

plt.ylabel('Sales (Rs.)')

plt.title('Monthly Sales from CSV')

plt.show()

 

14. Write a Python program to read monthly sales from a CSV file named sales.csv using Pandas and draw an interactive line chart using Plotly Express. Display markers and give a suitable title and labels.

 

import pandas as pd

import plotly.express as px

df = pd.read_csv('sales.csv')

fig = px.line(df, x='Month', y='Sales', markers=True, title='Monthly Sales from CSV', labels={'Month': 'Months', 'Sales': 'Sales (Rs.)'})

fig.show()

 

15. Write a Python program to draw a line chart showing monthly sales of a shop using Matplotlib. Display a red dashed line with circular markers. Give a suitable title and label both axes.

 

import matplotlib.pyplot as plt

months = ['Jan', 'Feb', 'Mar', 'Apr', 'May']

sales = [10000, 15000, 12000, 18000, 22000]

plt.plot(months, sales, color='red', linestyle='--', marker='o'

)

plt.xlabel('Months')

plt.ylabel('Sales (Rs.)')

plt.title('Monthly Sales')

plt.show()

 

16. Write a Python program to draw a pie chart showing the monthly household expenses of a family in five categories: Food (Rs. 12000), Rent (Rs. 20000), Transport (Rs. 5000), Education (Rs. 8000) and Others (Rs. 5000). Use Matplotlib, display category names and add a suitable title.

import matplotlib.pyplot as plt

categories = ['Food', 'Rent', 'Transport', 'Education', 'Others']

expenses = [12000, 20000, 5000, 8000, 5000]

plt.pie(expenses, labels=categories)

plt.title('Monthly Household Expenses')

plt.show()

17. Write a Python program to draw a pie chart showing the monthly expenses of a family using Matplotlib. Display the percentage of each category up to one decimal place, add labels and give a suitable title.

 

import matplotlib.pyplot as plt

categories = ['Food', 'Rent', 'Transport','Education', 'Others']

expenses = [12000, 20000, 5000, 8000, 5000]

plt.pie(expenses, labels=categories, autopct='%1.1f%%')

plt.title('Monthly Household Expenses')

plt.show()

 

19. Write a Python program to draw an interactive pie chart showing the monthly household expenses of a family using Plotly Express. Display category names and percentages with a suitable title.

 

import plotly.express as px

categories = ['Food', 'Rent', 'Transport', 'Education', 'Others']

expenses = [12000, 20000, 5000, 8000, 5000]

fig = px.pie(names=categories, values=expenses, title='Monthly Household Expenses')

fig.show()

 

20. A CSV file named expenses.csv contains household expense categories and their amounts. Write a Python program to read the CSV file using Pandas and draw a pie chart using Matplotlib. Display category names, percentages and a suitable title.

 

import pandas as pd

import matplotlib.pyplot as plt

df = pd.read_csv('expenses.csv')

plt.pie(

    df['Amount'],

    labels=df['Category'],

    autopct='%1.1f%%'

)

plt.title('Household Expenses from CSV')

plt.show()

 

22. Write a Python program to read the expenses.csv file using Pandas and create an interactive pie chart using Plotly Express. Display labels and percentages and give a suitable title.

 

import pandas as pd

import plotly.express as px

df = pd.read_csv('expenses.csv')

fig = px.pie(

    df,

    names='Category',

    values='Amount',

    title='Household Expenses from CSV'

)

fig.show()

 

23. Write a Python program to draw a pie chart showing household expenses using Matplotlib. Use different colors for each slice and display category names, percentages and a suitable title.

 

import matplotlib.pyplot as plt

categories = ['Food', 'Rent', 'Transport', 'Education', 'Others']

expenses = [12000, 20000, 5000, 8000, 5000]

colors = ['red', 'blue', 'green', 'orange', 'purple']

plt.pie(

    expenses,

    labels=categories,

    colors=colors,

    autopct='%1.1f%%'

)

plt.title('Monthly Household Expenses')

plt.show()

 

24. Write a Python program to draw a scatter plot showing the relationship between study hours and marks obtained by five students using Matplotlib. Give a suitable title and label both axes.

Study Hours

Marks

1

40

2

50

3

65

4

75

5

90

 

import matplotlib.pyplot as plt

hours = [1, 2, 3, 4, 5]

marks = [40, 50, 65, 75, 90]

plt.scatter(hours, marks, color='blue')

plt.xlabel('Study Hours')

plt.ylabel('Marks')

plt.title('Study Hours vs Marks')

plt.show()

 

25. Write a Python program to draw a scatter plot showing the relationship between study hours and marks obtained by five students using Seaborn. Add a title and appropriate axis labels.

 

import seaborn as sns

import matplotlib.pyplot as plt

hours = [1, 2, 3, 4, 5]

marks = [40, 50, 65, 75, 90]

sns.scatterplot(x=hours, y=marks, color='green')

plt.xlabel('Study Hours')

plt.ylabel('Marks')

plt.title('Study Hours vs Marks')

plt.show()

 

26. Write a Python program to draw an interactive scatter plot showing the relationship between study hours and marks using Plotly Express. Include a suitable title and labels.

 

import plotly.express as px

hours = [1, 2, 3, 4, 5]

marks = [40, 50, 65, 75, 90]

fig = px.scatter(

    x=hours,

    y=marks,

    title='Study Hours vs Marks',

    labels={'x': 'Study Hours', 'y': 'Marks'}

)

fig.show()

 

27. A CSV file named students.csv contains the study hours and marks obtained by five students. Write a Python program to read the CSV file using Pandas and draw a scatter plot using Matplotlib. Give a suitable title and label both axes.

 

import pandas as pd

import matplotlib.pyplot as plt

df = pd.read_csv('students.csv')

plt.scatter(df['Hours'], df['Marks'], color='blue')

plt.xlabel('Study Hours')

plt.ylabel('Marks')

plt.title('Study Hours vs Marks')

plt.show()

 

28. Write a Python program to draw a scatter plot showing the relationship between study hours and marks obtained by five students using Matplotlib. Use different colors and marker sizes for each point. Give a suitable title and label both axes.

 

import matplotlib.pyplot as plt

hours = [1, 2, 3, 4, 5]

marks = [40, 50, 65, 75, 90]

sizes = [100, 200, 300, 400, 500]

colors = ['red', 'blue', 'green', 'orange', 'purple']

plt.scatter(hours, marks, s=sizes, c=colors)

plt.xlabel('Study Hours')

plt.ylabel('Marks')

plt.title('Study Hours vs Marks')

plt.show()

 

 

29. A CSV file named students.csv contains the study hours and marks obtained by five students. Write a Python program to read the CSV file using Pandas and draw an interactive scatter plot using Plotly Express. Add a suitable title and axis labels.

 

import pandas as pd

import plotly.express as px

df = pd.read_csv('students.csv')

fig = px.scatter(

    df,

    x='Hours',

    y='Marks',

    title='Study Hours vs Marks',

    labels={'Hours': 'Study Hours', 'Marks': 'Marks'}

)

fig.show()

 

30. Write a Python program to read study hours and marks from a CSV file named students.csv using Pandas and draw a scatter plot using Seaborn. Give a suitable title and label both axes.

 

import pandas as pd

import seaborn as sns

import matplotlib.pyplot as plt

df = pd.read_csv('students.csv')

sns.scatterplot(data=df, x='Hours', y='Marks', color='green')

plt.xlabel('Study Hours')

plt.ylabel('Marks')

plt.title('Study Hours vs Marks')

plt.show()

 

31. Write a Python program to draw a scatter plot showing the relationship between study hours and marks obtained by five students using Matplotlib. Add grid lines, a suitable title and labels for both axes.

 

import matplotlib.pyplot as plt

hours = [1, 2, 3, 4, 5]

marks = [40, 50, 65, 75, 90]

plt.scatter(hours, marks, color='blue')

plt.xlabel('Study Hours')

plt.ylabel('Marks')

plt.title('Study Hours vs Marks')

plt.grid(True)

plt.show()

4.7 Introduction to Data Visualization

 

4.7 Introduction to Data Visualization

Data Visualization is the process of representing data through charts and graphs to make it easier to understand, analyze and interpret. It helps us identify patterns, trends and relationships in a simple and meaningful way.

Python provides various libraries, such as Matplotlib, Seaborn and Plotly, to create simple and advanced graphical representations of data.

Importance of Data Visualization

1.     Easy Understanding: Helps people understand large amounts of data easily through charts and graphs.

2.     Identify Patterns: Helps find repeated arrangements in data, such as sales increasing every Dashain.

3.     Identify Trends: Helps identify changes in data over time, such as the number of computer users increasing every year.

4.     Identify Relationships: Helps find connections between different sets of data, such as the relationship between students' study hours and their marks.

5.     Better Decision-Making: Helps businesses and professionals make better decisions by examining data.

6.     Clear Communication: Helps present and share information in a simple and understandable way.

Python Libraries for Data Visualization

Python provides different libraries for data visualization. Each library has its own features and is used to create different types of graphs and charts. Some popular Python libraries are:

1. Matplotlib: Used to create basic graphs such as bar charts, line graphs and pie charts.

2. Seaborn: Used to create attractive and colorful statistical graphs easily.

3. Plotly: Used to create interactive graphs that allow users to zoom, hover and explore data.

Matplotlib

Matplotlib is one of the most popular Python plotting libraries used for data visualization. It is a low-level library with a MATLAB-like interface that provides flexibility to create and customize different types of graphs, although it may require writing more code.

Installation of Matplotlib

Using pip: pip install matplotlib

Using conda: conda install matplotlib

Uses of Matplotlib

Matplotlib is suitable for creating different types of graphs, such as line charts, bar charts, pie charts, histograms, scatter plots

Importing Matplotlib

The pyplot module of Matplotlib can be imported using the following statement:

import matplotlib.pyplot as plt

Here:

  • matplotlib is the library name.
  • pyplot is the module used for creating graphs.
  • plt is the alias (short name) of pyplot.

Scatter Plot

A Scatter Plot is a type of graph that uses dots to represent the relationship between two variables. Each dot represents a pair of values (one X-value and one Y-value). It helps identify patterns and understand how two variables are related. Matplotlib provides the scatter() method to create a scatter plot.

Program: Create a Scatter Plot Using Matplotlib

import matplotlib.pyplot as plt

hours = [1, 2, 3, 4, 5]

marks = [40, 50, 60, 75, 90]

plt.scatter(hours, marks, color='blue', marker='o')

plt.title("Study Hours vs Marks")

plt.xlabel("Study Hours")

plt.ylabel("Marks")

plt.show()

Bar Chart

A Bar Chart is a type of graph that uses rectangular bars to represent data in different categories. The height or length of each bar represents the corresponding data value. It helps compare values among different categories easily. The bar() method of Matplotlib is used to create a bar chart.

Program: Create a Bar Chart Using Matplotlib

# Importing the libraries

import pandas as pd

import matplotlib.pyplot as plt

# Reading the dataset

data = pd.read_csv("Stu_data.csv")

# Creating bar chart

plt.bar(data['Name'], data['Marks'], color='skyblue')

# Adding title and labels

plt.title("Student Marks")

plt.xlabel("Name")

plt.ylabel("Marks")

# Displaying the graph

plt.show()

Difference Between Scatter Plot and Bar Chart

Scatter Plot

Bar Chart

Uses individual dots to represent data.

Uses rectangular bars to represent data.

Shows relationships between variables.

Compares different data categories.

Created using scatter().

Created using bar().

 

SEABORN

Seaborn is a Python library used to create attractive and informative charts. It is built on top of Matplotlib and works well with Pandas data. It supports different types of plots, such as line plots, bar plots and heatmaps. It helps visualize patterns and relationships in data and create complex charts using fewer lines of code.

Note: Matplotlib provides the basic graph-making functionality. Seaborn uses Matplotlib and adds attractive designs, colours and easier ways to create statistical charts.

 

Types of Charts Supported by Seaborn

i. Line Plots: Used to represent trends and changes in data.

ii. Bar Plots: Used to represent and compare data categories.

iii. Heatmaps: Use different colours to represent data values.

 

Installation of Seaborn

Seaborn can be installed using the following command in the command prompt:

pip install seaborn

Working Environment

Seaborn works best in Jupyter Notebook or IPython, which display charts more clearly.

 

Line Plot

A line plot is a type of graph that represents data points connected by lines. It is used to show patterns, trends and changes in data.

The lineplot() method is used to create a line plot in Seaborn.

Basic Syntax

sns.lineplot(x='column1', y='column2', data=dataset)

Where:

  • x represents the X-axis data.
  • y represents the Y-axis data.
  • data specifies the dataset used to create the plot.

 

Practical Program: Line Plot Using Seaborn

# Importing the libraries

import pandas as pd

import seaborn as sns

import matplotlib.pyplot as plt

# Reading the database

dataset = pd.read_csv("Stu_data.csv")

# Creating a line plot

sns.lineplot(x='Name', y='Marks', data=dataset)

# Displaying the graph

plt.show()

 

PLOTLY

1. Introduction to Plotly

Plotly is an open-source Python library used to create interactive charts. It supports different types of graphs, such as 3D charts, scientific and statistical charts, and financial charts. Plotly graphs can be viewed in Jupyter notebooks and web browsers or saved as HTML files. It also allows users to interact with charts by clicking, zooming and editing them.

Installation of Plotly

Plotly can be installed using the following command in the command prompt or terminal:

pip install plotly

Scatter Plot Using Plotly

# Importing the libraries

import pandas as pd

import plotly.express as px

# Reading the CSV dataset through Pandas

dataset = pd.read_csv("tips.csv")

# Creating a scatter plot

graph = px.scatter(dataset, x="total_bill", y="size", color="smoker")

# Displaying the chart

graph.show()

Line Chart Using Plotly

A line chart in Plotly is used to display data points connected by straight lines. It helps visualize changes and trends in data. Each data point is represented as a vertex (point) on the chart. Plotly makes line charts interactive and easy to customize.

Program: Create a Line Chart Using Plotly

# Importing the libraries

import plotly.express as px

import pandas as pd

# Reading the database

data = pd.read_csv("stu_data.csv")

# Creating a line chart

fig = px.line(data, y='Name', color='Gender')

# Displaying the chart

fig.show()

Bar Chart Using Plotly

A bar chart in Plotly is used to represent and compare data using rectangular bars. The height of each bar represents its corresponding value. Plotly Express provides the bar() function to create interactive bar charts.

Program: Create a Bar Chart Using Plotly

# Importing the libraries

import plotly.express as px

import pandas as pd

# Reading the database

data = pd.read_csv("Stu_data.csv")

# Creating a bar chart

fig = px.bar(data, x='Name', y='Marks', color='Gender')

# Displaying the chart

fig.show()

Common Marker Symbols

Markers are symbols used to show data points on a graph.

  • 'o' – Circle
  • '*' – Star
  • '^' – Upward triangle
  • 's' – Square
  • 'D' – Diamond
  • '+' – Plus

 

Common Line Styles

Line styles are used to change the appearance of lines in a graph.

  • '-' – Solid line
  • '--' – Dashed line
  • ':' – Dotted line
  • '-.' – Dash-dot line

 

plt.figure(figsize=(8, 5))

plt.plot(x, y, color='red', marker='o',

         linestyle='--', linewidth=2)

plt.title("Student Marks")

plt.xlabel("Name")

plt.ylabel("Marks")

plt.grid()

plt.show()

 

Explanation of the Program

Code

Function

plt.figure(figsize=(8, 5))

Sets the graph size (width 8, height 5).

plt.plot(x, y)

Creates a line graph using X and Y data.

color='red'

Changes the line colour to red.

marker='o'

Shows circle symbols at data points.

linestyle='--'

Makes the line dashed.

linewidth=2

Sets the line thickness to 2.

plt.title("Student Marks")

Adds a title to the graph.

plt.xlabel("Name")

Labels the X-axis as Name.

plt.ylabel("Marks")

Labels the Y-axis as Marks.

plt.grid()

Displays grid lines.

plt.show()

Displays the graph.

 


 

PYTHON DATA VISUALIZATION

20 EXAM-BASED PROGRAMMING QUESTIONS

Using Pandas and Matplotlib

 

========================================

SECTION A: LINE CHART (Q1–Q5)

========================================

 

Q1. MONTHLY SALES TREND

 

File: sales.csv

 

Month,Sales

Jan,12000

Feb,15000

Mar,18000

Apr,14000

May,20000

 

Write a Python program to:

1. Import Pandas and Matplotlib.

2. Read the CSV file.

3. Create a line chart using plt.plot().

4. Use a red line with circle markers.

5. Set the line width to 2.

6. Add the title "Monthly Sales Trend".

7. Label the X-axis as Month and Y-axis as Sales.

8. Display the chart.

 

 

Q2. WEEKLY TEMPERATURE CHANGES

 

File: temperature.csv

 

Day,Temperature

Sunday,20

Monday,25

Tuesday,28

Wednesday,24

Thursday,30

 

Write a Python program to:

1. Read the CSV file using Pandas.

2. Create a line chart using plt.plot().

3. Use a blue line with square markers.

4. Set the line style to dashed (--).

5. Add the title "Weekly Temperature Changes".

6. Label both axes.

7. Display the chart.

 

 

Q3. STUDENT PERFORMANCE

 

File: students.csv

 

Student,Marks

Ram,65

Sita,75

Hari,80

Gita,90

Rita,85

 

Write a Python program to:

1. Read the CSV file.

2. Create a line chart using plt.plot().

3. Use a green line with circle markers.

4. Set the line width to 2.

5. Add the title "Student Performance".

6. Label both axes.

7. Add a grid.

8. Display the chart.

 

 

Q4. POPULATION GROWTH

 

File: population.csv

 

Year,Population

2021,10000

2022,12000

2023,15000

2024,18000

2025,22000

 

Write a Python program to:

1. Read the CSV file.

2. Create a line chart using plt.plot().

3. Use a purple line with circle markers.

4. Set the line style to dashed.

5. Add the title "Population Growth".

6. Label both axes.

7. Display the chart.

 

 

Q5. MONTHLY WEBSITE VISITORS

 

File: visitors.csv

 

Month,Visitors

Jan,500

Feb,700

Mar,650

Apr,900

May,1200

 

Write a Python program to:

1. Read the CSV file.

2. Create a line chart using plt.plot().

3. Use an orange line with diamond markers.

4. Set the line width to 3.

5. Add the title "Monthly Website Visitors".

6. Label both axes.

7. Add a grid.

8. Display the chart.

 

 

========================================

SECTION B: BAR CHART (Q6–Q10)

========================================

 

Q6. SUBJECT-WISE MARKS

 

File: marks.csv

 

Subject,Marks

English,75

Mathematics,85

Science,90

Computer,95

Nepali,80

 

Write a Python program to:

1. Read the CSV file using Pandas.

2. Create a bar chart using plt.bar().

3. Set the bar colour to blue.

4. Add the title "Subject-wise Marks".

5. Label both axes.

6. Display the chart.

 

 

Q7. PRODUCT SALES

 

File: products.csv

 

Product,Sales

Laptop,20

Mobile,35

Keyboard,40

Mouse,50

Printer,15

 

Write a Python program to:

1. Read the CSV file.

2. Create a bar chart using plt.bar().

3. Use green bars.

4. Add the title "Product Sales".

5. Label both axes.

6. Display the chart.

 

 

Q8. NUMBER OF STUDENTS IN EACH CLASS

 

File: classes.csv

 

Class,Students

8,35

9,40

10,45

11,30

12,25

 

Write a Python program to:

1. Read the CSV file.

2. Create a bar chart using plt.bar().

3. Use orange bars.

4. Add the title "Number of Students in Each Class".

5. Label both axes.

6. Display the chart.

 

 

Q9. MONTHLY EXPENSES

 

File: expenses.csv

 

Category,Amount

Food,12000

Rent,15000

Education,8000

Transport,3000

Others,2000

 

Write a Python program to:

1. Read the CSV file.

2. Create a bar chart using plt.bar().

3. Use red bars.

4. Add the title "Monthly Expenses".

5. Label both axes.

6. Add a grid.

7. Display the chart.

 

 

Q10. FAVOURITE SPORTS

 

File: sports.csv

 

Sport,Students

Football,40

Cricket,30

Basketball,20

Volleyball,15

Badminton,25

 

Write a Python program to:

1. Read the CSV file.

2. Create a bar chart using plt.bar().

3. Use purple bars.

4. Add the title "Favourite Sports".

5. Label both axes.

6. Display the chart.

 

 

========================================

SECTION C: PIE CHART (Q11–Q15)

========================================

 

Q11. MONTHLY EXPENSES DISTRIBUTION

 

File: expenses.csv

 

Category,Amount

Food,12000

Rent,15000

Education,8000

Transport,3000

Others,2000

 

Write a Python program to:

1. Read the CSV file using Pandas.

2. Create a pie chart using plt.pie().

3. Display category labels.

4. Display percentage values using autopct.

5. Add the title "Monthly Expenses Distribution".

6. Display the chart.

 

 

Q12. SPORTS PARTICIPATION

 

File: sports.csv

 

Sport,Students

Football,40

Cricket,30

Basketball,20

Volleyball,10

 

Write a Python program to:

1. Read the CSV file.

2. Create a pie chart using plt.pie().

3. Display sport names and percentage values.

4. Set startangle=90.

5. Add the title "Sports Participation".

6. Display the chart.

 

 

Q13. LIBRARY BOOK DISTRIBUTION

 

File: library.csv

 

Category,Books

Science,40

Fiction,30

History,15

Computer,10

Others,5

 

Write a Python program to:

1. Read the CSV file.

2. Create a pie chart using plt.pie().

3. Display category labels.

4. Display percentage values up to one decimal place.

5. Add the title "Library Book Distribution".

6. Display the chart.

 

 

Q14. STUDENTS' MODES OF TRANSPORTATION

 

File: transport.csv

 

Transport,Students

Bus,45

Bicycle,20

Walking,15

Motorcycle,10

Car,10

 

Write a Python program to:

1. Read the CSV file.

2. Create a pie chart using plt.pie().

3. Display transport names and percentage values.

4. Add the title "Students' Modes of Transportation".

5. Display the chart.

 

 

Q15. COMPUTER PARTS SALES

 

File: computer.csv

 

Part,Sales

Keyboard,25

Mouse,30

Monitor,20

Printer,15

Speaker,10

 

Write a Python program to:

1. Read the CSV file.

2. Create a pie chart using plt.pie().

3. Display labels and percentage values.

4. Set startangle=90.

5. Add the title "Computer Parts Sales".

6. Display the chart.

 

 

========================================

SECTION D: SCATTER CHART (Q16–Q20)

========================================

 

Q16. STUDY HOURS VS MARKS

 

File: study.csv

 

Hours,Marks

1,40

2,50

3,60

4,75

5,90

 

Write a Python program to:

1. Read the CSV file using Pandas.

2. Create a scatter chart using plt.scatter().

3. Use red points with s=100.

4. Add the title "Study Hours vs Marks".

5. Label both axes.

6. Add a grid.

7. Display the chart.

 

 

Q17. TEMPERATURE VS ICE CREAM SALES

 

File: temperature.csv

 

Temperature,Sales

20,30

25,45

30,60

35,80

40,100

 

Write a Python program to:

1. Read the CSV file.

2. Create a scatter chart using plt.scatter().

3. Use blue points with s=80.

4. Add the title "Temperature vs Ice Cream Sales".

5. Label both axes.

6. Add a grid.

7. Display the chart.

 

 

Q18. ADVERTISING VS SALES

 

File: advertising.csv

 

Advertising,Sales

1000,5000

2000,7000

3000,9000

4000,12000

5000,15000

 

Write a Python program to:

1. Read the CSV file.

2. Create a scatter chart using plt.scatter().

3. Use green points with s=120.

4. Add the title "Advertising vs Sales".

5. Label both axes.

6. Add a grid.

7. Display the chart.

 

 

Q19. AGE VS SALARY

 

File: salary.csv

 

Age,Salary

22,20000

25,25000

30,35000

35,45000

40,55000

 

Write a Python program to:

1. Read the CSV file.

2. Create a scatter chart using plt.scatter().

3. Use purple points with s=100.

4. Add the title "Age vs Salary".

5. Label both axes.

6. Add a grid.

7. Display the chart.

 

 

Q20. EXERCISE HOURS VS CALORIES BURNED

 

File: exercise.csv

 

Hours,Calories

1,150

2,250

3,350

4,450

5,600

 

Write a Python program to:

1. Read the CSV file.

2. Create a scatter chart using plt.scatter().

3. Use orange points with s=150.

4. Add the title "Exercise Hours vs Calories Burned".

5. Label both axes.

6. Add a grid.

7. Display the chart.

 

 

========================================

END OF 20 PROGRAMMING QUESTIONS

========================================


 

Python programs | Matplotlib, Seaborn, Plotly, Pandas and CSV

1. Write a Python program to draw a vertical bar chart showing the marks obtained by five students using Matplotlib. Give a suitable title and label both axes.

 

import matplotlib.pyplot as plt

students = ['Ram', 'Sita', 'Hari', 'Gita', 'Rita']

marks = [85, 90, 75, 95, 80]

plt.bar(students, marks, color='skyblue')

plt.xlabel('Students')

plt.ylabel('Marks')

plt.title('Marks Obtained by Students')

plt.show()

 

2. Write a Python program to draw a horizontal bar chart showing the marks obtained by five students using Matplotlib.

 

import matplotlib.pyplot as plt

students = ['Ram', 'Sita', 'Hari', 'Gita', 'Rita']

marks = [85, 90, 75, 95, 80]

plt.barh(students, marks, color='green')

plt.xlabel('Marks')

plt.ylabel('Students')

plt.title('Marks Obtained by Students')

plt.show()

 

3. Write a Python program to display the marks obtained by five students using a Seaborn bar chart.

 

import seaborn as sns

import matplotlib.pyplot as plt

students = ['Ram', 'Sita', 'Hari', 'Gita', 'Rita']

marks = [85, 90, 75, 95, 80]

sns.barplot(x=students, y=marks, color='skyblue')

plt.xlabel('Students')

plt.ylabel('Marks')

plt.title('Marks Obtained by Students')

plt.show()

 

4. Write a Python program to draw an interactive bar chart showing the marks obtained by five students using Plotly Express.

 

import plotly.express as px

students = ['Ram', 'Sita', 'Hari', 'Gita', 'Rita']

marks = [85, 90, 75, 95, 80]

fig = px.bar(x=students, y=marks, title='Marks Obtained by Students', labels={'x': 'Students', 'y': 'Marks'})

fig.show()

 

5. Write a Python program to create a Pandas DataFrame containing student names and marks and draw a vertical bar chart using Matplotlib.

 

import pandas as pd

import matplotlib.pyplot as plt

data = {

    'Name': ['Ram', 'Sita', 'Hari', 'Gita', 'Rita'],

    'Marks': [85, 90, 75, 95, 80]

}

df = pd.DataFrame(data)

plt.bar(df['Name'], df['Marks'], color='skyblue')

plt.xlabel('Students')

plt.ylabel('Marks')

plt.title('Marks Obtained by Students')

plt.show()

 

6. Write a Python program to create a Pandas DataFrame containing student names and marks and draw a bar chart using Seaborn.

 

import pandas as pd

import seaborn as sns

import matplotlib.pyplot as plt

data = {

    'Name': ['Ram', 'Sita', 'Hari', 'Gita', 'Rita'],

    'Marks': [85, 90, 75, 95, 80]

}

df = pd.DataFrame(data)

sns.barplot(data=df, x='Name', y='Marks',  color='skyblue')

plt.xlabel('Students')

plt.ylabel('Marks')

plt.title('Marks Obtained by Students')

plt.show()

 

7. Write a Python program to create a Pandas DataFrame containing student names and marks and display an interactive bar chart using Plotly Express.

 

import pandas as pd

import plotly.express as px

data = {

    'Name': ['Ram', 'Sita', 'Hari', 'Gita', 'Rita'],

    'Marks': [85, 90, 75, 95, 80]

}

df = pd.DataFrame(data)

fig = px.bar(df, x='Name', y='Marks', title='Marks Obtained by Students')

fig.show()

 

8. Write a Python program to read student names and marks from a CSV file using Pandas and draw a vertical bar chart using Matplotlib.

 

import pandas as pd

import matplotlib.pyplot as plt

df = pd.read_csv('marks.csv')

plt.bar(df['Name'], df['Marks'], color='skyblue')

plt.xlabel('Students')

plt.ylabel('Marks')

plt.title('Student Marks from CSV')

plt.show()

 

9. Write a Python program to read student marks from a CSV file using Pandas and draw a bar chart using Seaborn.

 

import pandas as pd

import seaborn as sns

import matplotlib.pyplot as plt

df = pd.read_csv('marks.csv')

sns.barplot(data=df, x='Name', y='Marks', color='skyblue')

plt.xlabel('Students')

plt.ylabel('Marks')

plt.title('Student Marks from CSV')

plt.show()

 

10. Write a Python program to read student marks from a CSV file using Pandas and create an interactive bar chart using Plotly Express.

 

import pandas as pd

import plotly.express as px

df = pd.read_csv('marks.csv')

fig = px.bar(df, x='Name', y='Marks', title='Student Marks from CSV')

fig.show()

 

11. Write a Python program to read student marks from a CSV file using Pandas and draw a horizontal bar chart using Matplotlib.

 

import pandas as pd

import matplotlib.pyplot as plt

df = pd.read_csv('marks.csv')

plt.barh(df['Name'], df['Marks'], color='green')

plt.xlabel('Marks')

plt.ylabel('Students')

plt.title('Student Marks from CSV')

plt.show()

 

12. Write a Python program to draw a bar chart showing the marks of five students using different colors for each bar.

 

import matplotlib.pyplot as plt

students = ['Ram', 'Sita', 'Hari', 'Gita', 'Rita']

marks = [85, 90, 75, 95, 80]

colors = ['red', 'blue', 'green', 'orange', 'purple']

plt.bar(students, marks, color=colors)

plt.xlabel('Students')

plt.ylabel('Marks')

plt.title('Marks Obtained by Students')

 

plt.show()

 

13. Write a Python program to draw a vertical bar chart of five students' marks, including a suitable chart title, X-axis label and Y-axis label.

 

import matplotlib.pyplot as plt

students = ['Ram', 'Sita', 'Hari', 'Gita', 'Rita']

marks = [85, 90, 75, 95, 80]

plt.bar(students, marks)

plt.title('Student Marks')

plt.xlabel('Student Names')

plt.ylabel('Obtained Marks')

plt.show()

 

14. Write a Python program to draw a line chart showing the monthly sales of a shop for five months: January (10000), February (15000), March (12000), April (18000) and May (22000). Use Matplotlib and give suitable labels and a title.

 

import matplotlib.pyplot as plt

months = ['Jan', 'Feb', 'Mar', 'Apr', 'May']

sales = [10000, 15000, 12000, 18000, 22000]

plt.plot(months, sales)

plt.xlabel('Months')

plt.ylabel('Sales (Rs.)')

plt.title('Monthly Sales')

plt.show()

 

15. Write a Python program to display the monthly sales of a shop using a line chart with circular markers at each data point. Use Matplotlib and add a title and axis labels.

 

import matplotlib.pyplot as plt

months = ['Jan', 'Feb', 'Mar', 'Apr', 'May']

sales = [10000, 15000, 12000, 18000, 22000]

plt.plot(months, sales, marker='o', color='blue')

plt.xlabel('Months')

plt.ylabel('Sales (Rs.)')

plt.title('Monthly Sales with Markers')

plt.show()

 

16. Write a Python program to draw a line chart showing the monthly sales of a shop for five months using Seaborn. Give a suitable title and label both axes.

 

import seaborn as sns

import matplotlib.pyplot as plt

months = ['Jan', 'Feb', 'Mar', 'Apr', 'May']

sales = [10000, 15000, 12000, 18000, 22000]

sns.lineplot(x=months, y=sales, marker='o')

plt.xlabel('Months')

plt.ylabel('Sales (Rs.)')

plt.title('Monthly Sales Using Seaborn')

plt.show()

 

17. Write a Python program to draw an interactive line chart showing the monthly sales of a shop using Plotly Express. Include a suitable title, labels and markers.

 

import plotly.express as px

months = ['Jan', 'Feb', 'Mar', 'Apr', 'May']

sales = [10000, 15000, 12000, 18000, 22000]

fig = px.line(

    x=months,

    y=sales,

    markers=True,

    title='Monthly Sales',

    labels={'x': 'Months', 'y': 'Sales (Rs.)'}

)

fig.show()

 

18. Write a Python program to create a Pandas DataFrame containing monthly sales for five months and display the data using a line chart in Matplotlib. Include a suitable title and labels.

 

import pandas as pd

import matplotlib.pyplot as plt

data = {

    'Month': ['Jan', 'Feb', 'Mar', 'Apr', 'May'],

    'Sales': [10000, 15000, 12000, 18000, 22000]

}

df = pd.DataFrame(data)

plt.plot(df['Month'], df['Sales'], marker='o')

plt.xlabel('Months')

plt.ylabel('Sales (Rs.)')

plt.title('Monthly Sales Using Pandas')

plt.show()

 

19. Write a Python program to create a Pandas DataFrame containing months and sales and draw a line chart using Seaborn. Give a suitable title and axis labels.

 

import pandas as pd

import seaborn as sns

import matplotlib.pyplot as plt

data = {

    'Month': ['Jan', 'Feb', 'Mar', 'Apr', 'May'],

    'Sales': [10000, 15000, 12000, 18000, 22000]

}

df = pd.DataFrame(data)

sns.lineplot(data=df, x='Month', y='Sales',  marker='o')

plt.xlabel('Months')

plt.ylabel('Sales (Rs.)')

plt.title('Monthly Sales Using Seaborn')

plt.show()

 

20. Write a Python program to create a Pandas DataFrame containing monthly sales and draw an interactive line chart using Plotly Express. Display circular markers and add a suitable chart title.

 

import pandas as pd

import plotly.express as px

data = {

    'Month': ['Jan', 'Feb', 'Mar', 'Apr', 'May'],

    'Sales': [10000, 15000, 12000, 18000, 22000]

}

df = pd.DataFrame(data)

fig = px.line(

    df,

    x='Month',

    y='Sales',

    markers=True,

    title='Monthly Sales Using Plotly',

    labels={'Month': 'Months', 'Sales': 'Sales (Rs.)'}

)

fig.show()

 

21. A CSV file named sales.csv contains the monthly sales of a shop. Write a Python program to read the CSV file using Pandas and draw a line chart using Matplotlib. Give a suitable title and label both axes.

 

import pandas as pd

import matplotlib.pyplot as plt

df = pd.read_csv('sales.csv')

plt.plot(df['Month'], df['Sales'], marker='o')

plt.xlabel('Months')

plt.ylabel('Sales (Rs.)')

plt.title('Monthly Sales from CSV')

plt.show()

 

22. Write a Python program to read monthly sales data from a CSV file named sales.csv using Pandas and display a line chart using Seaborn. Include a suitable title and labels.

 

import pandas as pd

import seaborn as sns

import matplotlib.pyplot as plt

df = pd.read_csv('sales.csv')

sns.lineplot(data=df, x='Month', y='Sales', marker='o')

plt.xlabel('Months')

plt.ylabel('Sales (Rs.)')

plt.title('Monthly Sales from CSV')

plt.show()

 

23. Write a Python program to read monthly sales from a CSV file named sales.csv using Pandas and draw an interactive line chart using Plotly Express. Display markers and give a suitable title and labels.

 

import pandas as pd

import plotly.express as px

df = pd.read_csv('sales.csv')

fig = px.line(df, x='Month', y='Sales', markers=True, title='Monthly Sales from CSV', labels={'Month': 'Months', 'Sales': 'Sales (Rs.)'})

fig.show()

 

24. Write a Python program to read the monthly sales of a shop from sales.csv using Pandas and draw a line chart with circular markers, a blue line, a suitable title and axis labels using Matplotlib.

 

import pandas as pd

import matplotlib.pyplot as plt

df = pd.read_csv('sales.csv')

plt.plot(df['Month'], df['Sales'], marker='o', linestyle='-', color='blue')

plt.xlabel('Months')

plt.ylabel('Sales (Rs.)')

plt.title('Monthly Sales with Markers')

plt.show()

 

25. Write a Python program to draw a line chart showing monthly sales of a shop using Matplotlib. Display a red dashed line with circular markers. Give a suitable title and label both axes.

 

import matplotlib.pyplot as plt

months = ['Jan', 'Feb', 'Mar', 'Apr', 'May']

sales = [10000, 15000, 12000, 18000, 22000]

plt.plot(months, sales, color='red', linestyle='--', marker='o'

)

plt.xlabel('Months')

plt.ylabel('Sales (Rs.)')

plt.title('Monthly Sales')

plt.show()

 

26. Write a Python program to draw a line chart representing the monthly sales of a shop for five months using Matplotlib. Set the chart title to "Monthly Sales Report", the X-axis label to "Months" and the Y-axis label to "Sales (Rs.)".

 

import matplotlib.pyplot as plt

months = ['Jan', 'Feb', 'Mar', 'Apr', 'May']

sales = [10000, 15000, 12000, 18000, 22000]

plt.plot(months, sales)

plt.title('Monthly Sales Report')

plt.xlabel('Months')

plt.ylabel('Sales (Rs.)')

plt.show()

 

27. Write a Python program to draw a pie chart showing the monthly household expenses of a family in five categories: Food (Rs. 12000), Rent (Rs. 20000), Transport (Rs. 5000), Education (Rs. 8000) and Others (Rs. 5000). Use Matplotlib, display category names and add a suitable title.

 

import matplotlib.pyplot as plt

categories = ['Food', 'Rent', 'Transport', 'Education', 'Others']

expenses = [12000, 20000, 5000, 8000, 5000]

plt.pie(expenses, labels=categories)

plt.title('Monthly Household Expenses')

plt.show()

 

28. Write a Python program to draw a pie chart showing the monthly expenses of a family using Matplotlib. Display the percentage of each category up to one decimal place, add labels and give a suitable title.

 

import matplotlib.pyplot as plt

categories = ['Food', 'Rent', 'Transport','Education', 'Others']

expenses = [12000, 20000, 5000, 8000, 5000]

plt.pie(expenses, labels=categories, autopct='%1.1f%%')

plt.title('Monthly Household Expenses')

plt.show()

 

29. Write a Python program to draw a pie chart showing household expenses using Matplotlib with a Seaborn theme. Display category labels, percentages and a suitable title.

 

import seaborn as sns

import matplotlib.pyplot as plt

categories = ['Food', 'Rent', 'Transport', 'Education', 'Others']

expenses = [12000, 20000, 5000, 8000, 5000]

plt.pie(expenses, labels=categories,  autopct='%1.1f%%')

plt.title('Monthly Household Expenses')

plt.show()

 

30. Write a Python program to draw an interactive pie chart showing the monthly household expenses of a family using Plotly Express. Display category names and percentages with a suitable title.

 

import plotly.express as px

categories = ['Food', 'Rent', 'Transport', 'Education', 'Others']

expenses = [12000, 20000, 5000, 8000, 5000]

fig = px.pie(names=categories, values=expenses, title='Monthly Household Expenses')

fig.show()

 

31. Write a Python program to create a Pandas DataFrame containing five household expense categories and their amounts. Draw a pie chart using Matplotlib and display category names, percentages and a suitable title.

 

import pandas as pd

import matplotlib.pyplot as plt

data = {

    'Category': ['Food', 'Rent', 'Transport',

                 'Education', 'Others'],

    'Amount': [12000, 20000, 5000, 8000, 5000]

}

df = pd.DataFrame(data)

plt.pie(df['Amount'],

        labels=df['Category'],

        autopct='%1.1f%%')

plt.title('Monthly Household Expenses')

plt.show()

 

32. Write a Python program to create a Pandas DataFrame containing monthly household expenses and display them using a pie chart with a Seaborn theme and Matplotlib.

 

import pandas as pd

import seaborn as sns

import matplotlib.pyplot as plt

data = {

    'Category': ['Food', 'Rent', 'Transport',

                 'Education', 'Others'],

    'Amount': [12000, 20000, 5000, 8000, 5000]

}

df = pd.DataFrame(data)

plt.pie(df['Amount'],

        labels=df['Category'],

        autopct='%1.1f%%')

plt.title('Monthly Household Expenses')

plt.show()

 

33. Write a Python program to create a Pandas DataFrame containing monthly household expenses and display an interactive pie chart using Plotly Express. Add a suitable title and display percentage values.

 

import pandas as pd

import plotly.express as px

data = {

    'Category': ['Food', 'Rent', 'Transport',

                 'Education', 'Others'],

    'Amount': [12000, 20000, 5000, 8000, 5000]

}

df = pd.DataFrame(data)

fig = px.pie(

    df,

    names='Category',

    values='Amount',

    title='Monthly Household Expenses'

)

fig.show()

 

34. A CSV file named expenses.csv contains household expense categories and their amounts. Write a Python program to read the CSV file using Pandas and draw a pie chart using Matplotlib. Display category names, percentages and a suitable title.

 

import pandas as pd

import matplotlib.pyplot as plt

df = pd.read_csv('expenses.csv')

plt.pie(

    df['Amount'],

    labels=df['Category'],

    autopct='%1.1f%%'

)

plt.title('Household Expenses from CSV')

plt.show()

 

35. Write a Python program to read household expenses from a CSV file using Pandas and draw a pie chart with a Seaborn theme. Display category names, percentages and a suitable title.

 

import pandas as pd

import seaborn as sns

import matplotlib.pyplot as plt

df = pd.read_csv('expenses.csv')

sns.set_theme(style='white')

plt.pie(

    df['Amount'],

    labels=df['Category'],

    autopct='%1.1f%%'

)

plt.title('Household Expenses from CSV')

plt.show()

 

36. Write a Python program to read the expenses.csv file using Pandas and create an interactive pie chart using Plotly Express. Display labels and percentages and give a suitable title.

 

import pandas as pd

import plotly.express as px

df = pd.read_csv('expenses.csv')

fig = px.pie(

    df,

    names='Category',

    values='Amount',

    title='Household Expenses from CSV'

)

fig.show()

 

37. Write a Python program to draw a pie chart showing household expenses using Matplotlib. Use different colors for each slice and display category names, percentages and a suitable title.

 

import matplotlib.pyplot as plt

categories = ['Food', 'Rent', 'Transport', 'Education', 'Others']

expenses = [12000, 20000, 5000, 8000, 5000]

colors = ['red', 'blue', 'green', 'orange', 'purple']

plt.pie(

    expenses,

    labels=categories,

    colors=colors,

    autopct='%1.1f%%'

)

plt.title('Monthly Household Expenses')

plt.show()

 

37. Write a Python program to draw a scatter plot showing the relationship between study hours and marks obtained by five students using Matplotlib. Give a suitable title and label both axes.

Study Hours

Marks

1

40

2

50

3

65

4

75

5

90

 

import matplotlib.pyplot as plt

hours = [1, 2, 3, 4, 5]

marks = [40, 50, 65, 75, 90]

plt.scatter(hours, marks, color='blue')

plt.xlabel('Study Hours')

plt.ylabel('Marks')

plt.title('Study Hours vs Marks')

plt.show()

 

38. Write a Python program to draw a scatter plot showing the relationship between study hours and marks obtained by five students using Seaborn. Add a title and appropriate axis labels.

 

import seaborn as sns

import matplotlib.pyplot as plt

hours = [1, 2, 3, 4, 5]

marks = [40, 50, 65, 75, 90]

sns.scatterplot(x=hours, y=marks, color='green')

plt.xlabel('Study Hours')

plt.ylabel('Marks')

plt.title('Study Hours vs Marks')

plt.show()

 

40. Write a Python program to draw an interactive scatter plot showing the relationship between study hours and marks using Plotly Express. Include a suitable title and labels.

 

import plotly.express as px

hours = [1, 2, 3, 4, 5]

marks = [40, 50, 65, 75, 90]

fig = px.scatter(

    x=hours,

    y=marks,

    title='Study Hours vs Marks',

    labels={'x': 'Study Hours', 'y': 'Marks'}

)

fig.show()

 

41. Write a Python program to create a Pandas DataFrame containing the study hours and marks obtained by five students. Draw a scatter plot using Matplotlib with suitable labels and a title.

 

import pandas as pd

import matplotlib.pyplot as plt

data = {

    'Hours': [1, 2, 3, 4, 5],

    'Marks': [40, 50, 65, 75, 90]

}

df = pd.DataFrame(data)

plt.scatter(df['Hours'], df['Marks'], color='red')

plt.xlabel('Study Hours')

plt.ylabel('Marks')

plt.title('Study Hours vs Marks')

plt.show()

 

42. A CSV file named students.csv contains the study hours and marks obtained by five students. Write a Python program to read the CSV file using Pandas and draw a scatter plot using Matplotlib. Give a suitable title and label both axes.

 

import pandas as pd

import matplotlib.pyplot as plt

df = pd.read_csv('students.csv')

plt.scatter(df['Hours'], df['Marks'], color='blue')

plt.xlabel('Study Hours')

plt.ylabel('Marks')

plt.title('Study Hours vs Marks')

plt.show()

 

 

43. Write a Python program to draw a scatter plot showing the relationship between study hours and marks obtained by five students using Matplotlib. Use different colors and marker sizes for each point. Give a suitable title and label both axes.

 

import matplotlib.pyplot as plt

hours = [1, 2, 3, 4, 5]

marks = [40, 50, 65, 75, 90]

sizes = [100, 200, 300, 400, 500]

colors = ['red', 'blue', 'green', 'orange', 'purple']

plt.scatter(hours, marks, s=sizes, c=colors)

plt.xlabel('Study Hours')

plt.ylabel('Marks')

plt.title('Study Hours vs Marks')

plt.show()

 

44. Write a Python program to create a Pandas DataFrame containing the study hours and marks obtained by five students. Draw a scatter plot using Seaborn. Give a suitable title and label both axes.

 

import pandas as pd

import seaborn as sns

import matplotlib.pyplot as plt

data = {

    'Hours': [1, 2, 3, 4, 5],

    'Marks': [40, 50, 65, 75, 90]

}

df = pd.DataFrame(data)

sns.scatterplot(data=df, x='Hours', y='Marks', color='blue')

plt.xlabel('Study Hours')

plt.ylabel('Marks')

plt.title('Study Hours vs Marks')

plt.show()

 

45. A CSV file named students.csv contains the study hours and marks obtained by five students. Write a Python program to read the CSV file using Pandas and draw an interactive scatter plot using Plotly Express. Add a suitable title and axis labels.

 

import pandas as pd

import plotly.express as px

df = pd.read_csv('students.csv')

fig = px.scatter(

    df,

    x='Hours',

    y='Marks',

    title='Study Hours vs Marks',

    labels={'Hours': 'Study Hours', 'Marks': 'Marks'}

)

fig.show()

 

46. Write a Python program to read study hours and marks from a CSV file named students.csv using Pandas and draw a scatter plot using Seaborn. Give a suitable title and label both axes.

 

import pandas as pd

import seaborn as sns

import matplotlib.pyplot as plt

df = pd.read_csv('students.csv')

sns.scatterplot(data=df, x='Hours', y='Marks', color='green')

plt.xlabel('Study Hours')

plt.ylabel('Marks')

plt.title('Study Hours vs Marks')

plt.show()

47. Write a Python program to draw a scatter plot showing the relationship between study hours and marks obtained by five students using Matplotlib. Add grid lines, a suitable title and labels for both axes.

 

import matplotlib.pyplot as plt

hours = [1, 2, 3, 4, 5]

marks = [40, 50, 65, 75, 90]

plt.scatter(hours, marks, color='blue')

plt.xlabel('Study Hours')

plt.ylabel('Marks')

plt.title('Study Hours vs Marks')

plt.grid(True)

plt.show()