• Home
  • Courses
  • School
  • Programs
  • Problems
  • Contact Us
  • My account
  • Register

Have any question?

(+91) 98222 16647
info@simplycoding.in
RegisterLogin
Simply Coding
  • Home
  • Courses
  • School
  • Programs
  • Problems
  • Contact Us
  • My account
  • Register

Python

Python Pyplot Example

  • Categories Python, Python Libraries
Python Pyplot Examples

Python Pyplot Examples:

1.Create multiple line charts on common plot where two data ranges are plotted on same chart. The data range(s) to be plotted is/are:  
line 1 points
                         x1 = [10,20,30]
                         y1= [20,40,10]
line 2 points
                         x2 = [10,20,30] 
                         y2 = [40,10,30]          
The legend is on top left corner. X Axis has label “X – Axis” and y axis has label “Y – Axis”. The lines should have different width and color.
Ans
import matplotlib.pyplot as plt
# line 1 points
x1 = [10,20,30]
y1 = [20,40,10]
# line 2 points
x2 = [10,20,30]
y2 = [40,10,30]
 
plt.xlabel('X - Axis')
plt.ylabel('Y - Axis')
 
# Display the figure.
plt.plot(x1,y1, color='b', linewidth = 3,  label = 'line1')
plt.plot(x2,y2, color='r', linewidth = 5,  label = 'line2')
 
plt.legend()
plt.show()
 
linechart1

2.With the given data range(s) the line graph plotted is as shown. Write the python code to plot it.
 City 1City 2City 3
Toy 151012
Toy 261110
Toy 381415
Ans.
import numpy as np
import matplotlib.pyplot as plt
Data=[[5,6,8], [10,11,14], [12,10,15]]

X=np.arange(3)
plt.plot(X,Data[0],color='b',label='Toy 1')
plt.plot(X,Data[1],color='g',label='Toy 2')
plt.plot(X,Data[2],color='r',label='Toy 3')
plt.legend(loc='upper left')
plt.title("Toy Sales")
plt.xlabel("Toys")
plt.ylabel("City Sales")
plt.show()

linechart2
3.The data of three runners over 4 marathons is as given below. Write the code which will create the bar chart as below.
barchart1
                     Runners = [[5,25,45,20],[4,23,49,17], [6,22,47,19]]
Ans.
import numpy as np
import matplotlib.pyplot as plt
Run = [[5,25,45,20],[4,23,49,17], [6,22,47,19]]
X=np.arange(4)
plt.bar(X+0.00,Run[0],color='r',width=0.25)
plt.bar(X+0.25,Run[1],color='g',width=0.25)
plt.bar(X+0.5,Run[2],color='b',width=0.25)
plt.show()
4.Given data point p as [2,4,6], the bar chart displayed below has bars for p, p**2 and p**2. Write the code to create the graph.
barchart2
Ans.
import numpy as np
import matplotlib.pyplot as plt
p= np.array([2,4,6])
x=np.arange(3)
plt.bar(x,p,color='r',width=0.3)
plt.bar(x+0.3,p*2,color='b',width=0.3)
plt.bar(x+0.6,p**2,color='g',width=0.3)
plt.title("Series Comparision")
plt.show()
5.Write the code to create a pie chart for marks of a student as below.  
SubjectMarks
English67
Physics88
Chemistry63
Biology77
Maths65
  1. Show Maths value exploded
  2. Show % contribution for each subject
  3. The pie chart should be circular
Ans.
import matplotlib.pyplot as plt
Marks=[67,88,63, 77, 65]
Subject=["English","Physics","Chemistry","Biology","Maths"]
plt.axis("equal")
plt.pie(Marks,labels=Subject,explode=[0,0,0,0,0.2],autopct="%1.2f%%")
plt.show()
piechart1
6.Below is given a table consisting of grades and number of students who scored the respective grades in a class. Plot a pie chart to show the data
  1. The chart should have labels and percentage upto one decimal
  2. Explode the pie which has the maximum grade.
GradeABCDE
No . of students40551008025
Ans.
import matplotlib.pyplot as plt
students=[40,55,100,80,25]
grade=['A','B','C','D','E']
exp=[0,0,0.2,0,0]
plt.pie(students,labels=grade,explode=exp,autopct='%2.1f%%')
plt.show()
piechart2
  • Share:
author avatar
Simply Coding

Previous post

CBSE Python Data Structures Exercises
April 23, 2020

Next post

CBSE Python Question Bank on if else
April 24, 2020

You may also like

Libraries
Python Libraries
3 July, 2021
character python
Solve any character pattern program in python
3 June, 2021
number pattern in python
Solve any number patterns programs in python
3 June, 2021

Leave A Reply Cancel reply

You must be logged in to post a comment.

