polar_line
Create polar line plots from SQL queries on CSV or Parquet data sources. Visualize radial and angular coordinates with optional color coding for multi-dimensional analysis.
Instructions
Run query against specified source and make a polar line plot using result For both csv and parquet sources, use DuckDB SQL syntax Use 'CSV' as the table name in the SQL query for csv sources. Use 'PARQUET' as the table name in the SQL query for parquet sources.
This will return an image of the plot
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| source_id | Yes | The data source to run the query on | |
| query | Yes | SQL query to run on the data source | |
| r | Yes | Column name from SQL result to use as radial coordinate | |
| theta | Yes | Column name from SQL result to use as angular coordinate | |
| color | No | Optional; column name from SQL result to use for drawing multiple colored lines representing another dimension |
Implementation Reference
- zaturn/tools/visualizations.py:345-377 (handler)Handler function implementing the polar_line tool logic: executes SQL query on specified data source, generates polar line plot with Plotly Express (px.line_polar), converts to base64 PNG image, or returns error.def polar_line(self, source_id: Annotated[ str, Field(description='The data source to run the query on') ], query: Annotated[ str, Field(description='SQL query to run on the data source') ], r: Annotated[ str, Field(description='Column name from SQL result to use as radial coordinate') ], theta: Annotated[ str, Field(description='Column name from SQL result to use as angular coordinate') ], color: Annotated[ str | None, Field(description='Optional; column name from SQL result to use for drawing multiple colored lines representing another dimension') ] = None, ) -> str | ImageContent: """ Run query against specified source and make a polar line plot using result For both csv and parquet sources, use DuckDB SQL syntax Use 'CSV' as the table name in the SQL query for csv sources. Use 'PARQUET' as the table name in the SQL query for parquet sources. This will return an image of the plot """ try: df = self._get_df_from_source(source_id, query) fig = px.line_polar(df, r=r, theta=theta, color=color, line_close=True) return _fig_to_image(fig) except Exception as e: return str(e)
- zaturn/tools/visualizations.py:29-40 (registration)Registers the polar_line method by including it in the Visualizations class's self.tools list, which is aggregated into higher-level tool lists for MCP server registration.self.tools = [ self.scatter_plot, self.line_plot, self.histogram, self.strip_plot, self.box_plot, self.bar_plot, self.density_heatmap, self.polar_scatter, self.polar_line, ]
- zaturn/tools/visualizations.py:13-22 (helper)Helper function used by polar_line (and other plot tools) to convert Plotly figure to MCP ImageContent with base64-encoded PNG data.def _fig_to_image(fig): fig_encoded = b64encode(fig.to_image(format='png')).decode() img_b64 = "data:image/png;base64," + fig_encoded return ImageContent( type = 'image', data = fig_encoded, mimeType = 'image/png', annotations = None, )
- zaturn/tools/visualizations.py:43-49 (helper)Helper method used by polar_line to retrieve Pandas DataFrame from data source by executing the provided SQL query.def _get_df_from_source(self, source_id, query): source = self.data_sources.get(source_id) if not source: raise Exception(f"Source {source_id} Not Found") return query_utils.execute_query(source, query)