Javaplot set grid

914 views Asked by At

I try to plot using JavaPlot a particular graph in a java project (I use eclipse).

Now, I create the module for plotting as follow:

public void createPlot(){
    JavaPlot p = new JavaPlot();
    p.set("key", "rmargin");
    p.set("key title","'OBJECTS INSIDE:'");
    p.set("size", "square");
    p.set("xlabel", "'x'");
    p.set("ylabel", "'y'");
    p.set("title", "'TITLE'");
    p.addPlot(positionData); 
    p.plot();   
}

And the program work very good but I like to put inside this plot some upgrading:

  1. I like to put inside the grid but if I write: p.set("grid"); I receive error;
  2. I like to change the pointsize and point-type of the plot.

I understand, for the moment, that using p.set("",""); I need to specify what to set (xlabel, ylabel, size...) and how to set (x,y,square...) but how about more complex commands such that in point 1. and 2. of this question?

1

There are 1 answers

2
user4815162342 On

To change the point size and point type of the plot, you can explicitly define a JavaPlot style. Point type is set as an integer, so you may have to guess and check to get what you are looking for (the shape represented by each integer is set by the terminal type; for example style 13 in a png terminal gives diamond points).

PlotStyle newStyle = new PlotStyle(Style.POINTS);
newStyle.setPointType(13);
newStyle.setPointSize(4);

Then you need to apply the style to your data object:

positionData.setPlotStyle(newStyle)

then finally the commands to initialize and edit your plot parameters:

JavaPlot p = new JavaPlot();
p.set("key", "rmargin");
p.set("key title","'OBJECTS INSIDE:'");
p.set("size", "square");
p.set("xlabel", "'x'");
p.set("ylabel", "'y'");
p.set("title", "'TITLE'");
p.addPlot(positionData); 
p.plot();  

http://javaplot.panayotis.com/doc/index.html

Hopefully someone else can explain how to display a grid; I'm interested in how to do that too.