# Plotting a Load-Duration Curve with Python

Rate this post

You can check out the code in this article in the interactive Jupyter notebook here (Google Colab).

## Introduction

1. What is a load-duration curve?
2. What is the importance of a load-duration curve?
3. How do you calculate a load-duration curve?
4. What is the shape of a load-duration curve?
5. How to plot a load-duration curve?

This article will address these questions from the perspective of the electric power industry, with which I am familiar. It will also show how to calculate and plot a load-duration curve using Python and its NumPy, Pandas, and Seaborn modules.

## What is a Load-Duration Curve?

A load-duration curve is a plot of an electrical system’s load (demand), in units of power versus the percentage of the time for which this load or a load is greater than it existed. The load is plotted on the y-axis and the percentage of time on the x-axis. The load is not plotted in chronological order but in descending order of magnitude.

## The Shape of a Load-Duration Curve

The highest load is on the left of the graph, with the load decreasing towards the right and the lowest load on the far right. The resulting curve, therefore, slopes downward from the maximum load to the minimum load and is generally shaped like a reverse sigmoid function ()).

## The Importance of a Load-Duration Curve

Load-duration curves are plotted for daily, weekly, or annual periods and are used to conduct technical and economic analyses of an electrical system. It presents load information in an intuitive form and can be used to determine the maximum load and its duration.

They can be used to determine the duration of a specific load, that is, the amount of time that a load was equal to or greater than a particular value. Therefore, it can be used to determine the amount of time that various generating capacities must be available. The load is greater than or equal to the minimum load 100 percent of the time. This minimum load is referred to as the baseload. The capacity to meet this load must be always available. The area under the curve represents the total energy generated in this period.

## How to Plot a Load-Duration Curve

Electric utilities usually record the system load at hourly intervals. This data can be used to develop the load duration for a selected period. The loads for each recording interval are sorted in descending order of magnitude and multiplied by the percentage of the period that the load was equal to or above this value. The load is then plotted on the y-axis and the percentage of time that it was equal to or above that value on the x-axis.

## Plotting a Load-Duration Curve Using Python

The above procedure is illustrated using a Google Collaboratory Notebook, using Python and its NumPy, Matplotlib, Pandas, and Seaborn modules. This will be done using made-up data. For brevity, a period of one day will be used. However, the period could be a week, a month, or a year.

In the first cell, the required modules were loaded. The data are then loaded. These can be loaded from `*.csv` or Excel files or databases. For this illustration, a Python dictionary data structure was used. The loads and the hour at which they occurred were put in a dictionary as shown in the second cell below.

```#load the required modules
import numpy
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sb```
```# initialise a dictionary with the load data.
load_data = {'Hour':[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23], 'Load':[39.0, 39.2, 37.6, 36.8, 36.4, 36.2, 37.4, 41.4, 45.6, 48.8, 53.0, 53.6, 53.2, 54.0, 53.8, 52.8, 50.8, 44.4, 46.8, 47.4, 46.4, 44.0, 42.4, 40.6]}

In the next cell, the dictionary is converted to a Pandas DataFrame with the hour and load as columns. A graph of the load versus the hour is plotted using the `lineplot()` function of the Seaborn module. The load, in this case, is in chronological order and the graph is known as a (daily) load profile.

```# Convert dictionary to DataFrame and print it
```# Plot the load profile

sb.set(rc={"figure.figsize":(10, 7)})

plt.ylim(0, None)
plt.xlim(0, None)

p.set_xlabel("Time (Hrs)", fontsize = 20)

plt.show()```

The next step is to add a column with the time interval for which the loads were recorded. In this case, the loads were recorded in one-hour intervals.

```# Add a column for the time interval for which the loads were recorded

The next step is to rearrange the loads from being in chronological order to one of descending order of magnitude. This is done by sorting the DataFrame by the load column using the `sort_values()` function with the ascending parameter set to `False`. The printout of the DataFrame confirms that the loads are now in descending order of magnitude.

```# Sort the DataFrame by the loads, in descending order of magnitude

The next step is to add a column with the amount of time the system load was equal to or greater than the load in each row of the DataFrame. This is achieved by applying the `cumsum()` function to the interval column and assigning the results to a new column name duration. The `cumsum()` function calculates the cumulative sum over an axis of a Pandas DataFrame. In this case, it’s over the column axis. The printout verifies that the operation was successful.

```# Use the cumsum() function to to add a column with the duration
# for which the system load is greater than or equal to each load

The x-axis of the load duration curve is expressed as a percentage of the total time. So, the next step is to add a column with the duration expressed as a percentage of the total time. This is done in the next cell with the result printed out.

```# Calculate the percentage of time for which
# the system load is greater than or equal to each load

It’s now time to plot the load duration curve. As was done for the load profile, it was plotted using the `lineplot()` function of the Seaborn module. The load is on the y-axis and the percentage on the x-axis. The plot shows a curve that slopes downward from the maximum load to the minimum load and has some resemblance to a reverse sigmoid curve.

```# Plot the load_duration curve (Load vs Percentage of time)

plt.ylim(0, None)
plt.xlim(0, None)