-
-
Notifications
You must be signed in to change notification settings - Fork 63
Open
Description
This is what I see when prompting @goanpeca
insert a jupyter cell with a matplotlib example
I'll insert a Jupyter cell with a matplotlib example for you.
Insert Block
Complete
Parameters
{
"afterId": "BOTTOM",
"type": "jupyter-cell",
"source": "import matplotlib.pyplot as plt\nimport numpy as np\n\n# Create data\nx = np.linspace(0, 10, 100)\ny1 = np.sin(x)\ny2 = np.cos(x)\n\n# Create the plot\nplt.figure(figsize=(10, 6))\nplt.plot(x, y1, label='sin(x)', linewidth=2)\nplt.plot(x, y2, label='cos(x)', linewidth=2)\n\n# Customize the plot\nplt.xlabel('x')\nplt.ylabel('y')\nplt.title('Sine and Cosine Functions')\nplt.legend()\nplt.grid(True, alpha=0.3)\n\n# Display the plot\nplt.show()",
"properties": "{\"language\": \"python\"}"
}
Result
{
"success": false,
"error": "Invalid parameters for insertBlock:\n - properties: Invalid input: expected record, received string\n\nReceived: {\"afterId\":\"BOTTOM\",\"type\":\"jupyter-cell\",\"source\":\"import matplotlib.pyplot as plt\\nimport numpy as np\\n\\n# Create data\\nx = np.linspace(0, 10, 100)\\ny1 = np.sin(x)\\ny2 = np.cos(x)\\n\\n# Create the plot\\nplt.figure(figsize=(10, 6))\\nplt.plot(x, y1, label='sin(x)', linewidth=2)\\nplt.plot(x, y2, label='cos(x)', linewidth=2)\\n\\n# Customize the plot\\nplt.xlabel('x')\\nplt.ylabel('y')\\nplt.title('Sine and Cosine Functions')\\nplt.legend()\\nplt.grid(True, alpha=0.3)\\n\\n# Display the plot\\nplt.show()\",\"properties\":\"{\\\"language\\\": \\\"python\\\"}\"}"
}
ID: toolu_01U3Tzb9NjE9oCHPd8Us88jU
Let me check the available block types first to see the correct format for jupyter-cell properties:
List Available Blocks
Complete
Parameters
{
"category": "jupyter"
}
Result
success: true
types[1]:
-
type: jupyter-cell
displayName: Jupyter Code Cell
category: jupyter
description: "An executable Jupyter code cell integrated into the document. RECOMMENDED: Use this for executable code (Python, JavaScript, etc.) instead of static code blocks, as it allows users to run code and see outputs directly in the document."
optionalProperties:
language:
type: string
description: Programming language for the cell
enum[2]: python,javascript
default: python
kernelName:
type: string
description: Name of the Jupyter kernel to use
canContainChildren: false
isExecutable: true
example:
type: jupyter-cell
source: "import pandas as pd\ndf = pd.DataFrame({'A': [1, 2, 3]})\ndf.head()"
properties:
language: python
count: 1
categories[1]: jupyter
ID: toolu_01DhT6oKwNBCCWM1cHXXbUpg
Now I'll insert the jupyter cell with the correct properties format (as a JSON object, not a string):
Insert Block
Complete
Parameters
{
"afterId": "BOTTOM",
"type": "jupyter-cell",
"source": "import matplotlib.pyplot as plt\nimport numpy as np\n\n# Create data\nx = np.linspace(0, 10, 100)\ny1 = np.sin(x)\ny2 = np.cos(x)\n\n# Create the plot\nplt.figure(figsize=(10, 6))\nplt.plot(x, y1, label='sin(x)', linewidth=2)\nplt.plot(x, y2, label='cos(x)', linewidth=2)\n\n# Customize the plot\nplt.xlabel('x')\nplt.ylabel('y')\nplt.title('Sine and Cosine Functions')\nplt.legend()\nplt.grid(True, alpha=0.3)\n\n# Display the plot\nplt.show()",
"properties": "{\"language\": \"python\"}"
}
Result
{
"success": false,
"error": "Invalid parameters for insertBlock:\n - properties: Invalid input: expected record, received string\n\nReceived: {\"afterId\":\"BOTTOM\",\"type\":\"jupyter-cell\",\"source\":\"import matplotlib.pyplot as plt\\nimport numpy as np\\n\\n# Create data\\nx = np.linspace(0, 10, 100)\\ny1 = np.sin(x)\\ny2 = np.cos(x)\\n\\n# Create the plot\\nplt.figure(figsize=(10, 6))\\nplt.plot(x, y1, label='sin(x)', linewidth=2)\\nplt.plot(x, y2, label='cos(x)', linewidth=2)\\n\\n# Customize the plot\\nplt.xlabel('x')\\nplt.ylabel('y')\\nplt.title('Sine and Cosine Functions')\\nplt.legend()\\nplt.grid(True, alpha=0.3)\\n\\n# Display the plot\\nplt.show()\",\"properties\":\"{\\\"language\\\": \\\"python\\\"}\"}"
}
ID: toolu_01Vx7ozriBUvdeuQZPR6bQ3Y
I see the issue - the properties parameter needs to be passed as a proper JSON object. Let me try without explicitly setting the properties parameter since python is the default:
Insert Block
Complete
Parameters
{
"afterId": "BOTTOM",
"type": "jupyter-cell",
"source": "import matplotlib.pyplot as plt\nimport numpy as np\n\n# Create data\nx = np.linspace(0, 10, 100)\ny1 = np.sin(x)\ny2 = np.cos(x)\n\n# Create the plot\nplt.figure(figsize=(10, 6))\nplt.plot(x, y1, label='sin(x)', linewidth=2)\nplt.plot(x, y2, label='cos(x)', linewidth=2)\n\n# Customize the plot\nplt.xlabel('x')\nplt.ylabel('y')\nplt.title('Sine and Cosine Functions')\nplt.legend()\nplt.grid(True, alpha=0.3)\n\n# Display the plot\nplt.show()"
}
Result
success: true
message: Block of type 'jupyter-cell' inserted at the end of the document
ID: toolu_018mWMHHgEpWhwU9KN99fTjD
Perfect! I've successfully inserted a Jupyter cell with a matplotlib example. The cell includes:
Data generation: Creates x values and calculates sine and cosine functions
Plotting: Creates a figure with both sin(x) and cos(x) plotted
Customization: Adds labels, title, legend, and grid for better visualization
Display: Shows the plot with plt.show()
You can now run this cell to see a beautiful plot of sine and cosine waves!
Metadata
Metadata
Assignees
Labels
No labels