Skip to main content

xcsv-plot

xcsv-plot is a subpackage of xcsv. It's main purpose is to provide a simple CLI for plotting extended CSV (XCSV) files.

Install

The package can be installed from PyPI:

$ pip install xcsv-plot

Using the package

XCSV data can be plotted directly, as the data table is a pandas table:

content.data.plot(x='time (year) [a]', y='depth (m)')

and of course for more control over the plot, the data can be plotted using matplotlib, say.

But an XCSV file with an ACDD-compliant extended header section, and well-annotated column-headers, already provides much of the text needed to make an informative plot, so we can just plot the XCSV file directly from the command line. This is the purpose of the xcsv-plot subpackage. For example:

$ python3 -m xcsv.plot -x 0 -y 1 example.csv

Note here that we're calling xcsv-plot as a module main. As a convenience, this invocation is wrapped as a console script when installing the package, hence the following invocation is equivalent:

$ xcsv_plot -x 0 -y 1 example.csv

In addition to using the CLI, the package can be used as a Python library. The main class is Plot which provides methods to plot a given list of datasets (XCSV objects):

import xcsv
import xcsv.plot as xp

filenames = ['example1.csv','example2.csv','example3.csv']
datasets = []

for filename in filenames:
    with xcsv.File(filename) as f:
        datasets.append(f.read())

plotter = xp.Plot()
plotter.plot_datasets(datasets, xidx=0, yidx=1)

Command line usage

Calling the script with the --help option will show the following usage:

$ python3 -m xcsv.plot --help
usage: xcsv_plot [-h] [-x XIDX | -X XCOL] [-y YIDX | -Y YCOL]
                 [--x-label XLABEL] [--y-label YLABEL] [--invert-x-axis]
                 [--invert-y-axis] [--title TITLE] [--caption CAPTION]
                 [--label-key LABEL_KEY] [-s FIGSIZE FIGSIZE] [-b BG_IMG_PATH]
                 [-o OUT_FILE] [-P PLOT_OPTS] [-S] [-V]
                 in_file [in_file ...]

plot the given XCSV files

positional arguments:
  in_file               input XCSV file(s)

optional arguments:
  -h, --help            show this help message and exit
  -x XIDX, --x-idx XIDX
                        column index (zero-based) containing values for the
                        x-axis
  -X XCOL, --x-column XCOL
                        column label containing values for the x-axis
  -y YIDX, --y-idx YIDX
                        column index (zero-based) containing values for the
                        y-axis
  -Y YCOL, --y-column YCOL
                        column label containing values for the y-axis
  --x-label XLABEL      text to be used for the plot x-axis label
  --y-label YLABEL      text to be used for the plot y-axis label
  --invert-x-axis       invert the x-axis
  --invert-y-axis       invert the y-axis
  --title TITLE         text to be used for the plot title
  --caption CAPTION     text to be used for the plot caption
  --label-key LABEL_KEY
                        key of the header item in the extended header section
                        whose value will be used for the plot legend label
  -s FIGSIZE FIGSIZE, --figsize FIGSIZE FIGSIZE
                        size of the figure (width height)
  -b BG_IMG_PATH, --background-image BG_IMG_PATH
                        path to an image to show in the background of the plot
  -o OUT_FILE, --out-file OUT_FILE
                        output plot file
  -P PLOT_OPTS, --plot-options PLOT_OPTS
                        options for the plot, specified as a simple JSON
                        object
  -S, --scatter-plot    set plot options (see -P) to produce a scatter plot
  -V, --version         show program's version number and exit

Examples

Given an XCSV file with an ACDD-compliant extended header section, and a single column (at column 0) of data values:

# id: 1
# title: The title
depth (m)
0.575
1.125
2.225

Then the following invocation will plot the only column on the y-axis, with the x-axis the indices of the data points:

python3 -m xcsv.plot input.csv

If the file also contains a suitable variable for the x-axis:

# id: 1
# title: The title
time (year) [a],depth (m)
2012,0.575
2011,1.125
2010,2.225

then the columns to be used for the x- and y-axes can be specified thus:

python3 -m xcsv.plot -x 0 -y 1 input.csv

Metadata

Release files for xcsv-plot 0.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xcsv-plot 0.4.2
File Size Uploaded Provenance
xcsv_plot-0.4.2.tar.gz 11.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for xcsv-plot 0.4.2
File Interpreter ABI Platform
xcsv_plot-0.4.2-py3-none-any.whl Python 3 none any Details

Total release size: 24.2 kB

Release files / xcsv_plot-0.4.2.tar.gz

Download URL xcsv_plot-0.4.2.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a6c3c7f236e77e4542b4bc75e8837012f86223b3a0be5170be116e3a41f7f8c7
BLAKE2b-256 checksum
How to use checksums
cfe3c3604250a896e049acfe653717c922adcaf22588ccdb714368690156e752
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.2 CPython/3.8.10 Linux/5.15.0-91-generic

Release files / xcsv_plot-0.4.2-py3-none-any.whl

Download URL xcsv_plot-0.4.2-py3-none-any.whl
Size 12.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4ea599ea2a2c54e15ccf7325ce647013522b6f0fd682e3dbff4d70ca4fdb7a75
BLAKE2b-256 checksum
How to use checksums
617303b391a491a5e1b0a3fd3e63395696c88e261b757ae529f3ab5dbf91599f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.2 CPython/3.8.10 Linux/5.15.0-91-generic

Security for xcsv-plot 0.4.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page