HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →
Live examsInternational live exams are comingTell us which exam you want first. Timed practice papers are open now.See what is coming →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Space Science and Astronomy
  • Earth and Environmental Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Python Programming
  2. /Python for Science and Maths
  3. /Graphs with matplotlib

Graphs with matplotlib

Python Programming · High School (11–12) · 1 course, 10 worked problems, 20 practice questions

A graph shows a pattern that a table of numbers hides. The matplotlib library is the main plotting tool in Python. After import matplotlib.pyplot as plt, you can draw a line with plt.plot(x, y) and show it with plt.show(). A title, axis labels with units, a legend and grid lines make a graph easy to read. Other kinds of plot include scatter plots for experimental data, bar charts and histograms. A log scale shows data that changes over a wide range. With NumPy, matplotlib can plot a formula in a few lines.

With practice you will be able to

  • Plot a line graph of yyy against xxx with plt.plot()
  • Add a title, axis labels with units and a legend
  • Choose a scatter plot, bar chart or histogram for a data set

On the syllabus of

  • CBSE / State Class 12

Lessons

  • Graphs with matplotlibHow many points make a curve look smooth? Can a car's positions give its speed?High School (11–12)

Practice questions

Choose an answer, then check it. Each one shows a full explanation.

Which format string draws a green dashed line?

fig, axes = plt.subplots(2, 2). How many sets of axes does the figure have?

A detector counts 2500 clicks. What is the usual uncertainty of the count?

Which graph best shows the populations of five cities?

Worked problems

Each one has a hint, the key idea and a full worked solution.

  • Two cyclists, Asha and Ravi, have these distances in metres at 0, 1, 2, 3, 4 and 5 minutes…Easy
  • This program was meant to draw the height of a plant in centimetres over 10 days, but it stops with…Easy
  • Draw the graph of y = x² - 5x + 6 for x from 0 to 5…Medium
  • Draw three waves of the form y = A sin(2π f t) on one graph, for t from 0 to 2 seconds: A = 1 and f…Medium
  • For each job, say which graph you would draw: a line graph, a scatter plot, a bar chart or a…Easy

Python labs

  • Plot the cyclists
  • Plot a function
  • Count the bars
  • Histogram numbers
  • Two panels
  • Project: speed and acceleration

Related topics

  • Python for Science and Maths
  • NumPy Arrays
  • Solving Equations
  • Calculus by Computer
  • Simulation and Randomness
  • Data Analysis with pandas
  • Chemistry by Computer
  • Biology by Computer
  • Trigonometry and Waves by Computer

Which graph shows how 500 measurements of one length are spread around their mean?

What must you do so that the labels of two lines appear on a graph?

Why does a curve drawn from 5 points look rough?

Ice cream sales and the number of swimmers at a beach have a correlation of 0.9. What does this show?

What does a straight line on a graph with a log scale on the y axis tell you about the data?

A student writes plt.plot(time, distance), where time has 11 numbers and distance has 10. What happens?

All 20 practice questions on Graphs with matplotlib →

These are the marks of 30 students out of 100: 35, 48, 52, 55, 58, 61, 62, 64, 65, 66, 67, 68, 70…
Medium
  • A cup of tea is 60 degrees hotter than the room at time 0…Hard
  • A savings account starts with 1000 dollars and grows by 8 percent each year: after n years it has…Medium
  • A trolley is at the positions 0, 3, 12, 27, 48, 75 and 108 metres at the times 0, 1, 2, 3, 4, 5 and…Medium
  • A cyclist's speed in m/s at the times 0, 1, 2,..., 10 seconds is 0, 2, 4, 6, 8, 8, 8, 6, 4, 2, 0…Hard