xyplot - Plot XY dataset(s) using gnuplot
This document describes version 0.006 of xyplot (from Perl distribution App-GnuplotUtils), released on 2023-10-21.
xyplot --help (or -h, -?)
xyplot --version (or -v)
xyplot [--chart-title=str] [(--dataset-data=str)+|--dataset-datas-json=json] [(--dataset-file=filename)+|--dataset-files-json=json] [(--dataset-style=str)+|--dataset-styles-json=json] [(--dataset-title=str)+|--dataset-titles-json=json] [--field-delimiter=str|-d=str] [--format=name|--json] [--(no)naked-res] [--output-file=filename|-o=filename] [--output-format=str] [--overwrite|-O|--no-overwrite|--nooverwrite] [--page-result[=program]|--view-result[=program]] -- [dataset_file] ...
This utility is a wrapper for gnuplot to quickly generate a graph from the command-line and view it using an image viewer program or a browser.
Specifying dataset
You can specify the dataset to plot directly from the command-line or specify filename to read the dataset from.
To plot directly from the command-line, specify comma-separated list of X & Y number pairs using --dataset-data option:
--dataset-data
% xyplot --dataset-data '1,1, 2,3, 3,5.5, 4,7.9, 6,11.5' ; # whitespaces are optional
To add more datasets, specify more --dataset-data options:
% xyplot --dataset-data '1,1, 2,3, 3,5.5, 4,7.9, 6,11.5' \ --dataset-data '1,4,2,4,3,2,4,9,5,3,6,6'; # will plot two lines
To add a title to your chart and every dataset, use --dataset-title:
--dataset-title
% xyplot --chart-title "my chart" \ --dataset-title "foo" --dataset-data '1,1, 2,3, 3,5.5, 4,7.9, 6,11.5' \ --dataset-title "bar" --dataset-data '1,4,2,4,3,2,4,9,5,3,6,6'
To specify dataset from files, use one or more --dataset-file options (or specify the filenames as arguments):
--dataset-file
% xyplot --dataset-file ds1.txt --dataset-file ds2.txt % xyplot ds1.txt ds2.txt
ds1.txt should contain comma, or whitespace-separated list of X & Y numbers. You can put one number per line or more.
ds1.txt
1 1 2 3 3 5.5 4 7.9 6 11.5 8 13.5 9 14.2 10 14.8
To accept data from stdin, you can specify - as the filename:
-
% tabulate-drug-concentration ... | xyplot -
Seeing plot result
xyplot uses Desktop::Open to view the resulting plot. The module will first find a suitable application, and failing that will use the web browser. If you specify --output-file (-o), the plot is written to the specified image file.
xyplot
--output-file
-o
To see in a viewer program or browser and set the image format:
% xyplot --output-format svg ...
If you want to use to force the browser:
% PERL_DESKTOP_OPEN_USE_BROWSER=1 xyplot ...
If you want to set the program to use to open:
% PERL_DESKTOP_OPEN_PROGRAM=google-chrome xyplot --output-format svg ...
Tips & Tricks
CSV format. If you have your data in CSV format, you can use csv-unquote to make sure your numbers are not quoted with double quotes, or you can use csv2tsv to convert your CSV to TSV first. Both utilities are included in App::CSVUtils.
Keywords
xychart, XY chart, XY plot
* marks required options.
*
(No description)
Dataset(s).
Can be specified multiple times.
Dataset(s) (JSON-encoded).
See --dataset-data.
Dataset(s) from file(s).
Can also be specified as the 1st command-line argument and onwards.
Dataset(s) from file(s) (JSON-encoded).
See --dataset-file.
Dataset plot style(s).
Dataset plot style(s) (JSON-encoded).
See --dataset-style.
--dataset-style
Dataset title(s).
Dataset title(s) (JSON-encoded).
See --dataset-title.
Supply field delimiter character in dataset file instead of the default whitespace(s) or comma(s).
Default value:
"png"
Valid values:
["bmp","gif","jpg","png","webp","pdf","ps","svg"]
The output format is normally determined from the output filename's extension, e.g. foo.jpg. This option is for when you do not specify output filename and want to change the format from the default png.
foo.jpg
png
Choose output format, e.g. json, text.
undef
Output can be displayed in multiple formats, and a suitable default format is chosen depending on the application and/or whether output destination is interactive terminal (i.e. whether output is piped). This option specifically chooses an output format.
Set output format to json.
When outputing as JSON, strip result envelope.
0
By default, when outputing as JSON, the full enveloped result is returned, e.g.:
[200,"OK",[1,2,3],{"func.extra"=>4}]
The reason is so you can get the status (1st element), status message (2nd element) as well as result metadata/extra result (4th element) instead of just the result (3rd element). However, sometimes you want just the result, e.g. when you want to pipe the result for more post-processing. In this case you can use --naked-res so you just get:
--naked-res
[1,2,3]
Filter output through a pager.
This option will pipe the output to a specified pager program. If pager program is not specified, a suitable default e.g. less is chosen.
less
View output using a viewer.
This option will first save the output to a temporary file, then open a viewer program to view the temporary file. If a viewer program is not chosen, a suitable default, e.g. the browser, is chosen.
Display help message and exit.
Display program's version and exit.
This script has shell tab completion capability with support for several shells.
To activate bash completion for this script, put:
complete -C xyplot xyplot
in your bash startup (e.g. ~/.bashrc). Your next shell session will then recognize tab completion for the command. Or, you can also directly execute the line above in your shell to activate immediately.
It is recommended, however, that you install modules using cpanm-shcompgen which can activate shell completion for scripts immediately.
To activate tcsh completion for this script, put:
complete xyplot 'p/*/`xyplot`/'
in your tcsh startup (e.g. ~/.tcshrc). Your next shell session will then recognize tab completion for the command. Or, you can also directly execute the line above in your shell to activate immediately.
It is also recommended to install shcompgen (see above).
For fish and zsh, install shcompgen as described above.
Please visit the project's homepage at https://metacpan.org/release/App-GnuplotUtils.
Source repository is at https://github.com/perlancar/perl-App-GnuplotUtils.
tchart. From App::tchart Perl module, to quickly create ASCII chart, currently sparklines.
asciichart. From App::AsciiChart Perl module, to quickly create ASCII chart.
perlancar <perlancar@cpan.org>
To contribute, you can send patches by email/via RT, or send pull requests on GitHub.
Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via:
% prove -l
If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, Pod::Weaver::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond that are considered a bug and can be reported to me.
This software is copyright (c) 2023, 2021, 2020, 2018 by perlancar <perlancar@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=App-GnuplotUtils
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
To install App::GnuplotUtils, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::GnuplotUtils
CPAN shell
perl -MCPAN -e shell install App::GnuplotUtils
For more information on module installation, please visit the detailed CPAN module installation guide.