RADAR

Excel Usage

=RADAR(data, title, color_map, fill, alpha, legend)
  • data (list[list], required): Input data (Labels, Val1, Val2…).
  • title (str, optional, default: null): Chart title.
  • color_map (str, optional, default: “viridis”): Color map for series.
  • fill (str, optional, default: “true”): Fill the area.
  • alpha (float, optional, default: 0.25): Transparency.
  • legend (str, optional, default: “true”): Show legend.

Returns (object): Matplotlib Figure object (standard Python) or base64 encoded PNG string (Pyodide).

Examples

Example 1: Basic radar chart with one series

Inputs:

data
Speed 4
Power 3
Agility 5
Defense 2
Stamina 4

Excel formula:

=RADAR({"Speed",4;"Power",3;"Agility",5;"Defense",2;"Stamina",4})

Expected output:

"chart"

Example 2: Radar chart with multiple series

Inputs:

data
A 3 4
B 4 3
C 5 2
D 2 5
E 4 4

Excel formula:

=RADAR({"A",3,4;"B",4,3;"C",5,2;"D",2,5;"E",4,4})

Expected output:

"chart"

Example 3: Radar chart without fill

Inputs:

data fill
X 2 false
Y 4
Z 3
W 5

Excel formula:

=RADAR({"X",2;"Y",4;"Z",3;"W",5}, "false")

Expected output:

"chart"

Example 4: Radar chart with title and legend

Inputs:

data title legend
Cat1 3 5 Comparison true
Cat2 4 2
Cat3 5 4

Excel formula:

=RADAR({"Cat1",3,5;"Cat2",4,2;"Cat3",5,4}, "Comparison", "true")

Expected output:

"chart"

Python Code

import sys
import matplotlib
IS_PYODIDE = sys.platform == "emscripten"
if IS_PYODIDE:
    matplotlib.use('Agg')
import matplotlib.pyplot as plt
import io
import base64
import numpy as np

def radar(data, title=None, color_map='viridis', fill='true', alpha=0.25, legend='true'):
    """
    Create a radar (spider) chart.

    See: https://matplotlib.org/stable/gallery/specialty_plots/radar_chart.html

    This example function is provided as-is without any representation of accuracy.

    Args:
        data (list[list]): Input data (Labels, Val1, Val2...).
        title (str, optional): Chart title. Default is None.
        color_map (str, optional): Color map for series. Valid options: Viridis, Plasma, Inferno, Magma, Cividis. Default is 'viridis'.
        fill (str, optional): Fill the area. Valid options: True, False. Default is 'true'.
        alpha (float, optional): Transparency. Default is 0.25.
        legend (str, optional): Show legend. Valid options: True, False. Default is 'true'.

    Returns:
        object: Matplotlib Figure object (standard Python) or base64 encoded PNG string (Pyodide).
    """
    def to2d(x):
        return [[x]] if not isinstance(x, list) else x

    try:
        data = to2d(data)

        if not isinstance(data, list) or not all(isinstance(row, list) for row in data):
            return "Error: Invalid input - data must be a 2D list"

        # Transpose data: first column is labels, rest are series
        if len(data) < 1 or len(data[0]) < 2:
            return "Error: Data must have at least 2 columns (Labels, Values)"

        # Extract labels and values
        labels = []
        series = []
        num_series = len(data[0]) - 1

        for _ in range(num_series):
            series.append([])

        for row in data:
            if len(row) >= 2:
                # First column is label
                labels.append(str(row[0]))
                # Remaining columns are values for each series
                for i in range(num_series):
                    if i + 1 < len(row):
                        try:
                            series[i].append(float(row[i + 1]))
                        except (TypeError, ValueError):
                            series[i].append(0)
                    else:
                        series[i].append(0)

        if len(labels) == 0:
            return "Error: No valid data found"

        # Number of variables
        num_vars = len(labels)

        # Compute angle for each axis
        angles = np.linspace(0, 2 * np.pi, num_vars, endpoint=False).tolist()

        # Complete the circle
        angles += angles[:1]

        # Create radar plot
        fig = plt.figure(figsize=(8, 6))
        ax = fig.add_subplot(111, projection='polar')

        # Get colors from colormap
        cmap = plt.get_cmap(color_map)
        colors = cmap(np.linspace(0, 1, num_series))

        # Plot each series
        for i, values in enumerate(series):
            values_plot = values + values[:1]  # Complete the circle
            if fill == "true":
                ax.plot(angles, values_plot, 'o-', linewidth=2, color=colors[i], label=f"Series {i+1}")
                ax.fill(angles, values_plot, alpha=alpha, color=colors[i])
            else:
                ax.plot(angles, values_plot, 'o-', linewidth=2, color=colors[i], label=f"Series {i+1}")

        # Fix axis to go in the right order
        ax.set_xticks(angles[:-1])
        ax.set_xticklabels(labels)

        if title:
            ax.set_title(title)

        if legend == "true":
            ax.legend(loc='upper right', bbox_to_anchor=(1.3, 1.1))

        if IS_PYODIDE:
            buf = io.BytesIO()
            plt.savefig(buf, format='png', bbox_inches='tight')
            plt.close(fig)
            buf.seek(0)
            img_base64 = base64.b64encode(buf.read()).decode('utf-8')
            return f"data:image/png;base64,{img_base64}"
        else:
            return fig
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator