materials-science-figure-skill
by @grenzlinie
Use when the user wants to generate or edit images with Google's Nanobanana/Gemini image models using the official Gemini API shape, or when they need public...
clawhub install materials-science-figure-skillπ About This Skill
name: nanobanana-image-generation description: Use when the user wants to generate or edit images with Google's Nanobanana/Gemini image models using the official Gemini API shape, or when they need publication-style scientific figures rendered exactly from data with the bundled Python plotting tool. Prefer this skill for text-to-image, image-to-image editing, multi-image reference workflows, attachment-based recreations, exact bar/trend/heatmap/scatter plots, or when the user wants publication-style figures such as materials-science paper schematics. Use it when the user asks for a materials-science figure, journal-style scientific illustration, graphical abstract, mechanism diagram, device architecture, processing workflow, or paper-ready materials figure. metadata: {"openclaw":{"requires":{"anyBins":["python3","python"],"env":["NANOBANANA_API_KEY","NANOBANANA_BASE_URL"]},"primaryEnv":"NANOBANANA_API_KEY","homepage":"https://github.com/siyuliu/materials-science-figure-skill"}} disable-model-invocation: true
Nanobanana Image Generation
Overview
This skill now supports two modes:
image modegenerateContent flow
plot modeUse image mode for mechanism figures, graphical abstracts, device schematics, style-matched redraws, and diagram-first work.
Use plot mode for exact bar charts, trend curves, heatmaps, scatter plots, and multi-panel figures that must preserve numeric truth.
Runtime policy:
image and plot workflows.scripts/generate_image.js is an optional parity CLI for environments that already use Node.js, not the required runtime baseline for registry gating.When the user is working in Codex and describes a plot in natural language, do not require them to hand-write a JSON spec. Codex should translate the request into an internal plot request or spec and run the plotting scripts.
For image mode, follow Google's official examples and replace:
Do not use OpenAI-style /images/generations or /images/edits routes for this skill.
Attachment-Only Inputs
If the image exists only as a chat attachment and the platform does not expose a local file path, do not claim the script can upload it directly.
Use this rule:
1. If the user needs an exact edit of the original uploaded pixels, ask for the local file path first. 2. If the user accepts a close recreation, analyze the attached image visually and generate a new image that preserves the original composition and style as closely as possible.
For requests like "replace the English text in this attached image with Chinese", the fallback recreation workflow is acceptable when exact pixel-preserving edit is impossible.
Quick Start
Preflight:
plot mode is local-only and does not require API credentials or outbound network access.image mode sends prompt text, API credentials, and any --input-image files to the configured Gemini-compatible endpoint.--allow-third-party or NANOBANANA_ALLOW_THIRD_PARTY=1 and treat that as an explicit trust decision.Set environment variables:
export NANOBANANA_API_KEY="your-provider-key"
export NANOBANANA_BASE_URL="https://generativelanguage.googleapis.com"
export NANOBANANA_MODEL="gemini-3.1-flash-image-preview"
Optional third-party provider:
export NANOBANANA_BASE_URL="https://api.zhizengzeng.com/google"
export NANOBANANA_ALLOW_THIRD_PARTY=1
If you do not want the API key to appear in the command line, store it in a file and use:
export NANOBANANA_API_KEY_FILE="$PWD/.secrets/nanobanana_api_key"
Generate an image:
python3 scripts/generate_image.py "Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme"
Edit an image:
python3 scripts/generate_image.py "Using the provided image, change only the blue sofa to a vintage brown leather Chesterfield sofa. Keep everything else exactly the same." --input-image ./living-room.png
Recreate an attached diagram with translated labels:
python3 scripts/generate_image.py "Recreate the attached pastel technical diagram with the same layout, icons, arrows, and hand-drawn style. Replace all visible English labels with natural Simplified Chinese. Keep the composition unchanged." --aspect-ratio 16:9 --image-size 2K
Safety note:
scripts/build_materials_figure_prompt.py and --print-prompt are local-only and do not send data over the network.--allow-third-party or NANOBANANA_ALLOW_THIRD_PARTY=1.NANOBANANA_API_KEY_FILE over inline --api-key when you do not want the key to appear in shell history.Workflow
Choose a mode first:
1. If the user supplied numeric data and needs exact plotting, use plot mode.
Read references/publication-plot-api.md and run scripts/plot_publication_figure.py.
For natural-language requests, also read references/natural-language-plot-workflow.md.
2. If the user needs a schematic, graphical abstract, or image editing workflow, use image mode.
Follow the Gemini generateContent flow below.
For image mode:
1. Keep the official Gemini request shape.
Use POST /v1beta/models/{model}:generateContent with X-goog-api-key.
2. Put prompt text and image inputs into contents[].parts.
Text-only generation uses one text part. Image editing appends one or more inline image parts.
3. Put image options in generationConfig.imageConfig.
Prefer --aspect-ratio and --image-size, matching the official docs.
4. For materials-science figures, prefer building the final prompt first.
Use python3 scripts/build_materials_figure_prompt.py --materials-figure ... when you want to inspect or refine the prompt before sending any API request.
5. For publication-style research figures, load the bundled design guides as needed.
Read references/publication-figure-design.md for house style, palette semantics, typography, and panel logic.
6. If the figure contains chart-like panels, read references/publication-chart-patterns.md.
Use those patterns to specify grouped bars, heatmaps, trend layouts, dedicated legends, and wide comparison panels.
7. Save image outputs from candidates[0].content.parts[].inlineData.
Save text parts too when returned.
8. If the source image is attachment-only, choose between exact edit and recreation.
Ask for a local path for exact editing. Use recreation if the user wants the result and accepts a visually matched redraw.
For plot mode:
1. Read references/publication-plot-api.md.
2. If the user is speaking naturally, infer the plotting intent and data structure.
Do not ask the user to author the internal spec unless they explicitly want low-level control.
3. For concise internal translation, optionally create a request JSON and expand it with scripts/build_plot_spec.py.
4. Build or generate a JSON spec with top-level style, layout, and panels.
5. Use bar, trend, heatmap, scatter, legend, or empty panels.
6. Render with:
python3 skills/nanobanana-image-generation/scripts/plot_publication_figure.py spec.json
7. Export exact PNG, PDF, or SVG outputs.
Environment
Required:
NANOBANANA_API_KEYNANOBANANA_BASE_URLhttps://generativelanguage.googleapis.comOptional:
NANOBANANA_MODELgemini-3.1-flash-image-preview
NANOBANANA_TIMEOUT120
NANOBANANA_API_KEY_FILENANOBANANA_ALLOW_THIRD_PARTY1 only when you intentionally want to send API keys and user-provided files to a non-official Gemini-compatible provider.Scripts
scripts/generate_image.pygenerateContent request shape.
scripts/generate_image.jsscripts/plot_publication_figure.pyscripts/build_plot_spec.pyCommon options:
--input-image ./source.png--prompt-file ./background.md--aspect-ratio 16:9--image-size 2K--text-only--thinking-level high--include-thoughts--materials-figure mechanism-figure--lang zh--style-note "Nature Energy style"--print-prompt--allow-third-party--api-key-file ./.secrets/nanobanana_api_keyDefault output location:
./output/nanobanana/ relative to the current Codex working directoryDeterministic plotting:
python3 skills/nanobanana-image-generation/scripts/plot_publication_figure.py ./spec.json \
--out-path ./output/plots/result \
--formats png pdf svg \
--dpi 300
Natural-language-friendly internal workflow:
python3 skills/nanobanana-image-generation/scripts/build_plot_spec.py ./request.json --out ./spec.json
python3 skills/nanobanana-image-generation/scripts/plot_publication_figure.py ./spec.json
Official Mapping
Official Google examples:
api_key="GEMINI_API_KEY"base_url="https://generativelanguage.googleapis.com"Third-party provider replacements:
api_key="your_provider_api_key"base_url="your_google_compatible_endpoint"allow_third_party=trueOptional Zhizengzeng example:
api_key="your_zzz_api_key"base_url="https://api.zhizengzeng.com/google"allow_third_party=trueEverything else should stay aligned with the official Gemini documentation.
Prompting Rules
zh-CN prompts when image fidelity matters.Materials Science Figure Shortcut
If the user asks for a materials-science paper figure, journal-style scientific schematic, graphical abstract, mechanism diagram, synthesis workflow figure, microstructure-property diagram, device architecture figure, or characterization-plan figure, use the bundled materials-science templates instead of writing the prompt from scratch.
Workflow:
1. Read references/materials-science-figure-template.md.
2. Pick the closest subtype:
- graphical-abstract
- mechanism-figure
- device-architecture
- processing-workflow
3. Choose the output language:
- en
- zh
4. Insert the user's scientific content into the Scientific Background slot, or use the script shortcut directly.
5. Preserve the template's constraints about causality, palette, typography, layout, and avoiding unsupported claims.
6. If the user did not provide exact numbers, keep labels qualitative or explicitly use placeholders rather than fabricating data.
7. If the user wants a specific journal style, append that preference after the template rather than rewriting the template.
8. If the scientific background is long, put it in a markdown file and use --prompt-file or scripts/build_materials_figure_prompt.py --background-file ... instead of squeezing it into one shell argument.
9. For prompt refinement, consult:
- references/materials-science-figure-template.md
- references/publication-figure-design.md
- references/publication-chart-patterns.md
Research Figure Design Integration
This skill includes a distilled publication-figure playbook adapted from the figures4papers project. Use it to make Nanobanana outputs look like journal figures rather than generic AI art.
Read the reference files only as needed:
Apply these rules when prompting:
Quantitative Boundary
This skill is strong for:
This skill is not a guarantee of exact quantitative plotting. If the user needs exact bar heights, exact heatmap values, or faithful axis tick math from raw numbers, treat Nanobanana as a layout or visual-direction tool unless the request is explicitly a redraw from a trusted reference image.
For exact plotting, switch to plot mode and use references/publication-plot-api.md plus scripts/plot_publication_figure.py.
Python shortcut:
python3 scripts/generate_image.py "paste the scientific background here" \
--materials-figure mechanism-figure \
--lang en \
--style-note "Benchmark the figure against Nature Materials aesthetics." \
--aspect-ratio 4:3 \
--image-size 2K
JavaScript shortcut:
node scripts/generate_image.js "paste the scientific background here" \
--materials-figure graphical-abstract \
--lang zh \
--aspect-ratio 4:3 \
--image-size 2K
Prompt-only preflight:
python3 scripts/build_materials_figure_prompt.py \
--materials-figure mechanism-figure \
--lang en \
--background-file ./background.md \
--style-note "Nature Materials aesthetic with concise panel labels."
Failure Handling
401 or 403, verify NANOBANANA_API_KEY.NANOBANANA_BASE_URL or pass --base-url.--allow-third-party or set NANOBANANA_ALLOW_THIRD_PARTY=1 only if that provider is intentional.404, verify that the request is going to /v1beta/models/{model}:generateContent.candidates[0].content.parts and check whether the request asked for image output.References
figures4papers.π‘ Examples
Preflight:
plot mode is local-only and does not require API credentials or outbound network access.image mode sends prompt text, API credentials, and any --input-image files to the configured Gemini-compatible endpoint.--allow-third-party or NANOBANANA_ALLOW_THIRD_PARTY=1 and treat that as an explicit trust decision.Set environment variables:
export NANOBANANA_API_KEY="your-provider-key"
export NANOBANANA_BASE_URL="https://generativelanguage.googleapis.com"
export NANOBANANA_MODEL="gemini-3.1-flash-image-preview"
Optional third-party provider:
export NANOBANANA_BASE_URL="https://api.zhizengzeng.com/google"
export NANOBANANA_ALLOW_THIRD_PARTY=1
If you do not want the API key to appear in the command line, store it in a file and use:
export NANOBANANA_API_KEY_FILE="$PWD/.secrets/nanobanana_api_key"
Generate an image:
python3 scripts/generate_image.py "Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme"
Edit an image:
python3 scripts/generate_image.py "Using the provided image, change only the blue sofa to a vintage brown leather Chesterfield sofa. Keep everything else exactly the same." --input-image ./living-room.png
Recreate an attached diagram with translated labels:
python3 scripts/generate_image.py "Recreate the attached pastel technical diagram with the same layout, icons, arrows, and hand-drawn style. Replace all visible English labels with natural Simplified Chinese. Keep the composition unchanged." --aspect-ratio 16:9 --image-size 2K
Safety note:
scripts/build_materials_figure_prompt.py and --print-prompt are local-only and do not send data over the network.--allow-third-party or NANOBANANA_ALLOW_THIRD_PARTY=1.NANOBANANA_API_KEY_FILE over inline --api-key when you do not want the key to appear in shell history.