Plotting data in real-time is a very useful task that could be tough, but using the tool KST, I will show how easy it is. The front end looks very professional and clean to present your project.
KST is a very powerful and robust solution for plotting live “streaming” data.
Why I chose KST?
- It is free and open source.
- You can control it with the user interface (with the mouse), but it is also fully scriptable with python (under linux).
- It is very powerful. In my project I visualize 22 realtime sensors at 15 Hz and it runs perfectly.
- it is cross-platform. I started using it on windows, but later move to Ubuntu and then RaspberryPi.
Let’s start!!!
How to plot data with Kst
1.First download KST. It is available to all the platforms: Windows, Mac and Linux. Follow the instructions from the website to complete the installation in your OS.
2. Execute the program. If you are using Windows, just unzip and go to folder /bin and open the executable file “kst2.exe”.
If you are using Linux, you have to call the following command to open the GUI:
kst2
Also is possible to call kst from a python script. For that use:
import subprocess .... subprocess.Popen[("kst2")] #open the real time plotter
If you want to open a saved kst configuration file, which has to be in the root folder:
import subprocess .... subprocess.Popen[("kst2", "myKSTfile.kst")] #open the real time plotter
3. Open the data wizard and go through. I will explain a standard configuration with these pictures.
4. First of all select the source file. This is usually a csv or a txt file. Then choose the time interval: “change detection” if you are working with local data. If you want to reproduce a saved file, which is not going to be updated, just select “no update“. Don´t forget to change the ASCII file configuration.
5. ASCII configuration. Here you modify the parameters to explain the program how to interpret the data from the file. This configuration depends on your file. Check the parameters I marked in red on the picture.
6. Select your data you want to plot. If your file has a header (normally on the first row) with the field names and you have selected previously “Read field names from line“, now you should see the names (like in the following picture). If not, you will see “column 1″, Column 2”, etc…
Kst always generates an automatic column called INDEX, which is the numbers 0, 1, 2, 3, 4, 5, 6… useful to use on the x-axis.
Put the columns you want to visualise on the right part and then go to the next step.
7. Data range. Usually, you want to plot real-time data, so you wish to see the last X samples available in your csv file. In this case select “count from end” and put the range between 200 and 500 depending on the speed you read the data. This can be changed later.
Put on the X-axis the INDEX column, if you don’t have a special column for the x-axis like time.
8. Layout configuration. I would leave this as default and later you can change what you like easily.
The only thing I regularly do is removing the legends of each plot. This makes a better view. legends only makes sense if you plot more than one curve per graph.
After pressing Finish, some view like this should appear:
Don’t forget to save the configuration if you are going to reuse this plot. A *.kst file is generated and you will save much time for the next time. If you are using linux, you can just run the command:
kst2 myKSTfile.kst #open your kst file and start plotting data
How to modify the visualisation?
KST allows to modify it “live”, very easy and with the mouse or you can use script commands. There are hundreds of possibilities.
Here I will mention some handy tips I consider relevant:
- For example to change the order of the graphs, just drag and drop and you will change the order. Then click on automatic to clean up and leave the layout more tidy.
- To change the Y scale of the axis and set it to a fix range. This is needed because it varies a lot when are set by auto. For this select a graph and pressing the key E (or by double click).
- Remember that if you want to change all the graphs with the same configuration just go to “Edit Multiple” on the top right part and select all.
- To modify the speed of the incoming data (scale the X axis) or how many last data do you visualize. For that click on the “Data Range” icon (on the next picture) and modify the “Range” as shown in the following pictures:
- Press ‘Z’ or right-click over a graph and select “Maximize plot” to see it in full-screen. Later you can press again ‘Z’ and everything will return to the normality.
KST let you modify many aspects of your visualisation front-end. Here I only mentioned a couple of tricks I find practical to start using this software.
samar
Thank you. Yes, it is an excellent tool that I have just rediscovered after not having used it for many years. Your introduction to it is very well done.
Alberto L.
Thanks Samar 🙂
amirul
Hi, Alberto. My name is Amirul Hidayat. I really love your passionate work of sharing information and knowledge in your blog. I am working on an analysis of networking performances and your work on KST tutorials really help me to display the outputs of the project. To be honest, I had a quite challenging task to operate with lack of resources and references. You were one of the few people that truly help me in this difficult period. Since I am a newbie in KST terms etc, it would be helpful if you can share your knowledge with me. I just want to ask a few questions to be clear of those unfamiliar KST interfaces. Thanks in advance Alberto.
Alberto L.
Hello Amirul,
I am happy that it was useful for you.
I am glad to share my knowledge with the community, this is the aim of this blog, to share content that scares…
I wrote all the useful tips about KST I consider valuables. Then if you wanna go digger, you can search and read the official documentation.
Best Regards!
Alberto
samar
One question: I am acquiring data at about 30 times per second with an SD of about 7 percent. The FFT displays seem to be not consistent with what I am getting in R and what I actually know to be the case. Could it be that KST2 assumes the rate of capture to be 1 Hz. If so what is a practical way for displaying the correct values in the KST window.
Alberto L.
Hello Samar,
As far as I know, I plot with KST faster than 1 Hz. I dont know what can be the problem…
I Regards
Alberto
Luberth Dijkman
Wow this is advanced
and runs well on rasspberry pi,
Wanted to view a second time logfile
safoora
Hi Alberto. appreciate for this tutorial.
in the last stage, my plots does not going forward and i cant see real time data.to see the updates in plot i must push “read to end” button again and again…?! I cant find what is wrong
Alberto L.
Yes, you have to say KST to actualize and read the file continuously. I get it to work. I don’t know how is with the new versions may it changes something.