0

I'm trying to display a spectogram using JavaPlot with this piece of code:

    PlotStyle style = new PlotStyle();
    style.setStyle(Style.IMAGE);


    DataSetPlot data = new DataSetPlot(points);
    data.setPlotStyle(style);


    JavaPlot plot = new JavaPlot();
    plot.addPlot(data);
    plot.plot();

Where the points are valid as they work when using gnuplot in the command line like this:

 gnuplot --persist -e 'plot "data.dat" w image'

The problem is that the above piece of code doesn't show any image at all, it is all white. However the previous command works fine, and data.dat contains the points in the exactly same format. No error appears when running the code.

Here is a example of some points data:

0.0 193.0 0.18183826861232413
0.0 194.0 0.2467637036800797
0.0 195.0 0.43531750893288235
0.0 196.0 0.3893599780473012
0.0 197.0 0.3220816458659573
0.0 198.0 0.25389713892289173
0.0 199.0 0.22935136709597423
1.0 0.0 0.23021155472288352
1.0 1.0 0.33383157107150707
1.0 2.0 0.3745792715533692
1.0 3.0 2.028348052193793
1.0 4.0 2.4150235476868978
1.0 5.0 2.4169194327766736
1.0 6.0 1.8633442057577019
1.0 7.0 4.2682342944471054
1.0 8.0 3.22544345282322

And this are the commands sended to gnuplot by JavaPlot:

set multiplot layout 1,2 rowsfirst downwards
_gnuplot_error = 1
plot '-' title 'Datafile 1' with image ; _gnuplot_error = 0
0.0 9.0 6.612583996900796 
1.0 9.0 4.719585678813712 
2.0 9.0 0.5475948495661151 
3.0 9.0 0.7385211622757041 
4.0 9.0 0.711512824841686 
5.0 9.0 3.7572382303712604 
6.0 9.0 1.0818137070547578 
7.0 9.0 0.057188125070687344 
8.0 9.0 0.8218555010675036 
9.0 9.0 5.754170136586405 
e
if (_gnuplot_error == 1) print '_ERROR_'
unset multiplot
quit

For this example I took 10x10 points, so the passed coordinates should be something like:

0.0 0.0 6.612583996900796 
0.0 1.0 4.719585678813712 
0.0 2.0 0.5475948495661151 
0.0 3.0 0.7385211622757041 
0.0 4.0 0.711512824841686 
0.0 5.0 3.7572382303712604 
0.0 6.0 1.0818137070547578 
0.0 7.0 0.057188125070687344 
0.0 8.0 0.8218555010675036 
0.0 9.0 5.754170136586405 
1.0 0.0 6.612583996900796 
1.0 1.0 4.719585678813712 
1.0 2.0 0.5475948495661151 
1.0 3.0 0.7385211622757041 
1.0 4.0 0.711512824841686 
1.0 5.0 3.7572382303712604 
1.0 6.0 1.0818137070547578 
1.0 7.0 0.057188125070687344 
1.0 8.0 0.8218555010675036 
1.0 9.0 5.754170136586405 
...
9.0 9.0 xxxxxxxxxxxxx

It seems that JavaPlot is not iterating the Y coordinates.

Does someone know what am I doing wrong?

3
  • Is there a way to check the JavaPlot pipe to see what commands gnuplot is actually seeing? Commented Jul 23, 2012 at 15:09
  • Not sure (I don't know java), however, it is definitely possible as it was done by another user: stackoverflow.com/q/11396616/748858 -- Perhaps rather than sending it to gnuplot.exe, send it to another program which reads from stdin and writes a temporary file... Commented Jul 23, 2012 at 15:18
  • Finally I got the output: set multiplot layout 1,2 rowsfirst downwards gnuplot_error = 1 plot '-' title 'Datafile 1' with image ; _gnuplot_error = 0 0.0 199.0 0.0 1.0 199.0 0.0 2.0 199.0 0.0 3.0 199.0 0.0 4.0 199.0 0.0 e if (_gnuplot_error == 1) print '_ERROR' unset multiplot quit Commented Jul 23, 2012 at 16:32

2 Answers 2

0

How big of a data set are you using?

Something I noticed when working with JavaPlot is that it really doesn't like large data sets. Its like there's a bug when JavaPlot talks to gnuplot and each time a data point is graphed, there's a small chance it'll flip out. Its not an issue with small amounts of data but makes graphing larger ones (> 1000) almost impossible. It looks a line is improperly entered and you end up with all lines after that one getting something like this:

multiplot> 53.86510713480712 67.8601980449745 53.557782725560635 
       ^
       invalid command

Try using a smaller set of data and see if it works. If this is the case, the only way I know to deal with it is to break apart your data set or to try using another wrapper library like jgnuplot--> http://jgnuplot.sourceforge.net/

Also, I notice you never say you're using a new graph. Try adding changing it to

JavaPlot plot = new JavaPlot();
plot.newGraph();  //added this line
plot.plot();
Sign up to request clarification or add additional context in comments.

4 Comments

so 40000? try with 40 and see if that works. If it does, try 400 and generate the graph several times. If you have the problem I did, it should work some times and fail (create white screens) the other times
try running it several times and if it still doesn't work, try just 5 points. If it still doesn't work, this isn't your problem
can you look at what gnuplot is being sent? A terminal should have popped up as well as the window. I see "warning: Image grid must be at least 2 x 2" on mine.
Sorry to say, I have no idea. I'll play around with it a little more but I don't have a lot of experience with gnuplot or JavaPlot. Hopefully someone else will be able to shed some light.
0

As I couldn't fix that error I finally decided to call gnuplot and pass the points correctly by myself. Here is the piece of code I've used to draw the spectogram:

Process p = Runtime.getRuntime().exec("gnuplot --persist");

BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
String s = "plot '-' title 'Spectogram' w image\n";
writer.write(s);
writer.flush();

for(int m = 0; m < x.length; m++){
   for(int k = 0; k < x[0].length; k++){
       s = m + " " + k + " " + x[m][k] + "\n";
       writer.write(s);  
       writer.flush();
   }
}

s = "e\n";
writer.write(s);
writer.flush();

And it works! :D

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.