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...

GRADE XII CS - VIVA QUESTIONS

  VIVA QUESTIONS GRADE XII CS Dear All Be thorough with your project and practical files, as the viva can be asked from anywhere. Stay calm, don’t get nervous, and be confident in front of the examiner. 1. Tell me about your project. 2. Which concepts you have used for your project? 3. What do you mean by front end and back end? How they are important in developing any such projects? 4  Mention the modules and built-in functions you have used in your project. 5. Which real world problems are solved by your project? 6. Explain the most important feature of your project. 7. Name a few mutable data types of python. Lists, Sets, and Dictionaries 8. Name a few immutable data types of python. Strings, Tuples, Numeric 9. Name ordered and unordered data type of python. Ordered – String, List, Tuples Unordred – Set, Dictionaries 10. What is the significance of a pass statement in python? pass is no operation python statement. This is used where python requires syntax but logic requires...