Skip to main content

Tabplot: A wrapper over matplotlib for reading tabular (csv) text files.

Project description

tabplot

WORK IN PROGRESS

When working from the terminal, I'd need to quickly (and beautifully) plot the data in csv-style text files. This meant good colors, axis labels, plot labels, adjustable axis limits, etc. I started with making a simple wrapper script around matplotlib to do this. Over time, I kept adding pre- and post-processing functionality such as scaling, normalizing, and linear regression, not to mention exposing more of matplotlib's properties and functions. Since the script kept growing, I decided to move it into its own separate package.

Installation

You can install tabplot via testpypi

pip install git+https://github.com/jayghoshter/tabplot

Check out SciencePlots for added plot beautification.

Examples

Simple line plots

Assuming text data stored in csv-style files with the following assumptions:

  • No header labels
  • x,y data in columns 0,1 respectively
  • Either space or comma separated

The following code will generate basic plots. For customization options please refer to the examples section or test cases.

from tabplot import Plot
plot = Plot()
plot.files = ['./file_1.csv', './file_2.csv'],
plot.linewidths = 2,
plot.labels = ['A', 'B']
plot.read()
plot.draw()
plot.show()
plot.close()

or

from tabplot import Plot
Plot(
    files = ['./file_1.csv', './file_2.csv'],
    linewidths = 2,
    labels = ['A', 'B']
).read().draw().show().close()
  • Most used plot properties are exposed directly on the Plot object.
  • files, twinx, and labels can be specified on Plot or in the read() method
  • read() loads the data from the given files into .xs and .ys, which can be accessed and manipulated as wished.
  • setup() creates a .fig and .ax if not already done
  • draw() plots the lines etc. to the figure
  • save('file.pdf') will write to file.pdf
  • show() will display the plotted image

Bar plots

from tabplot import BarPlot
files = ['dummy.csv']
BarPlot(bar_width = 0.5).read(files).draw().save('dummy.pdf').close()
  • BarPlot is derived from Plot

Notes/Issues

  • Operator chaining is possible as seen above.
  • Currently only uses one subplot
  • Make sure to close the current plot with .close(). Unless garbage collected, plots may linger and calling .show() for some other object may also display a previous unclosed figure.
  • hlines/vlines must be called after all plots/fit_lines etc are done so that no further changes to xlims, ylims are effected later.
  • legends don't include hlines
  • preload-style can affect legend style even if not explicitly specified because we use setrc() in _update_params. So the default value overrides anything given in the style. While this is to be expected, the question is if this is user-friendly or not. Maybe a n otice is sufficient, that --preload-style can have this behavior.
    • [TASK] perhaps I can separate out the setrc_defaults() and call it at another time? Or only call it if the user has specified changes to the default values

Project details


Release history Release notifications | RSS feed

This version

0.2

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tabplot-0.2-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file tabplot-0.2-py3-none-any.whl.

File metadata

  • Download URL: tabplot-0.2-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for tabplot-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 242c4c2f4f3c03ea8cb79c6b07ee797e8ab7d0d07e0c224f5b7ada0f6c7660b5
MD5 2d2ba302645fb6a7448d0b7f9d2f067a
BLAKE2b-256 dd3732353d429bf3550bacb2b5303b399a8c548a0d1128fe25469dab457007a7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page