pyplotc is a Python tool for visualizing data files generated by C/C++ code using the fprintf
function. It supports plotting with either Gnuplot or Matplotlib, making it easy to analyze and visualize space-separated data logs from robotics and control applications.
- Automatic parsing of C/C++
fprintf
structure files to map data columns to variable names. - Flexible plotting: Select specific columns or groups of columns to plot, and organize them into multiple graphs.
- Supports Gnuplot and Matplotlib for visualization.
Install the required dependencies:
pip install py-gnuplot==1.3 matplotlib pandas pycparser
Plot two graphs: columns 3 & 17 in the first graph, and position_error
in the second graph:
python plot_data.py --structure_file=data_structure/example.txt --data_file=data/example.txt --target=3,17:position_error
--structure_file
: Path to the structure file describing the C/C++fprintf
format.--data_file
: Path to the space-separated data file to plot.--replacement_file
: (Optional) Path to the JSON file for macro/variable replacement in the structure file.--target
: (Optional) Comma-separated list of columns or variable names to plot. Use:
to separate different graphs.--start_frame
: (Optional) Start index of the frame to plot.--end_frame
: (Optional) End index of the frame to plot.--plot_tool
: (Optional) Choose'gnuplot'
or'matplotlib'
for plotting (default:gnuplot
).
When specifying targets using --target
, pyplotc automatically
-
trims pointer or object prefixes from structure file expressions to isolate the actual variable name and index.
Structure File Expression Parsed Target Argument curobo_command_ptr->JointPosCmd[i]
JointPosCmd
curobo_command_ptr.JointPosCmd[i]
JointPosCmd
This means you can simply use:
--target=JointPosCmd
-
maps column indices or variable names to their corresponding array expressions in the structure file.
--target=3
(if index 3 isset_velocity[3]
) will plot allset_velocity[i]
in the graph.--target=position_error
will plot allposition_error[i]
in the graph.
Structure files (in data_structure/
) describe how each line of your data file was written in C/C++. This allows the tool to map data columns to variable names automatically.
Each fprintf
statement must output values separated by spaces, so that the data file aligns correctly with the structure definition.
See the data_structure/example.txt
directory for example structure file.
The replacement.json
file is used to substitute macros or variables in your structure file. For example:
{
"NUM_JOINTS": 10
}
Data files contain space-separated numerical values logged from C/C++ programs using fprintf
. Each row typically represents one frame or time step, and each column — separated by a space — corresponds to a variable or array element defined in the structure file.
See the data/example.txt
directory for example data file.