一个简单的csv导入/导出器,具有matplotlib的绘图功能
csv-manager的Python项目详细描述
CSV_管理器
这是一个python模块,它有两个简单的类,分别用于使用python和matplotlib(启用乳胶渲染)读取(类Reader
)和绘制(类Plotter
)csv,避免了使用csv
python库编写csv读取器的繁琐重复,然后使数据在可读结构中用于plt.plot(...)
。示例用example/csv_plot_example.py
:
fromcsv_manager.plotterimportPlotterplotter=Plotter(num_rows=1,num_columns=2)file1='test_file.csv'plotter.load(file1,alias='test file')######################################################plotter.plot('test file','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.htmlplotter.plot('test file','time','10 * sqrt(2/10 * position)',0,1,label='speed $v(t)$')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.htmlplotter.set(0,1,xlabel='Time ',ylabel='Speed')plotter.show()
其中文件example/test_file.csv
如下所示:
time position 0 0 1 5 2 20 3 45 4 80 5 125 6 180 7 245 8 320 9 405 10 500
依赖关系:
- python matplotlib
- pythonpy_expression_eval,可以与
pip install py_expression_eval
一起安装
- 安装在计算机中的LaTex Distribution,可以通过将下面的行
plt.rcParams['text.usetex'] = True
更改为plt.rcParams['text.usetex'] = False
,在csv撸u plotter.py中停用