Visual Studio Code makes a comfortable gnuplot editor: install a Gnuplot syntax extension from the Marketplace for highlighting, add a small task to run the current script with one shortcut, and keep the integrated terminal open for interactive plotting. gnuplot itself must be installed separately first.
Step 0: Install gnuplot Itself
VS Code only edits and launches scripts — the gnuplot program does the plotting. If gnuplot --version does not work in a terminal yet, follow the guide for your system: Windows, macOS, or Linux.
Step 1: Add Gnuplot Language Support
- Open the Extensions view (
Ctrl+Shift+X). - Search the Marketplace for “gnuplot” and install an extension that provides gnuplot syntax highlighting (language support for .gp and .plt files). Several community extensions offer this; pick one whose description mentions gnuplot syntax highlighting and check its recent update history.
- Open any .gp script — keywords, comments, and strings should now be colourised and the language indicator in the status bar should read “gnuplot”.
Step 2: Add a Run Task
Create .vscode/tasks.json in your project folder with a task that runs the currently open script:
{
"version": "2.0.0",
"tasks": [
{
"label": "Run gnuplot script",
"type": "shell",
"command": "gnuplot",
"args": ["-p", "${file}"],
"problemMatcher": []
}
]
}
Run it with Terminal → Run Task → Run gnuplot script. The -p flag keeps the plot window open after the script finishes.
Step 3: Verify in the Integrated Terminal
gnuplot --version
gnuplot -p -e "plot sin(x)"
The first line confirms VS Code’s terminal sees the same gnuplot as your system terminal; the second should pop up a sine plot. Save scripts with set terminal pngcairo and set output blocks when you want files instead of windows.
Common Pitfalls
- Task fails with “gnuplot not found” but the system terminal works: VS Code was already running when gnuplot was installed and inherited the old PATH. Restart VS Code completely.
- Plot window closes instantly: the
-p(persist) flag is missing from the task arguments, or the script sets its own output file — both are fine, just check the generated PNG next to your script.
New to gnuplot itself? Start a script, then test commands interactively in the online terminal before wiring them into tasks.
Back up your plot scripts and data
Your .gp scripts and data files are small but hard to recreate. Keeping a synced backup means a reinstall never costs you your work. pCloud offers cloud storage with a one-time lifetime option and syncs a scripts folder across machines automatically. Affiliate link — see our Affiliate Disclosure.
