Skip to content

ruby889/pyplotc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pyplotc

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.

Features

  • 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.

Installation

Install the required dependencies:

pip install py-gnuplot==1.3 matplotlib pandas pycparser

Usage

Basic Example

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

Arguments

  • --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).

Target Argument Parsing

When specifying targets using --target, pyplotc automatically

  • trims pointer or object prefixes from structure file expressions to isolate the actual variable name and index.

    Examples
    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.

    Examples
    • --target=3 (if index 3 is set_velocity[3]) will plot all set_velocity[i] in the graph.
    • --target=position_error will plot all position_error[i] in the graph.

Data Structure Files

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.

Replacement File

The replacement.json file is used to substitute macros or variables in your structure file. For example:

{
    "NUM_JOINTS": 10
}

Data File

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.

About

Use python to plot c "fprintf" function

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages