Skip to main content
Glama

mpl_mcp_plot_barchart

Create bar charts from numerical data using Matplotlib within Fermat MCP for mathematical visualization and analysis.

Instructions

Plots barchart of given datavalues

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
valuesYes
labelsNo
titleNo
xlabelNo
ylabelNo
colorNoskyblue
saveNo
dpiNo
orientationNovertical

Implementation Reference

  • The handler function that executes the barchart plotting logic using matplotlib, with type-annotated parameters serving as input schema.
    def plot_barchart( values: List[Union[float, int]], labels: Optional[List[str]] = None, title: str = "", xlabel: str = "", ylabel: str = "", color: str = "skyblue", save: bool = False, dpi: int = 200, orientation: Literal["vertical", "horizontal"] = "vertical", ) -> Image: """ Plot a bar chart (vertical or horizontal) with optional labels (defaults to empty strings). Args: values: List of bar heights (values: float or int) labels: List of bar labels (categories) or None for empty labels title: Plot title xlabel: Label for the x-axis ylabel: Label for the y-axis color: Color for the bars (default: "skyblue") save: If True, save the figure to a buffer dpi: Output image resolution (dots per inch, default: 100) orientation: "vertical" or "horizontal" (default: "vertical") Returns: FastMCP Image object with the plotted chart """ plt.figure(dpi=dpi) if labels is None: labels = [""] * len(values) if orientation == "vertical": plt.bar(labels, values, color=color) else: plt.barh(labels, values, color=color) plt.title(title) plt.xlabel(xlabel) plt.ylabel(ylabel) plt.xticks(rotation=45) plt.tight_layout() buf = io.BytesIO() plt.savefig(buf, format="png", dpi=dpi) plt.close() buf.seek(0) return Image(data=buf.read(), format="png")
  • Registers the plot_barchart handler as a tool in the FastMCP server named 'mpl_mcp', resulting in the tool name 'mpl_mcp_plot_barchart'.
    mpl_mcp.tool(plot_barchart, description="Plots barchart of given datavalues")
  • Imports the plot_barchart function into the server module for registration.
    from .core.bar_chart import plot_barchart

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/abhiphile/fermat-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server