POLAR_SCATTER
Excel Usage
=POLAR_SCATTER(data, title, plot_color, marker, point_size, legend)
data(list[list], required): Input data (Theta, R).title(str, optional, default: null): Chart title.plot_color(str, optional, default: null): Point color.marker(str, optional, default: “o”): Marker style.point_size(float, optional, default: 20): Size of points.legend(str, optional, default: “false”): Show legend.
Returns (object): Matplotlib Figure object (standard Python) or base64 encoded PNG string (Pyodide).
Examples
Example 1: Basic polar scatter spiral pattern
Inputs:
| data | |
|---|---|
| 0 | 1 |
| 0.785 | 1.5 |
| 1.571 | 2 |
| 2.356 | 2.5 |
| 3.142 | 3 |
Excel formula:
=POLAR_SCATTER({0,1;0.785,1.5;1.571,2;2.356,2.5;3.142,3})
Expected output:
"chart"
Example 2: Polar scatter with red color
Inputs:
| data | plot_color | |
|---|---|---|
| 0 | 1 | red |
| 1.571 | 2 | |
| 3.142 | 1.5 | |
| 4.712 | 2.5 |
Excel formula:
=POLAR_SCATTER({0,1;1.571,2;3.142,1.5;4.712,2.5}, "red")
Expected output:
"chart"
Example 3: Polar scatter with square markers
Inputs:
| data | marker | |
|---|---|---|
| 0 | 2 | s |
| 0.785 | 3 | |
| 1.571 | 2.5 | |
| 2.356 | 3.5 |
Excel formula:
=POLAR_SCATTER({0,2;0.785,3;1.571,2.5;2.356,3.5}, "s")
Expected output:
"chart"
Example 4: Polar scatter with title and legend
Inputs:
| data | title | legend | |
|---|---|---|---|
| 0 | 1 | Polar Scatter | true |
| 1.571 | 2 | ||
| 3.142 | 3 |
Excel formula:
=POLAR_SCATTER({0,1;1.571,2;3.142,3}, "Polar Scatter", "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 polar_scatter(data, title=None, plot_color=None, marker='o', point_size=20, legend='false'):
"""
Create a scatter plot in polar coordinates.
See: https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.scatter.html
This example function is provided as-is without any representation of accuracy.
Args:
data (list[list]): Input data (Theta, R).
title (str, optional): Chart title. Default is None.
plot_color (str, optional): Point color. Valid options: Blue, Green, Red, Cyan, Magenta, Yellow, Black, White. Default is None.
marker (str, optional): Marker style. Valid options: None, Point, Pixel, Circle, Square, Triangle Down, Triangle Up. Default is 'o'.
point_size (float, optional): Size of points. Default is 20.
legend (str, optional): Show legend. Valid options: True, False. Default is 'false'.
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"
# Extract theta and r columns
if len(data) < 1 or len(data[0]) < 2:
return "Error: Data must have at least 2 columns (Theta, R)"
theta = []
r = []
for row in data:
if len(row) >= 2:
try:
theta.append(float(row[0]))
r.append(float(row[1]))
except (TypeError, ValueError):
continue
if len(theta) == 0:
return "Error: No valid numeric data found"
# Create polar plot
fig = plt.figure(figsize=(8, 6))
ax = fig.add_subplot(111, projection='polar')
# Apply color if specified
scatter_kwargs = {'s': point_size}
if plot_color:
scatter_kwargs['color'] = plot_color
ax.scatter(theta, r, marker=marker, **scatter_kwargs)
if title:
ax.set_title(title)
if legend == "true":
ax.legend(['Data'])
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)}"