Learn how to create a Taylor Diagram in Python using Matplotlib and Pandas. This guide explains model evaluation through standard deviation, correlation, and performance visualization with clear code examples.
A polar plot is a type of plot where data is displayed using angles and radial distances instead of Cartesian x-y coordinates.
Element | Description |
---|---|
Angle (ΞΈ) | Represents the direction or correlation (in Taylor diagrams). |
Radius (r) | Represents the magnitude, often standard deviation. |
Center | Called the origin, where r = 0 . |
In a polar plot:
import matplotlib.pyplot as plt
import numpy as np
# Example angles (in degrees) and magnitudes
angles_deg = [0, 45, 90, 135, 180, 225, 270, 315]
magnitudes = [1, 2, 1.5, 3, 2.5, 2, 1, 1.8]
# Convert degrees to radians for polar plot
angles_rad = np.deg2rad(angles_deg)
# Create polar plot
plt.figure(figsize=(6, 6))
ax = plt.subplot(111, polar=True) # 111 means 1x1 grid, 1st plot
# Plot the data
ax.plot(angles_rad, magnitudes, marker='o')
# Add title
ax.set_title("Simple Polar Plot", va='bottom')
# Show the plot
plt.show()
angles_deg
: Compass directions like North (0Β°), East (90Β°), South (180Β°), etc.magnitudes
: Distance from the center for each direction.np.deg2rad()
: Converts degrees to radians since matplotlib
uses radians.polar=True
: Tells matplotlib to use polar coordinates.import matplotlib.pyplot as plt
import numpy as np
# Compass directions in degrees
angles_deg = [0, 45, 90, 135, 180, 225, 270, 315]
magnitudes = [1, 2, 1.5, 3, 2.5, 2, 1, 1.8]
# Convert degrees to radians
angles_rad = np.deg2rad(angles_deg)
# Repeat first point to close the circular shape
angles_rad = np.append(angles_rad, angles_rad[0])
magnitudes.append(magnitudes[0])
# Create plot
plt.figure(figsize=(7, 7))
ax = plt.subplot(111, polar=True)
# Plot line and fill area
ax.plot(angles_rad, magnitudes, color='teal', linewidth=2, label='Measurements')
ax.fill(angles_rad, magnitudes, color='skyblue', alpha=0.4)
# Set title and labels
ax.set_title("π Compass Polar Plot", va='bottom')
ax.set_xticks(np.deg2rad(angles_deg))
ax.set_xticklabels(['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'])
# Add legend
ax.legend(loc='upper right')
# Show plot
plt.show()
fill()
makes the plot visually intuitive and engaging.import matplotlib.pyplot as plt
import numpy as np
# Define sales regions and sales figures
regions = ['North', 'North-East', 'East', 'South-East', 'South', 'South-West', 'West', 'North-West']
sales = [120, 150, 130, 180, 160, 140, 110, 170]
# Convert region positions to angles (in radians)
angles = np.linspace(0, 2 * np.pi, len(regions), endpoint=False).tolist()
# Close the circular plot by repeating the first point
sales += [sales[0]]
angles += [angles[0]]
# Create polar plot
plt.figure(figsize=(8, 6))
ax = plt.subplot(111, polar=True)
# Plot the line and fill the area
ax.plot(angles, sales, color='navy', linewidth=2, label='Sales')
ax.fill(angles, sales, color='skyblue', alpha=0.4)
# Set region names around the circle
ax.set_xticks(angles[:-1]) # exclude last repeated angle
ax.set_xticklabels(regions)
# Title and legend
ax.set_title("π Sales Distribution by Region", pad=30)
ax.legend(loc='upper right')
# Show plot
plt.show()