Categories

  • Uncategorized
  • Programs
    • Python
    • Java
  • Problems
    • Python
    • Java
    • Web Development
      • Internet
    • Emerging Technologies
  • Notes
    • General
    • QBasic
    • MS Access
    • Web Development
      • XML
      • HTML
      • JavaScript
      • Internet
    • Database
    • Logo Programming
    • Scratch
    • Emerging Trends
      • Artificial Intelligence
      • Internet of Things
      • Cloud Computing
      • Machine Learning
    • Computer Fundamentals
      • Computer Networks
      • E-Services
      • Computer Hardware
    • Python
    • Java
  • School
    • ICSE
      • Computers Class 9
        • Java Introduction
        • Tokens & Data Types
        • Java Operators
        • Math Library
        • if & switch
        • For & While
        • Nested loops
      • Computer Class 10
        • Sample Papers
        • OOPS concepts
        • Functions in Java
        • Constructors
        • Arrays in Java
        • Strings in Java
    • SSC
      • IT Class 11
        • IT Basics
        • DBMS
        • Web Designing
        • Cyber Laws
      • IT Class 12
        • Web Designing
        • SEO
        • Advanced JavaScript
        • Emerging Tech
        • Server Side Scripting
        • E-Com & E-Gov
      • Computer Science 11
      • Computer Science 12
    • CBSE
      • Computer 9
        • Basics of IT
        • Cyber Safety
        • Scratch
        • Python
      • Computer 10
        • Sample Papers
        • Networking
        • HTML
        • Cyber Ethics
        • Scratch
        • Python
      • Computer Science 11
        • Computer Systems
        • Python 11
          • Python Basics
          • Python Tokens
          • Python Operators
          • Python if-else
          • Python loops
          • Python Strings
          • Python List
          • Python Tuple
          • Python Dictionary
          • Python Modules
        • Data Management
      • Computer Science 12
        • Sample Papers
        • Python 12
          • Python Functions
          • Python File Handling
          • Python Libraries
          • Python Recursion
          • Data Structures
        • Computer Networks
        • Data Management
    • ISC
      • Computer Science 11
        • Introduction to Java
        • Values & Data Types
        • Operators
        • if & switch
        • Iterative Statements
        • Functions
        • Arrays
        • String
        • Data Structures
        • Cyber Ethics
      • Computer Science 12
        • Sample Papers
        • Boolean Algebra
        • OOPS
        • Wrapper Classes
        • Functions
        • Arrays
        • String

Categories

  • Uncategorized
  • Programs
    • Python
    • Java
  • Problems
    • Python
    • Java
    • Web Development
      • Internet
    • Emerging Technologies
  • Notes
    • General
    • QBasic
    • MS Access
    • Web Development
      • XML
      • HTML
      • JavaScript
      • Internet
    • Database
    • Logo Programming
    • Scratch
    • Emerging Trends
      • Artificial Intelligence
      • Internet of Things
      • Cloud Computing
      • Machine Learning
    • Computer Fundamentals
      • Computer Networks
      • E-Services
      • Computer Hardware
    • Python
    • Java
  • School
    • ICSE
      • Computers Class 9
        • Java Introduction
        • Tokens & Data Types
        • Java Operators
        • Math Library
        • if & switch
        • For & While
        • Nested loops
      • Computer Class 10
        • Sample Papers
        • OOPS concepts
        • Functions in Java
        • Constructors
        • Arrays in Java
        • Strings in Java
    • SSC
      • IT Class 11
        • IT Basics
        • DBMS
        • Web Designing
        • Cyber Laws
      • IT Class 12
        • Web Designing
        • SEO
        • Advanced JavaScript
        • Emerging Tech
        • Server Side Scripting
        • E-Com & E-Gov
      • Computer Science 11
      • Computer Science 12
    • CBSE
      • Computer 9
        • Basics of IT
        • Cyber Safety
        • Scratch
        • Python
      • Computer 10
        • Sample Papers
        • Networking
        • HTML
        • Cyber Ethics
        • Scratch
        • Python
      • Computer Science 11
        • Computer Systems
        • Python 11
          • Python Basics
          • Python Tokens
          • Python Operators
          • Python if-else
          • Python loops
          • Python Strings
          • Python List
          • Python Tuple
          • Python Dictionary
          • Python Modules
        • Data Management
      • Computer Science 12
        • Sample Papers
        • Python 12
          • Python Functions
          • Python File Handling
          • Python Libraries
          • Python Recursion
          • Data Structures
        • Computer Networks
        • Data Management
    • ISC
      • Computer Science 11
        • Introduction to Java
        • Values & Data Types
        • Operators
        • if & switch
        • Iterative Statements
        • Functions
        • Arrays
        • String
        • Data Structures
        • Cyber Ethics
      • Computer Science 12
        • Sample Papers
        • Boolean Algebra
        • OOPS
        • Wrapper Classes
        • Functions
        • Arrays
        • String
Simply Coding Computer Courses for School                Privacy Policy     Terms of Use     Contact Us

© 2021 Simply Coding

Login with your site account

Lost your password?

Not a member yet? Register now

Register a new account

Are you a member? Login now