A simple CSV importer/exporter with plotting capabilities with matplotlib
Project description
csv_manager
This is a python module that features two simple classes for reading (class Reader
) and plotting (class Plotter
), and a method for writing CSVs, using Matplotlib (Latex rendering enabled) for the plots.
By using this module, the user avoids the cumbersome repetition of coding a csv reader using the csv
python library then making the data in a readable structure for plt.plot(...)
.
An example is written in example/csv_plot_example.py
, that showcases what can be done with this module:
from csv_manager.plotter import Plotter
# Plotter inherits the class Reader
plotter = Plotter(num_rows=1, num_columns=2)
# Number of rows and columns for plt.sublots
file1 = 'data_file_1.csv'
file2 = 'data_file_2.csv'
plotter.load(file1, alias='dataset1')
plotter.load(file2, alias='dataset1')
#Both files are loaded in the same `dataset`, if column names collide, the latest ones get "_b" appended to their name
plotter.show_loaded_data()
# prints the loaded datasets. For each dataset, is printed:
# - the source files the data has been loaded from
# - the column names
plotter.get_column_names('dataset1')
# returns the list of column names of the dataset `dataset1`
######################################################
plotter.plot('dataset1', 'time', 'position', 0, 0, label='position $x(t)$', color='red', linestyle=':')
# Starting from " label='save' [...]" the arguments are the **kwargs in https://matplotlib.org/api/_as_gen/matplotlib.pyplot.plot.html
plotter.plot('dataset1', 'time', 'speed', 0, 0, label='speed $v(t)$', color='blue', linestyle='--')
plotter.plot('dataset1', 'time', 'position + sqrt(2/10 * speed)', 0, 1, label='dummy curve from expression')
plotter.plot_data(0, 0, [0, 1, 2], [0, 1, 2], label='dummy data')
plotter.set(0, 0, xlabel='Time ', ylabel='Position')
# Starting from " xlabel='time' [...]" the options that can be set are the **kwargs in https://matplotlib.org/api/axes_api.html
plotter.set(0, 1, xlabel='Time ', ylabel='Dummy data')
plotter.show()
The file example/data_file_1.csv
looks like the following:
time position
0 0
1 5
2 20
3 45
4 80
5 125
6 180
7 245
8 320
9 405
10 500
The file example/data_file_2.csv
looks like the following:
time speed
0 0
1 3
2 3.6
3 2
4 5
5 8
6 9
7 10
8 9.1
9 8
10 7
Dependencies:
- Python Matplotlib
- Python py_expression_eval, can be installed with
pip install py_expression_eval
- Latex distribution installed in your computer, can be deactivated in csv_plotter.py by changing the following line
plt.rcParams['text.usetex'] = True
toplt.rcParams['text.usetex'] = False
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for csv_manager-0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a34a9ad627c328d97871b37bdcb180f4648a447bb55f6387b92cc8cee9070d1d |
|
MD5 | 3f4faf99138832d11cba0629fe36c0ad |
|
BLAKE2b-256 | 3fe2a5579bf7006513b3ee17a0508d43b318812dad7356d7d95cade574627e00 |