VOOZH about

URL: https://www.geeksforgeeks.org/python/how-to-create-a-scatter-plot-with-several-colors-in-matplotlib/

⇱ How to create a Scatter Plot with several colors in Matplotlib? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to create a Scatter Plot with several colors in Matplotlib?

Last Updated : 23 Jul, 2025

Matplotlib is a plotting library for creating static, animated, and interactive visualizations in Python. Matplotlib can be used in Python scripts, the Python and IPython shell, web application servers, and various graphical user interface toolkits like Tkinter, awxPython, etc. In this article, we will see how to create a scatter plot with different colors in Matplotlib.

Parameter Marker Color to Create a Scatter Plot 

The possible values for marker color are:

  • A single color format string.
  • A 2-D array in which the rows are RGB or RGBA.

Create a Scatter Plot with Several Colors in Matplotlib Example

Below are some examples by which we can see how to customize Matplotlib plots with different colors and change colors in Matplotlib in Python:

  • Creating Scatter Plots with Matplotlib
  • Scatter Plot with Categorical Coloring

Matplotlib Customize Plot Colors Using Scatter Plots

In this example, we are using the Matplotlib library to generate two scatter plots. The first set of data points (x=[1, 2, 3, 4], y=[4, 1, 3, 6]) is depicted as green dots, while the second set (x=[5, 6, 7, 8], y=[1, 3, 5, 2]) is shown in red. The plt.scatter() function is used to create each scatter plot, specifying the x and y coordinates along with the color ('c') of the markers.

Output:

👁 create a Scatter Plot with several colors in Matplotlib
create a Scatter Plot with several colors in Matplotlib

Matplotlib Scatter Plot with Categorical Coloring using Colormap

Example 1: Create a Scatter Plot with RGB Colors

Colormap instances are used to convert data values (floats) from the interval [0, 1] to the RGBA color. In this example, the code utilizes the Matplotlib library to create a scatter plot. It first imports necessary modules, including matplotlib.pyplot and NumPy. Data points are represented by a 2D array 'a', with each column containing x and y coordinates.

Output:

👁 create a Scatter Plot with several colors in Matplotlib
create a Scatter Plot with several colors in Matplotlib

Example 2: Create a Scatter Plot Using Color Codes

In this example, we are using Matplotlib to generate a scatter plot with specific data points and color-coded categories. Initially, essential modules such as Matplotlib and NumPy are imported. The data points are defined as a NumPy array 'a,' consisting of two arrays representing x and y coordinates.

Output:

👁 create a Scatter Plot with several colors in Matplotlib
create a Scatter Plot with several colors in Matplotlib
Comment