Hi,
I have a project in C that runs real-time and uses gnuplot for real-time plotting. I want to replace gnuplot with plplot. I’ve written a test script (see below), but the only way I’ve been able to replot y data is to use plclear() and then redraw all the axes, labels, title, etc. Is there a cleaner way to just update the y data and replot rather than using wiping out everything with plclear? Any suggestions welcome, as I’m a newbie to plplot!! Thanks, Don
Hi,
I have a project in C that runs real-time and uses gnuplot for real-time plotting. I want to replace gnuplot with plplot. I’ve written a test script (see below), but the only way I’ve been able to replot y data is to use plclear() and then redraw all the axes, labels, title, etc. Is there a cleaner way to just update the y data and replot rather than using wiping out everything with plclear? Any suggestions welcome, as I’m a newbie to plplot!! Thanks, Don
//------------------------------------------------------------------------------
//
// gcc plplotLive1.c -o plplotLive1 -I/usr/include/plplot -lplplot -lm
// ./plplotLive1
//------------------------------------------------------------------------------
// Include libraries
include <plplot.h></plplot.h>
include <unistd.h> // for sleep()</unistd.h>
include <math.h></math.h>
include <stdio.h></stdio.h>
// Defined parameters
define PI 3.14159265358979323846
define AMP 1.0
define FREQ 1.0
define SRATE 100
define DUR 1.0
define TINT 2*PI/SRATE
// Main thread
int main() {
// Define sin wave data size
int nsamples = (int)(SRATE * DUR);
double xdata[nsamples];
double ydata[nsamples];
double time;
// Create a default sine wave from 0 to 2PI
for (int j=0; j<nsamples; j++) {
time = (double)(j) / SRATE;
ydata[j] = AMP * sin(2 * PI * FREQ * time);
xdata[j] = j * TINT;
}
// Declare plplot variables
PLFLT x[100], y[100];
PLCHAR_VECTOR afgi;
// Initialize PLplot
plsdev("xcairo"); // or any other suitable device
plspage(0,0,800,600,0,0); // Define size of fig
plinit();
plenv(0, 2*PI, -1.5, 1.5, 0, 0); // Set up the plot window
pllab(0, 0, "Live Plot Example");
// Set up colors
plscolbg(16,16,16);
//plcol0(15); // white
plcol0(1); // red
//plcol0(0); // black
//for (int i=0; i<400; i++) {
while(1) {
} // End of while
// End plotting
plspause(0); // Use this command to close plot window
plend(); // Tidy up plplot and end
// End of main
printf("Program complete.\n");
return 0;
} // End of main
Don
Don Kelly
LinkedIn: www.linkedin.com/in/kellydak