Wind Rose Plot Visualization in Matplotlib using Python

Hey there fellow Python visualizer! In this tutorial, we bring yet another visualization chart known as the Wind Rose Chart using Matplotlib in Python programming. We will understand what Wind Rose plots are, why are they used and what are their advantages. Later, we will learn how to implement the same chart using the Matplotlib library in Python.

Introduction to Wind Rose Chart

Wind Rose plots help display frequencies of wind directions and speeds in a circular format. The circular layout is a representation of a compass and hence is, divided into sections. The length of each line indicates the frequency of wind and the angle will indicate the direction of the wind. These plots are useful in identifying wind patterns, directions, and wind speeds over time to make analysts understand climatic changes based on wind patterns.

Advantages of Wind Rose Plot

These plots have a variety of advantages, some are listed below:

  1. Provides a clear visualization of wind patterns.
  2. Easy identification of wind directions and speed.
  3. It is useful in analyzing seasonal or climatic variations based on wind patterns.

Python Code Implementation of Wind Rose Charts

We will start by creating a dataset for Wind Analysis, I will be creating a data frame to plot wind directions and wind speeds using numpy and pandas library. Have a look at the code snippet below which is self-explanatory given you are aware of numpy and pandas libraries. For direction, I have taken angles in radians as they are representations of degrees of angles for direction.

import numpy as np
import pandas as pd

df = pd.DataFrame({'Directions': np.radians(np.random.uniform(0, 360, 5)), 
                   "Speeds": np.random.uniform(0, 20, 5)})
print(df)

The resulting data frame is as follows:

   Directions     Speeds
0    6.003409   0.660051
1    1.746655   8.181999
2    3.952451   8.981164
3    4.831855  19.045060
4    1.372460  12.813151

Visualizing a Basic Wind Chart

In this section, next, we will now use Matplotlib to create a basic Wind Rose plot using the generated data. For the visualization, we will make use of simple functions like polar and hist and add coloring components to visualize the plot properly.

import matplotlib.pyplot as plt

plt.figure(figsize=(5, 5))
ax = plt.subplot(polar=True)
ax.hist(df['Directions'], weights=df['Speeds'], edgecolor='blue', color='skyblue')

plt.title('Basic Wind Rose Plot')
plt.show()

The resulting visualization displayed on the screen is as follows:

Wind Rose Chart using Matplotlib in Python

In this circular histogram where the angles represent the direction of the wind and the length of each bar represents the speed of the wind.

Customizing the Basic Wind Chart

To customize the basic plot, we will be doing the following: Adding alpha component to the plot, Adding customization to the circular grid and as I mentioned before the circular layout acts as a compass, we will add directions as ticks to the plot instead of numeric values.

import matplotlib.pyplot as plt

plt.figure(figsize=(5, 5))
ax = plt.subplot(polar=True)
ax.hist(df['Directions'], weights=df['Speeds'], 
        edgecolor='blue', color='skyblue',alpha=0.5)

ax.grid(True, linestyle='dashdot', alpha=0.3, color='green')

compass_labels = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW']
ax.set_xticks(np.arange(0, 2*np.pi, 2*np.pi/8))
ax.set_xticklabels(compass_labels)

plt.title('Customized Wind Rose Plot')
plt.show()

The resulting visualization displayed on the screen is as follows:

Customized Wind Rose Chart

Using a Real-World Dataset for Wind Chart

Let’s use a dataset mentioned about wind direction and speeds from the internet. For this tutorial, I have downloaded the CSV file mentioned in the link here. And the rest of the procedure remains the same. Have a look at the complete code and output below.

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

df = pd.read_csv('wind_data.csv')
num_bins = 72
plt.figure(figsize=(8, 8))
ax = plt.subplot(polar=True)
weights = df['Wind speed (m/s) @ 10m'] / df['Wind speed (m/s) @ 10m'].max()
bars = ax.hist(np.radians(df['Wind direction']), bins=num_bins, weights=weights, 
               edgecolor='blue', color='skyblue', alpha=0.5)
ax.grid(True, linestyle='dashdot', alpha=0.3, color='green')
compass_labels = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW']
ax.set_xticks(np.linspace(0, 2*np.pi, len(compass_labels), endpoint=False))
ax.set_xticklabels(compass_labels)

plt.title('Real Time Data Wind Rose Plot')
plt.show()

As this is real-world data, the dataset will be very large compared to earlier. We will add a few modifications to make the plot visually appealing and more informative. The resulting visualization displayed on the screen is as follows:

Customized Wind Rose Chart

I hope you liked this tutorial and learned something new through this tutorial as well. Have a look at the tutorial below as well.

  1. Side-by-side Boxplots in Python
  2. Data Visualizations But Animated – Python
  3. Venn Diagram in Python Programming
  4. Create a Pie chart using Plotly in Python

Happy Learning!

Leave a Reply

Your email address will not be published. Required fields are marked *