Matplotlib Plot Multiple Lines with Same Color

While I was working on data visualization in Python as a part of a project for my clients, one of the common tasks I encountered was plotting multiple lines on the same graph. Often, the goal is to emphasize the overall trend or category rather than individual lines, which means using the same color for all lines can be very effective.

In this tutorial, I’ll share my firsthand experience on how to plot multiple lines with the same color in Matplotlib. Whether you’re visualizing sales trends across different US states or comparing temperature data over time, this guide will help you create clean and consistent charts.

Let’s get started!

Methods to Plot Multiple Lines with the Same Color

Sometimes, you want to group several lines visually without overloading the graph with too many colors. For example, if you are plotting monthly sales data for different stores across the US, using the same color can help highlight the overall sales pattern rather than individual store differences.

Using the same color also keeps your charts simple and professional, especially when paired with other visual cues like line styles or markers.

Method 1: Plot Multiple Lines Using a Loop with the Same Color

One of the easiest ways to plot multiple lines with the same color is by using a loop. This method is easy and gives you control over each line’s data.

Here’s an example where I plot sales data for three stores in the USA over six months. All lines are plotted in blue.

import matplotlib.pyplot as plt

# Sample monthly sales data for 3 stores (in thousands of dollars)
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
store1_sales = [25, 30, 28, 35, 40, 45]
store2_sales = [20, 22, 25, 30, 33, 37]
store3_sales = [15, 18, 20, 25, 28, 30]

# Combine sales data into a list
all_sales = [store1_sales, store2_sales, store3_sales]

plt.figure(figsize=(10, 6))

# Plot each store's sales in blue
for sales in all_sales:
    plt.plot(months, sales, color='blue')

plt.title('Monthly Sales for 3 Stores (Same Color)')
plt.xlabel('Month')
plt.ylabel('Sales (Thousands of $)')
plt.grid(True)
plt.show()

I executed the above example code and added the screenshot below.

Plot Multiple Lines with Same Color in Matplotlib

In this example, I simply loop through each store’s sales data and plot it using the color blue. This keeps the chart visually consistent and easy to interpret.

Read Matplotlib Dashed Line

Method 2: Plot Multiple Lines at Once with the Same Color

Python Matplotlib also allows you to plot multiple lines in one command by passing multiple y-values. You can specify the color once, and it applies to all lines.

Here’s how:

import matplotlib.pyplot as plt
import numpy as np

months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
x = np.arange(len(months))

store1_sales = [25, 30, 28, 35, 40, 45]
store2_sales = [20, 22, 25, 30, 33, 37]
store3_sales = [15, 18, 20, 25, 28, 30]

# Stack sales data for plotting
all_sales = np.array([store1_sales, store2_sales, store3_sales])

plt.figure(figsize=(10, 6))

# Plot all lines with the same color 'green'
for sales in all_sales:
    plt.plot(x, sales, color='green')

plt.xticks(x, months)
plt.title('Monthly Sales for 3 Stores (Green Lines)')
plt.xlabel('Month')
plt.ylabel('Sales (Thousands of $)')
plt.grid(True)
plt.show()

I executed the above example code and added the screenshot below.

Plot Multiple Lines with Same Color Matplotlib

This method is similar to the first but uses NumPy arrays for convenience. I’ve used green here to show how easy it is to change colors globally.

Method 3: Use Line Styles or Markers to Differentiate Lines

When all lines share the same color, it might be helpful to differentiate them by line style or markers. This is especially useful in black-and-white prints or presentations.

Here’s an example:

import matplotlib.pyplot as plt

months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
x = range(len(months))

store1_sales = [25, 30, 28, 35, 40, 45]
store2_sales = [20, 22, 25, 30, 33, 37]
store3_sales = [15, 18, 20, 25, 28, 30]

plt.figure(figsize=(10, 6))

# Plot with same color but different line styles and markers
plt.plot(x, store1_sales, color='red', linestyle='-', marker='o', label='Store 1')
plt.plot(x, store2_sales, color='red', linestyle='--', marker='s', label='Store 2')
plt.plot(x, store3_sales, color='red', linestyle=':', marker='^', label='Store 3')

plt.xticks(x, months)
plt.title('Monthly Sales for 3 Stores (Same Color with Styles)')
plt.xlabel('Month')
plt.ylabel('Sales (Thousands of $)')
plt.legend()
plt.grid(True)
plt.show()

I executed the above example code and added the screenshot below.

Matplotlib Plot Multiple Lines with Same Color

By using different line styles and markers, I keep the color consistent while still making each line distinguishable.

Method 4: Plot Multiple Lines with the Same Color Using Pandas

If you’re working with tabular data in Pandas, plotting multiple lines with the same color can be done easily with the .plot() method in Python.

Example:

import pandas as pd
import matplotlib.pyplot as plt

# Create a DataFrame with sales data
data = {
    'Jan': [25, 20, 15],
    'Feb': [30, 22, 18],
    'Mar': [28, 25, 20],
    'Apr': [35, 30, 25],
    'May': [40, 33, 28],
    'Jun': [45, 37, 30]
}
stores = ['Store 1', 'Store 2', 'Store 3']
df = pd.DataFrame(data, index=stores)

plt.figure(figsize=(10, 6))

# Transpose to have months on x-axis and plot all stores with same color
df.T.plot(color='purple', legend=True)

plt.title('Monthly Sales for 3 Stores (Pandas Plot, Same Color)')
plt.xlabel('Month')
plt.ylabel('Sales (Thousands of $)')
plt.grid(True)
plt.show()

Here, the color='purple' argument applies the same color to all lines. It’s a quick way to visualize multiple series without manually looping.

Tips for Using the Same Color Effectively

  • Use line styles or markers to distinguish lines when using the same color.
  • Add a legend to make it clear what each line represents.
  • Choose a color that contrasts well with the background for readability.
  • Avoid using too many lines with the same color to prevent confusion.

Plotting multiple lines with the same color in Matplotlib is easy once you know the right approach. Whether you prefer looping through your data, using NumPy arrays, or leveraging Pandas, you can create clean and effective visualizations that emphasize group trends.

If you want to keep your charts simple or highlight categories rather than individual series, this technique is invaluable. I hope this guide helps you create better visual stories with Python.

You may also like to read other Matplotlib tutorials:

51 Python Programs

51 PYTHON PROGRAMS PDF FREE

Download a FREE PDF (112 Pages) Containing 51 Useful Python Programs.

pyython developer roadmap

Aspiring to be a Python developer?

Download a FREE PDF on how to become a Python developer.

Let’s be friends

Be the first to know about sales and special discounts.