I needed a way to visualize some values in real-time, so I started making a tiny module that is specialized to plot something in real-time.
I’m not plublishing a library yet, because it needs more work to have a truly nice API. I want to show it here so that people can give some fedback.
The main ideas are:
- initialize a plot, and put it in your model.
- use the draw function for plots in your
- push in new points from the right, and the drawing will update.
I intend to keep the configuration choices really minimal and specialized to a few use cases. For now, you can choose
- The maximum number of points that the plot keeps. This helps performance and indirectly defines the speed at which the plot scrolls by.
- The y-axis range: keep it within fixed bounds, or have the range change depending on your data.
- The x-axis behaviour: have a sliding window, or accumulate all the points forever, making the plot ‘shrink’ along that axis.
Let me know what you think. Personally it has already helped me so much to visualize what’s happening in the simulation that I’m working on (for example, I had a huge bug in calculating ‘potential energy’ in the simulation above, which I missed just looking at the numbers. The plot for ‘total energy’ made the bug completely obvious).
If you use it in your project, I would love to see it! You can just plop
TinyPlot.elm in your project and use it.