
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to make several plots on a single page using matplotlib in Python?
Using Pandas, we can create a data frame and create a figure and axis. After that, we can use the scatter method to draw points.
Steps
Create lists of students, marks obtained by them, and color codings for each score.
Make a data frame using Panda’s DataFrame, with step 1 data.
Create fig and ax variables using subplots method, where default nrows and ncols are 1.
Set the X-axis label using plt.xlabel() method.
Set the Y-axis label using plt.ylabel() method.
A scatter plot of *y* vs. *x* with varying marker size and/or color.
To show the figure, use plt.show() method.
Example
from matplotlib import pyplot as plt import pandas as pd no_of_students = [1, 2, 3, 5, 7, 8, 9, 10, 30, 50] marks_obtained_by_student = [100, 95, 91, 90, 89, 76, 55, 10, 3, 19] color_coding = ['red', 'blue', 'yellow', 'green', 'red', 'blue', 'yellow', 'green', 'yellow', 'green'] df = pd.DataFrame(dict(students_count=no_of_students, marks=marks_obtained_by_student, color=color_coding)) fig, ax = plt.subplots() plt.xlabel('Students count') plt.ylabel('Obtained marks') ax.scatter(df['students_count'], df['marks'], c=df['color']) plt.show()
Output
- Related Articles
- How to make several plots on a single page using Matplotlib(Python)?
- How to make several plots on a single page using Matplotlib?
- How to make semilogx and semilogy plots in Matplotlib?
- How to make two plots side-by-side using Python?
- How to make several legend keys to the same entry in Matplotlib?
- How can Matplotlib be used to three-dimensional line plots using Python?
- How to make colorbar orientation horizontal in Python using Matplotlib?
- How to make a page redirect using jQuery?
- How to reuse plots in Matplotlib?
- How do I show the same Matplotlib figure several times in a single IPython notebook?
- How to save multiple plots into a single HTML file in Python Plotly?
- How to align multiple plots in a grid using GridSpec Class in Matplotlib
- How can multiple plots be plotted in same figure using matplotlib and Python?
- How to add multiple graphs to a Plotly Dash app on a single browser page in Python Plotly?
- How to add annotations in Matplotlib Plots?

Advertisements