You can build a PLplot example without relying on the bundled sample programs by writing your own minimal C source file, then compiling it against the installed PLplot libraries with the flags that plplot-config (or pkg-config) reports. The key condition is that the compiler must see both the PLplot headers and the link libraries, and the program must call plparseopts and plinit before any plotting call. Everything else—the page setup, the plot calls, the cleanup—you write yourself, which is exactly what makes it "without the sample."
This guide assumes PLplot is already installed on a Linux or Unix-like system (the same steps work on macOS with minor path differences, and on Windows under MSYS2 or a similar environment). It's written for someone comfortable with a terminal and a C compiler but new to linking PLplot directly.
What "without the sample" actually means
PLplot ships with a large set of example programs in its examples/ directory, organized by language (C, C++, Fortran, Python, and others). Those examples are useful references, but they come with a build system—typically CMake—that configures include paths, library names, and driver options for you. "Building without the sample" means skipping that scaffold: you write a source file in your own directory, invoke the compiler yourself, and link PLplot by hand.
There are two honest interpretations, and both are covered here. The first is that you don't want to compile or copy the shipped examples at all—you want your own minimal program. The second is that you want to understand the mechanics the sample build system hides, so you can drop PLplot into your own project. If you only ever run make inside the examples directory, you never see the link line, and that link line is the part that trips people up. Writing a five-line plot by hand surfaces it immediately.
One thing to be clear about up front: PLplot is a plotting library, not a framework. It draws lines, points, contours, 3D surfaces, and labels onto a "device" that can be a file format (PNG, PDF, SVG), an interactive window (the xwin driver), or a text terminal. It has no built-in notion of "a chart object" you configure declaratively; you issue imperative calls that move a pen. That style is why the API feels dated to some people and pleasantly direct to others.
Prerequisites and what to check before you start
Before writing code, confirm four things. Getting these wrong is the source of nearly every "it won't compile" or "it won't link" complaint.
First, the compiler. gcc --version should report something. On macOS, clang --version is fine; PLplot links against either.
Second, the headers. The public header is plplot.h, and a second header plstream.h exists for the C++ wrapper. Find where they live with plplot-config --includes or pkg-config --cflags plplot. A typical result is -I/usr/include/plplot or -I/usr/local/include/plplot. If the command returns nothing or errors, PLplot's development package isn't installed—on Debian/Ubuntu that's libplplot-dev, on Fedora it's plplot-devel, and on macOS with Homebrew it's plplot (the formula includes headers).
Third, the libraries. plplot-config --libs prints the link flags, something like -lplplot -lplplotcxx depending on build options, plus any dependencies. pkg-config --libs plplot gives the same information in pkg-config form. Note that some distributions split the C and C++ libraries, and the exact names vary with version and build configuration—this is precisely why you ask the installed tooling rather than memorizing a link line.
Fourth, a working device driver. plplot-config --drivers or plplot-config --dev lists compiled drivers. If you plan to write a PNG, you need a driver like png or cairo; if you only have xwin and pdf, those are what you can target. The list matters because a program that hardcodes png will fail at runtime on a build without it.
A quick sanity check that ties it together: run plplot-config --version and note the version. PLplot's API is fairly stable across the 5.x series, but a few functions and option behaviors have shifted, so knowing your version tells you which documentation applies.
Writing a minimal PLplot program
Here is the smallest complete program that produces a plot and exits cleanly. Type it into a file called myplot.c.
Walk through it. plparseopts consumes PLplot's own command-line options—things like -dev png and -o output.png—which is how you choose the device without recompiling. PL_PARSE_FULL is a flag that tells the parser to handle the full option set; passing the actual argc and argv is what lets -dev work from the shell. If you skip this call, you lose the ability to select a device on the command line, though you can still call plsdev in code.
plinit opens the output device. It must come before any drawing. plenv sets up a 2D coordinate system on the current page with the given world-coordinate ranges and axis flags; the first four arguments are x-min, x-max, y-min, y-max, and the two integers control axis boxing and tick style. plline draws a polyline through the points. plend closes the device and flushes output.
That's a genuinely minimal example. It draws a diagonal line from the lower-left to the upper-right of the plot box. Compile it with the flags the tooling reports:
The $(...) substitution inserts the include paths and link flags in one shot. If your distribution would rather you use pkg-config, the equivalent is:
Run it. With no arguments, PLplot picks a default device, which depends on your build—often an interactive one or a null device. To be explicit, name a device and an output file:
You should get line.png containing a boxed diagonal line. That's the success check: the file exists, opens in an image viewer, and shows the line. If the program runs but the file is empty or missing, the problem is almost always the device name or output path, not the code.
Understanding the compile and link line
The reason "without the sample" is worth learning is that the flags encode real information. Break plplot-config --cflags --libs apart conceptually.
The cflags portion is the include path, typically -I/include/plplot, because plplot.h sits in a plplot subdirectory rather than directly under include. If you omit it, the compiler errors with "plplot.h: No such file or directory," which is unambiguous and easy to fix.
The libs portion is the link line: library search paths (-L/lib) and the library itself (-lplplot), plus transitive dependencies PLplot needs. On a dynamic build these may include math and font libraries; the exact set is build-dependent. Link order matters: put the object or source file before the -l flags, because Unix linkers resolve symbols left to right. If you list -lplplot first and the source second, you can get "undefined reference to plinit" even though the library is present.
A subtle but common failure: mixing a static PLplot build with the flags for a dynamic one, or vice versa. If you have both installed, plplot-config should reflect the one it was configured for, but a hand-built prefix can confuse this. If you see errors about missing symbols that seem internal, check plplot-config --libs against what's actually in the library directory.
There's also a versioning detail on some systems: the library may install as libplplot.so with a versioned soname, and the linker handles that automatically. You don't need to name the version. The one exception is linking against a sibling library such as the C++ wrapper, libplplotcxx, which has its own flag—plplot-config will report it if you ask, or pkg-config exposes it as plplot-c++ on builds that provide it.
Choosing and controlling the output device
The device is PLplot's term for the backend. File-based devices write a finished artifact: png, pdf, svg, ps. Interactive devices open a window: xwin, tk, wxwidgets, depending on what was compiled. A mem device writes to memory, useful for embedding, and null discards output—handy when you want to test code paths without producing files.
You set the device three ways, in increasing order of convenience. In code, call plsdev("png") before plinit. On the command line, pass -dev png. Or set the environment variable PLPLOT_DEV if your build honors it. The command-line route is the most flexible because it doesn't require a rebuild to switch formats, which is why the minimal program parses options. To set the output file, use plsfnam("output.png") before plinit in code, or -o output.png from the shell.
Two practical notes. First, the device name is not the file extension; -dev svg -o chart.svg is correct, but -dev chart.svg will fail because there's no device by that name. Second, some devices accept sub-options, like page size or compression, passed via -dev syntax or an option string. These are driver-specific and documented in PLplot's device pages—check plplot-config --dev for what your build actually supports before relying on a sub-option.
A clean way to structure a program that may be run in different contexts is to let the command line win but provide a sane fallback:
In practice, PLplot doesn't expose a "was the device set" query in the minimal API, so the common pattern is to simply not call plsdev and let plparseopts fill it from -dev, falling back to however plinit resolves an unset device. If you need a guaranteed default, call plsdev with your preferred device before plparseopts, since command-line options typically override earlier programmatic settings when parsed. Verify the precedence on your installed version rather than assuming, because option handling has been refined across releases.
Expanding to a real plot with multiple calls
Once the minimal program runs, you build up by adding calls between plenv and plend. These are the ones you'll reach for most.
Labels and a title: pllab("x axis", "y axis", "Title") sets all three at once after plenv. For finer control, plmtex places text at a position relative to the viewport edges, and plbox draws a box with axis ticks and labels using format strings.
Data and points: plline draws a polyline; plpoin draws symbols at given coordinates, with plsym doing the same for a symbol code. plptex writes text at a data-coordinate point. For scattered data, plpoin with a large marker is the simple approach; for a scatter cloud you may also want plssym to set the symbol size once.
Multiple pages: after drawing a page, pladv(0) advances to the next page on multi-page devices like PDF or PostScript. Each page then gets its own plenv. Without pladv, subsequent plenv calls overwrite the current page's relationship—so if you want a multi-page document, call pladv between panels.
Colors: plcol0(n) selects from the current color map by index; plcol1(rgb) takes an RGB value. plscmap0 lets you redefine the palette itself. If colors look wrong or all identical, check whether you've selected a color before drawing—the default color is fine for a single-line plot but not for distinguishing series.
A representative multi-call section looks like this:
The mechanics you should internalize: drawing calls operate in the coordinate system established by plenv, colors and line styles persist until changed, and every page needs its own plenv before plotting. The success check is visual—two distinct colored curves with labeled axes.
Common build and runtime failures
These come up repeatedly, so match the symptom to the cause before changing code.
"plplot.h: No such file or directory." The include path is missing. Confirm plplot-config --cflags prints a -I path and that it's actually on your compile line. If you're using a build system, make sure the flags are passed to the compiler step, not just the linker.
"undefined reference to plinit" (or plparseopts, plenv). Two usual causes: the -lplplot flag is missing, or it appears before the source file on the command line. Move the -l flags to the end. If the flags are present and ordered correctly, confirm the library actually installs that symbol—nm -D on the library can show it, though most users won't need this probe.
It compiles and links but produces no file. The device didn't get set to a file-writing driver, or the output path wasn't given. Run with -dev png -o out.png explicitly. If it still fails, check plplot-config --dev for whether png is compiled in. A common trap: the program defaults to a device that produces nothing in a headless environment.
A blank or truncated file. The program exited or crashed before plend, which is what flushes and closes the device. Add error checks around your drawing calls, or run under a debugger. Also confirm the file isn't being read before the process finishes—if you cat or open it immediately from the same shell, timing can occasionally mislead, especially with buffered drivers.
Runtime error about an unknown device. The name doesn't match any compiled driver. List drivers and use an exact name. This is also what happens if you pass a filename to -dev.
It works on one machine but not another. The two machines have different PLplot builds: different drivers, different library layout, or different option behavior across versions. Ask plplot-config on each and compare. This is the strongest argument for using the tooling rather than a hand-copied flag string.
When the issue is clearly a library installation problem—missing headers after installing a package, or a linker that can't find the shared object at runtime despite a successful link—that's the point to consult your distribution's PLplot packaging or a system administrator, because at that stage you're resolving environment configuration, not PLplot usage.
Putting it in your own project
If you want this program inside a larger codebase rather than a one-off, the portable approach is to query pkg-config at configure time. In a Makefile, that looks like:
In CMake, find_package(PLplot) is sometimes provided by the installation's config files, but availability varies by build, so a robust fallback is to run pkg-config from CMake with execute_process and use the returned flags. Avoid hardcoding /usr/include/plplot and -lplplot in a project meant to travel; the prefix and library set differ across distributions and between system and Homebrew installs on macOS.
Keep your plotting code isolated in one translation unit if the rest of the project is large. PLplot's global state—current device, current color, current page—is process-wide, so if two parts of your program both call plenv and plend independently, the second will misbehave or close quietly. The practical pattern is a small wrapper: one function initializes the stream, a set of functions draw pages, and one function finalizes. That gives you the directness of the C API without leaking its implicit state everywhere.
Finally, note that the C++ wrapper uses its own header, plstream.h, whose type is plstream, and that a separate link flag applies. Don't include plstream.h in a pure C build. If you see "plstream.h: No such file" while writing C, the include is simply the wrong one.
How to verify and where to go next
The verification for a from-scratch build is straightforward and worth doing once methodically. Compile the minimal program with the reported flags and no code changes beyond what's shown. Run it with an explicit file-writing device and an output path. Open the artifact and confirm it contains the expected diagonal line inside a box. Then change one thing at a time—add a label, switch the device to pdf, change the color—and confirm each change appears. If a change doesn't appear, the problem is in that call or where you placed it relative to plenv and plend, not in the build.
From there, the natural next steps are contour plots (plcont), 3D surfaces (plsurf3d and the associated 3D setup calls), and custom palettes. Each has its own setup, and PLplot's reference documentation for the specific function is the reliable source for argument order, because the API is old-style and the parameter lists are long. Reading the header itself, plplot.h, is often faster than a tutorial—every function is declared with argument types, and the comments explain the less obvious ones.
The through-line for building without the sample is this: PLplot doesn't hide its link contract, it just delegates it to plplot-config and pkg-config. Once you've compiled one file by hand and watched a PNG appear, the sample build systems stop being magic. They're the same two facts—headers and libraries—wrapped in configuration. Your own program, written from the four calls plparseopts, plinit, plenv, and plend, is a complete PLplot application, and everything else is calls added between the last two.