Skip to main content

GRADE XII - IP - MATPLOTLIB QUESTIONS | 21 JULY

 ASSIGNMENT

MATPLOTLIB


1.     #1  Make A bar graph of the number of boys and girls who have opted the given subjects.

Sub: French,English math, geography,Science

Girls: 20,30,40,38,45

Boys: 25,22,40,31,42

Use Xticks to show subjects and rotation=30

Sol:

import pandas as pd

import matplotlib.pyplot as plt

data = {

    'Girls': [20, 30, 40, 38, 45],

    'Boys': [25, 22, 40, 31, 42]

}

subjects = ['French', 'English', 'Math', 'Geography', 'Science']

 df = pd.DataFrame(data, index=subjects)

 # Plot bar chart

df.plot(kind='bar', rot=30, color=['pink', 'skyblue'])

 # Labels and title

plt.xlabel('Subjects')

plt.ylabel('Number of Students')

plt.title('Subject-wise Student Count by Gender')

plt.tight_layout()

plt.show()


1.     #2  Create a bar plot to show horizontal bar plot

Year: 2020,2019,2018,2017

Sales: 1200,700,1500,800

Sol:

import matplotlib.pyplot as plt

 year = ['2020', '2019', '2018', '2017']

sales = [1200, 700, 1500, 800]

 # Plotting horizontal bar chart

plt.barh(year, sales, color='lightgreen')

 # Adding labels and title

plt.xlabel('Sales')

plt.ylabel('Year')

plt.title('Year-wise Sales')

 # Display the plot

plt.show()


1.    #3   Create a Histogram graph based on marks given:

[take random values upto 100]

Sol:

import matplotlib.pyplot as plt

marks = [25, 67, 88, 90, 25, 67, 55, 35,64,34,67,12]

 # Plot histogram with 10 bins

plt.hist(marks, bins=10, color='skyblue', edgecolor='black')

 # Labels and title

plt.xlabel('Marks Range')

plt.ylabel('Number of Students')

plt.title('Distribution of Marks (Histogram)')

plt.show()


1.       #4Create a dataframe:

2018      2019      2020

10          15          18

20          25          29         

15          20          22

25          28          30

Index as A,B,C,D

Plot bar chart based on the above data

Sol:

import pandas as pd

import matplotlib.pyplot as plt

 # Create the DataFrame

data = {

    '2018': [10, 20, 15, 25],

    '2019': [15, 25, 20, 28],

    '2020': [18, 29, 22, 30]

}

 df = pd.DataFrame(data, index=['A', 'B', 'C', 'D'])

 # Display the DataFrame (optional)

print(df)


Comments

Popular posts from this blog

PYTHON - MYSQL CONNECTIVITY CODE

  #INSERTION OF DATA import mysql.connector mydb = mysql.connector.connect( host="localhost", user="root", passwd="root", database="school" ) print("Successfully Connected") #print(mydb) mycursor=mydb.cursor()   v1=int(input("enter ID:")) v2=input("enter name:") v3=input("enter Gender:") v4=int(input("enter age:")) sql='insert into TEACH values("%d","%s","%s","%s")'%(v1,v2,v3,v4) print(sql) mycursor.execute(sql) mydb.commit() print("record added") #MYSQL Connection code – Deletion on database SOURCE CODE: s=int(input("enter id of TEACHER to be deleted:")) r=(s,) v="delete from TEACH where id=%s" mycursor.execute(v,r) mydb.commit() print("record deleted") MYSQL Connection code – Updation on database SOURCE CODE: import mysql.connector mydb = mysql.connector.c...

REVISION IF CONSTRUCT | CLASS TEST

                                                                                     CLASS TEST 1. Write a Python program that asks the user for their age, gender, and current fitness level (beginner, intermediate, or advanced). Based on this information, suggest a suitable fitness plan using if-else statements. Requirements: Inputs : Age (integer) Gender (male/female) Fitness level (beginner/intermediate/advanced) Outputs : Recommend a fitness plan that includes: Suggested workout duration. Type of exercises (e.g., cardio, strength, flexibility). Rest days. Logic : Use if-else to determine the plan based on conditions such as: Age group (e.g., <18, 18–40, >40). Fitness leve...