//curve part ot the plot
$plot->SetXAxisPosition();
$plot->SetPlotType("lines");
$plot->SetDataValues($aCoords);
$plot->DrawGraph();
//a marking point to be placed on the curve
$pt1="points";
$dt1="text-data";
$plot->SetDataType($dt1);
$plot->SetPlotType($pt1);
$plot->SetDataValues($rr);
$plot->DrawGraph();
//Turn off X axis ticks and labels because they get in the way:
$plot->SetXTickLabelPos('none');
$plot->SetXTickPos('none');
$plot->PrintImage();
The "points" part of the plot places the point at the correct y-position, but the x position
is way off. The x position of the point is located near the y axis, but should be at the intersection between the curve and the horizontal gridline.
It seems that the point x-value does not coincide with the x-values already used for the parabolic curve.
As far as I understand it the point coordinates should be aligned according to the already given x points. I have also tried to mark the point with a vertical line projected on the x axis, and a horizontal line projected on the y axis. But the outcome of this is far from the intention.
I am new to this, so I have not discovered how to attach a print screen file of the plot.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It's hard for me to try your script, because I don't know what your data looks like. I do see that you have 2 data arrays, $aCoords and $rr, and you are not using SetPlotAreaWorld() to set the plot area data range for either overlay. In this case, PHPlot is supposed to automatically calculate a good range based on the data array for the first overlay, and then use the same range for the second - regardless of the second data array. Is this what you want?
If you could post something about your 2 data arrays (Y min and max should be enough, since X is implied), also $xmax, $xmin, and $npf, then I will try it.
One minor point is that the SetXTickLabelPos() and SetXTickPos() that you have at the end will do nothing, because they are after all the DrawGraph() calls, and the image has already been drawn. If you want them to have an effect, they need to be before DrawGraph().
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you kindly for the reply-
"In this case, PHPlot is supposed to automatically calculate a good range based on the data array for the first overlay, and then use the same range for the second - regardless of the second data array. Is this what you want?"
Yes, this is what I want, and I thought that PHPlot would use the same range for the second plot as for the first. The dataset is generated via a named pipe communication with a listening C-program which performs the calculations on request, and returns the result through the pipe.
The dataset:
$rr=2.487506 ,0.118421
$npf=38 $xmin= 1.23 $xmax= 4.93 $ymin=0.000857 $ymax=0.149295
$aCoords=39 (count)
x,y1,y2= 1.23,0.075076,0.075076
x,y1,y2= 1.33,0.087278,0.062875
x,y1,y2= 1.43,0.092332,0.05782
x,y1,y2= 1.53,0.096210,0.053942
x,y1,y2= 1.63,0.099479,0.050673
x,y1,y2= 1.73,0.102360,0.047793
x,y1,y2= 1.83,0.104964,0.045189
x,y1,y2= 1.93,0.107358,0.042794
x,y1,y2= 2.03,0.109587,0.040565
x,y1,y2= 2.13,0.111681,0.038471
x,y1,y2= 2.23,0.113661,0.036491
x,y1,y2= 2.33,0.115544,0.034608
x,y1,y2= 2.43,0.117344,0.032809
x,y1,y2= 2.49,0.118421,0.031731
x,y1,y2= 2.53,0.119069,0.031083
x,y1,y2= 2.63,0.120730,0.029422
x,y1,y2= 2.73,0.122333,0.02782
x,y1,y2= 2.83,0.123882,0.02627
x,y1,y2= 2.93,0.125384,0.024768
x,y1,y2= 3.03,0.126843,0.023309
x,y1,y2= 3.13,0.128261,0.021891
x,y1,y2= 3.23,0.129643,0.020509
x,y1,y2= 3.33,0.130991,0.019162
x,y1,y2= 3.43,0.132306,0.017846
x,y1,y2= 3.53,0.133593,0.01656
x,y1,y2= 3.63,0.134851,0.015301
x,y1,y2= 3.73,0.136084,0.014068
x,y1,y2= 3.83,0.137292,0.01286
x,y1,y2= 3.93,0.138477,0.011675
x,y1,y2= 4.03,0.139641,0.010512
x,y1,y2= 4.13,0.140783,0.009369
x,y1,y2= 4.23,0.141907,0.008245
x,y1,y2= 4.33,0.143011,0.007141
x,y1,y2= 4.43,0.144098,0.006054
x,y1,y2= 4.53,0.145169,0.004984
x,y1,y2= 4.63,0.146223,0.003929
x,y1,y2= 4.73,0.147261,0.002891
x,y1,y2= 4.83,0.148285,0.001867
x,y1,y2= 4.93,0.149295,0.000857
For each x value there are 2 y values, the curve is a stock portfolio frontier which is a parabola with its minimum point is pointing towards the y axis. (a horizontally oriented parabola) The upper part is the efficient part part of the frontier showing the risk/return relationship for the portfolio in question, based on different portfolio weights. The actual risk/return combination (based on the actual weights)is given in $rr
I seems that x=2.48 is plotted in the same x-point as 1.23, the minimum point. The y value of $rr is plotted correctly.
Take a look at the screenshot!
First, data arrays and data type. The data type tells PHPlot how to interpret the values in your data array. You are using 'text-data', which means each row of the array has a text label, then one or more Y values. There are no X values in this type of data array - they are implied as sequentially numbers. You've shown me X, Y1, Y2 values but not what a row in your data array looks like, but I'm guessing the first row is array(1.23, 0.075076, 0.075076). To PHPlot, that means a label of 1.23 (not X value), and 2 Y values. This would sort of work, because your X values are in fact steps of 1 apart, but I'm pretty sure it isn't what you want.
Try this: Fix your data array so there is an empty string at the start of each row, so they look like this: array('', 1.23, 0.075076, 0.075076). Change your second data array $rr in a similar way, so that its single row is in this form: $rr = array(array('',2.487506 ,0.118421));
Then change your data type ($dt and $dt1) to 'data-data'. You probably want to remove both SetXTickIncrement() calls - your calculated value is way too low, and 100 is too high. (Let PHPlot calculate the values at first, then if you don't like the way it comes out you can override it.)
One more thing: you need to avoid duplicating the X and Y axis labels, one for each overlay, especially X (because it will draw them at different positions). Do this by adding SetXTitle('') and SetYTitle('') after the first DrawGraph().
When I made the above changes, I got what you describe: a horizontal parabola with minimum towards Y, half green and half blue, and a point on along the upper arc.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks a lot, almost there.
I have added:
$plot->SetXTickPos('plotdown');
$plot->SetXDataLabelPos('plotdown');
$plot->SetXTickLabelPos('plotdown');
$plot->SetDrawXGrid(True);
The grid comes out nicely, as well as marking ticks on the x axis, but the x axis labels are too dense, so the numbers cannot be read separately - I am looking for a way to print out say every second or third number in order to make it possible to read.
I also wanted to clarify the graph by including projections from the point to the x and y axis, by drawing a vertical and horizontal line from the point and to the x and y axis respectively, but this code does not work, i.e. nothing is printed:
$proj_x=array(
array('',$co_x,0),
array('',$co_x,$co_y)
); //projection to the x axis
$proj_y=array(
array('',0,$co_y),
array('',$co_x,$co_y)
); //projection to the y axis
The $co_x and $co_y are the coordinates of the point, now plotted correctly.
There must be something wrong with the following code:
$plot->SetDataType("data-data");
$plot->SetPlotType("lines");
$plot->SetDataValues($proj_x);
$plot->DrawGraph(); //projection to the x axis
$plot->SetDataType("data-data");
$plot->SetPlotType("lines");
$plot->SetDataValues($proj_y);
$plot->DrawGraph(); //projection to the y axis
The other adjustmentsw you suggested work fine, I have enclosed a screendump to prove it.
Regarding the tick mark labels, yes, PHPlot will always label each tick mark. I suppose that could be a useful feature - to label only every Nth one - but there isn't a direct way to do that in PHPlot at this time.
So here are some options:
(1) Increase the X tick interval, which will spread out the tick marks and grid lines and reduce the label density.
(2) Turn the labels 90 degrees with SetXLabelAngle so they are vertical. You will have the same number of labels, but they might be readable.
(3) Set up a custom label formatting function with SetXLabelType('custom', ...). Your function will control the label density by returning either the formatted label, or an empty string. But it can be tricky, because the function has to decide based only on the label value (that is, you can't just skip 9 of 10 labels because they aren't necessarily generated in order).
I can give you an example of (3), custom label formatting function, if you want to try that.
(I'll look at the second part, projection to X and Y axis, soon.)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
By the way, I noticed that I had to turn the grids off (both X and Y) off after the first overlay, otherwise some of the grid lines look funny (because they are being drawn more than one time). See the Y=0.1 and Y=0.14 lines in your picture, for example. So I added SetDrawXGrid(False), SetDrawYGrid(False) after the first DrawGraph().
Regarding the projection lines, I inserted your new code into the script, after setting $co_x = $rr[0][1]; and $co_y = $rr[0][2]; and it worked fine. I got blue lines from the point to the X axis and Y axis.
Are you sure you added the new code in the right place (before PrintImage)?
By the way, you don't need 2 extra plots - one will do, something like this:
Yes, this works fine. I am grateful for good support.
One peculiar thing though: When setting LabelAngle to 90 (dregrees) the numbers along the x axis came out vertically, but with a lot of decimals. I did not quite understand that since the input values of x only have 2 decimals. (See screendump) I also tried 2 decimals for the y values, but that gave a stepwise (jagged, not smooth) parabola,
The printing format specifier in the C program is %f, giving 6 decimals as default. But this gives a smooth parabola.
Someting I am missing here?
Another puzzle:
At the outset I processed the input like this:
for($i=0;$i<=$npf;$i++){ //$npf number of records to be read, input ahead of // the stream
$inp=fgets($fifo); //read a record from named pipe $fifo
$co=explode(",",$inp); //separating x,y,y values into array $co
$aCoords[]=array('',$co[0],$co[1],$co[2]); //building parabola plot dataset
}
This resulted in only the upper half the parabola (blue) being plotted, the green part was not shown.
After some experimenting I did as follows:
$aCoords[]=array('',$co[0],$co[1],$co[2]*1);
In my opinion a somewhat crude method, but it lead me to believe that this maybe causes a casting operation. So I did as follows:
$aCoords[]=array('',$co[0],$co[1],(double)$co[2]);
- and that worked.
The $c0[0] and $co[1] works fine without any special treatment. I don't know why, but this does the trick.
The coordinates of the point $rr was also treated in a similar way:
if($tr=='V'){ //V= identifies variance (x value)
$co_x=(double)substr($inp,2); //casting into x coordinate
}
if($tr=='E'){ //E= identifies expected return (y value)
$co_y=(double)substr($inp,2); /casting into y corrdinate
}
The $rr:
$rr=array();
$rr[]=array('',$co_x,$co_y);
Your way of geting this off the ground was to invert this:
setting $co_x = $rr[0][1]; and $co_y = $rr[0][2];
putting $rr back into the co_. After casting this was not necessary.
I don't know if this is something that is related to PHP as such, or if it has to do with the properties of PHPlot.
Btw: My source of reading up on PHPlot is http://oeducador.com/phplot/phplot.pdf
and I suppose you are one of the authors. This works fine as a reference manual.
Do you also have some overview for dummies, some sort of introductory textbook giving an overall description of the PHPlot system ?
Lots of good questions. An easier one first, though. When reading your file, fgets() returns the next line including the newline at the end. When you explode() the result, the newline is including with the last value, co[2]. So it isn't a proper numeric value, so PHPlot ignores it. Hence no Y2. You found a fix, by forcing it to cast to numeric, but a cleaner fix would be to trim() the result from fgets(). This will strip leading and trailing whitespace.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Regarding the decimals in the X tick labels: I'm pretty sure this has nothing to do with rotating the labels. Perhaps you made some other change at the same time?
But it is important to note that with X tick labels, the X values will usually not correspond to the X values in your data array. By default, PHPlot-6.0 and higher will try to use "whole" or "natural" numbers for the X tick intervals. The values I see in your screen-shot are definitely not that. Unless you are using an older version of PHPlot (5.x), perhaps you are using SetXTickIncrement() with a calculated value for the tick step. Let's see... it looks like (3.7 / 39). Is that what you are doing? If so, PHPlot is using that value, and the default is producing a lot of decimals.
You can either change your tick increment, or use SetXLabelType('data', 2) to format the labels with 2 decimal digits, for example.
Yes I am the author of the phplot.pdf manual you linked to, although it contains some older content by those listed as co-authors. But that version you have is quite old, and does not cover any of PHPlot-6.x. On the PHPlot project page, you can find the latest version, both as PDF and HTML (along with a link to download the zipped up HTML release). The project page is at http://phplot.sourceforge.net/ (also http://www.phplot.com/ points to the same site).
The manual is all I've got, sorry. I tried to make it all-inclusive, from beginner to most advanced, with lots of examples, but it's a 1-person effort...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Bingo!
$inp=trim(fgets($fifo)); does the trick. I have a library of various C functions that I wrote some time ago where "readline(..)" takes care of the newlines. So old habit made me ignore this source of error. One should not rely on old habit in new territory. I am quite new to PHP, I have have for a long time wanted to take this on, and now I do.
You are quite right, the decimals has nothing to do with rotating the labels.
It has to do with this one:
$plot->SetXTickIncrement($ti);
By removing it everyting fell into place. You have pinpointed the problem exactly. See screendump. After the dump I tried to plot without rotating the labels, and now I get a clear picture of readable numbers printed horisontally. It was all the decimals that blurred the print.
phpinfo() shows that I run PHP Version 5.5.3-1ubuntu2.6
So I understand that I must upgrade.
If this manual is a 1 person effort, I'm impressed. This is not done during a one weekend session, I'm sure about that.
One final question for now: I have browsed through the Table of Contents in the manual that I presently have downloaded.
I was looking for the possibility of 3D plotting. Earlier I used GNUplot together with C, and GNUplot has this possibility. A bit cumbersome to use, but still. I want to study further the graphical results of the caharacteristic function of a proboalility distribution. and I then will need 3 dimensions, since it involves complex numbers.
Again, thanks a lot for excellent support, I did learn a lot from this.
Edit: In the includefile located in the includepath /usr/share/php/phplot.php, I discover:
PHPLOT Version 6.1.0
I guess I have the latest PHPlot after all. The version numbers of PHP and PHPlot must of course follow different paths.
phpinfo() shows that I run PHP Version 5.5.3-1ubuntu2.6
So I understand that I must upgrade.
This is your PHP version, and 5.5.x is fine as long as you are keeping up with the Ubuntu security updates. If not, the current PHP releases are 5.6.5, 5.5.21, and 5.4.37.
Never mind, I see that you found the PHPlot version: 6.1.0, which is the current release.
Unfortunately PHPlot has almost nothing in 3D plotting. The only tiny effort in that direction was the addition of the 'bubbles' plot type. While this does plot a function of 2 independent variables, the representation is 2D (plotting Z=f(X,Y) where Z maps to the diameter of the bubble), not 3D.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The following code only works in part:
$plot->SetTitle("Portfolio frontier ".$ipf);
$plot->SetXTitle('Variance');
$plot->SetYTitle('Return');
$ti=($xmax-$xmin)/($npf+1);
$plot->SetXTickIncrement($ti);
$dt="text-data";
$plot->SetDataType($dt);
$plot->SetXTickIncrement(100);
$plot->SetLineWidths(2);
$plot->SetPrintImage(False);
//curve part ot the plot
$plot->SetXAxisPosition();
$plot->SetPlotType("lines");
$plot->SetDataValues($aCoords);
$plot->DrawGraph();
//a marking point to be placed on the curve
$pt1="points";
$dt1="text-data";
$plot->SetDataType($dt1);
$plot->SetPlotType($pt1);
$plot->SetDataValues($rr);
$plot->DrawGraph();
//Turn off X axis ticks and labels because they get in the way:
$plot->SetXTickLabelPos('none');
$plot->SetXTickPos('none');
$plot->PrintImage();
The "points" part of the plot places the point at the correct y-position, but the x position
is way off. The x position of the point is located near the y axis, but should be at the intersection between the curve and the horizontal gridline.
It seems that the point x-value does not coincide with the x-values already used for the parabolic curve.
As far as I understand it the point coordinates should be aligned according to the already given x points. I have also tried to mark the point with a vertical line projected on the x axis, and a horizontal line projected on the y axis. But the outcome of this is far from the intention.
I am new to this, so I have not discovered how to attach a print screen file of the plot.
It's hard for me to try your script, because I don't know what your data looks like. I do see that you have 2 data arrays, $aCoords and $rr, and you are not using SetPlotAreaWorld() to set the plot area data range for either overlay. In this case, PHPlot is supposed to automatically calculate a good range based on the data array for the first overlay, and then use the same range for the second - regardless of the second data array. Is this what you want?
If you could post something about your 2 data arrays (Y min and max should be enough, since X is implied), also $xmax, $xmin, and $npf, then I will try it.
One minor point is that the SetXTickLabelPos() and SetXTickPos() that you have at the end will do nothing, because they are after all the DrawGraph() calls, and the image has already been drawn. If you want them to have an effect, they need to be before DrawGraph().
Thank you kindly for the reply-
"In this case, PHPlot is supposed to automatically calculate a good range based on the data array for the first overlay, and then use the same range for the second - regardless of the second data array. Is this what you want?"
Yes, this is what I want, and I thought that PHPlot would use the same range for the second plot as for the first. The dataset is generated via a named pipe communication with a listening C-program which performs the calculations on request, and returns the result through the pipe.
The dataset:
$rr=2.487506 ,0.118421
$npf=38 $xmin= 1.23 $xmax= 4.93 $ymin=0.000857 $ymax=0.149295
$aCoords=39 (count)
x,y1,y2= 1.23,0.075076,0.075076
x,y1,y2= 1.33,0.087278,0.062875
x,y1,y2= 1.43,0.092332,0.05782
x,y1,y2= 1.53,0.096210,0.053942
x,y1,y2= 1.63,0.099479,0.050673
x,y1,y2= 1.73,0.102360,0.047793
x,y1,y2= 1.83,0.104964,0.045189
x,y1,y2= 1.93,0.107358,0.042794
x,y1,y2= 2.03,0.109587,0.040565
x,y1,y2= 2.13,0.111681,0.038471
x,y1,y2= 2.23,0.113661,0.036491
x,y1,y2= 2.33,0.115544,0.034608
x,y1,y2= 2.43,0.117344,0.032809
x,y1,y2= 2.49,0.118421,0.031731
x,y1,y2= 2.53,0.119069,0.031083
x,y1,y2= 2.63,0.120730,0.029422
x,y1,y2= 2.73,0.122333,0.02782
x,y1,y2= 2.83,0.123882,0.02627
x,y1,y2= 2.93,0.125384,0.024768
x,y1,y2= 3.03,0.126843,0.023309
x,y1,y2= 3.13,0.128261,0.021891
x,y1,y2= 3.23,0.129643,0.020509
x,y1,y2= 3.33,0.130991,0.019162
x,y1,y2= 3.43,0.132306,0.017846
x,y1,y2= 3.53,0.133593,0.01656
x,y1,y2= 3.63,0.134851,0.015301
x,y1,y2= 3.73,0.136084,0.014068
x,y1,y2= 3.83,0.137292,0.01286
x,y1,y2= 3.93,0.138477,0.011675
x,y1,y2= 4.03,0.139641,0.010512
x,y1,y2= 4.13,0.140783,0.009369
x,y1,y2= 4.23,0.141907,0.008245
x,y1,y2= 4.33,0.143011,0.007141
x,y1,y2= 4.43,0.144098,0.006054
x,y1,y2= 4.53,0.145169,0.004984
x,y1,y2= 4.63,0.146223,0.003929
x,y1,y2= 4.73,0.147261,0.002891
x,y1,y2= 4.83,0.148285,0.001867
x,y1,y2= 4.93,0.149295,0.000857
For each x value there are 2 y values, the curve is a stock portfolio frontier which is a parabola with its minimum point is pointing towards the y axis. (a horizontally oriented parabola) The upper part is the efficient part part of the frontier showing the risk/return relationship for the portfolio in question, based on different portfolio weights. The actual risk/return combination (based on the actual weights)is given in $rr
I seems that x=2.48 is plotted in the same x-point as 1.23, the minimum point. The y value of $rr is plotted correctly.
Take a look at the screenshot!
Last edit: PARonning 2015-02-10
First, data arrays and data type. The data type tells PHPlot how to interpret the values in your data array. You are using 'text-data', which means each row of the array has a text label, then one or more Y values. There are no X values in this type of data array - they are implied as sequentially numbers. You've shown me X, Y1, Y2 values but not what a row in your data array looks like, but I'm guessing the first row is array(1.23, 0.075076, 0.075076). To PHPlot, that means a label of 1.23 (not X value), and 2 Y values. This would sort of work, because your X values are in fact steps of 1 apart, but I'm pretty sure it isn't what you want.
Try this: Fix your data array so there is an empty string at the start of each row, so they look like this: array('', 1.23, 0.075076, 0.075076). Change your second data array $rr in a similar way, so that its single row is in this form: $rr = array(array('',2.487506 ,0.118421));
Then change your data type ($dt and $dt1) to 'data-data'. You probably want to remove both SetXTickIncrement() calls - your calculated value is way too low, and 100 is too high. (Let PHPlot calculate the values at first, then if you don't like the way it comes out you can override it.)
One more thing: you need to avoid duplicating the X and Y axis labels, one for each overlay, especially X (because it will draw them at different positions). Do this by adding SetXTitle('') and SetYTitle('') after the first DrawGraph().
When I made the above changes, I got what you describe: a horizontal parabola with minimum towards Y, half green and half blue, and a point on along the upper arc.
Thanks a lot, almost there.
I have added:
$plot->SetXTickPos('plotdown');
$plot->SetXDataLabelPos('plotdown');
$plot->SetXTickLabelPos('plotdown');
$plot->SetDrawXGrid(True);
The grid comes out nicely, as well as marking ticks on the x axis, but the x axis labels are too dense, so the numbers cannot be read separately - I am looking for a way to print out say every second or third number in order to make it possible to read.
I also wanted to clarify the graph by including projections from the point to the x and y axis, by drawing a vertical and horizontal line from the point and to the x and y axis respectively, but this code does not work, i.e. nothing is printed:
$proj_x=array(
array('',$co_x,0),
array('',$co_x,$co_y)
); //projection to the x axis
$proj_y=array(
array('',0,$co_y),
array('',$co_x,$co_y)
); //projection to the y axis
The $co_x and $co_y are the coordinates of the point, now plotted correctly.
There must be something wrong with the following code:
$plot->SetDataType("data-data");
$plot->SetPlotType("lines");
$plot->SetDataValues($proj_x);
$plot->DrawGraph(); //projection to the x axis
$plot->SetDataType("data-data");
$plot->SetPlotType("lines");
$plot->SetDataValues($proj_y);
$plot->DrawGraph(); //projection to the y axis
The other adjustmentsw you suggested work fine, I have enclosed a screendump to prove it.
Last edit: PARonning 2015-02-11
Regarding the tick mark labels, yes, PHPlot will always label each tick mark. I suppose that could be a useful feature - to label only every Nth one - but there isn't a direct way to do that in PHPlot at this time.
So here are some options:
(1) Increase the X tick interval, which will spread out the tick marks and grid lines and reduce the label density.
(2) Turn the labels 90 degrees with SetXLabelAngle so they are vertical. You will have the same number of labels, but they might be readable.
(3) Set up a custom label formatting function with SetXLabelType('custom', ...). Your function will control the label density by returning either the formatted label, or an empty string. But it can be tricky, because the function has to decide based only on the label value (that is, you can't just skip 9 of 10 labels because they aren't necessarily generated in order).
I can give you an example of (3), custom label formatting function, if you want to try that.
(I'll look at the second part, projection to X and Y axis, soon.)
By the way, I noticed that I had to turn the grids off (both X and Y) off after the first overlay, otherwise some of the grid lines look funny (because they are being drawn more than one time). See the Y=0.1 and Y=0.14 lines in your picture, for example. So I added SetDrawXGrid(False), SetDrawYGrid(False) after the first DrawGraph().
Regarding the projection lines, I inserted your new code into the script, after setting $co_x = $rr[0][1]; and $co_y = $rr[0][2]; and it worked fine. I got blue lines from the point to the X axis and Y axis.
Are you sure you added the new code in the right place (before PrintImage)?
By the way, you don't need 2 extra plots - one will do, something like this:
Yes, this works fine. I am grateful for good support.
One peculiar thing though: When setting LabelAngle to 90 (dregrees) the numbers along the x axis came out vertically, but with a lot of decimals. I did not quite understand that since the input values of x only have 2 decimals. (See screendump) I also tried 2 decimals for the y values, but that gave a stepwise (jagged, not smooth) parabola,
The printing format specifier in the C program is %f, giving 6 decimals as default. But this gives a smooth parabola.
Someting I am missing here?
Another puzzle:
At the outset I processed the input like this:
for($i=0;$i<=$npf;$i++){ //$npf number of records to be read, input ahead of // the stream
$inp=fgets($fifo); //read a record from named pipe $fifo
$co=explode(",",$inp); //separating x,y,y values into array $co
$aCoords[]=array('',$co[0],$co[1],$co[2]); //building parabola plot dataset
}
This resulted in only the upper half the parabola (blue) being plotted, the green part was not shown.
After some experimenting I did as follows:
$aCoords[]=array('',$co[0],$co[1],$co[2]*1);
In my opinion a somewhat crude method, but it lead me to believe that this maybe causes a casting operation. So I did as follows:
$aCoords[]=array('',$co[0],$co[1],(double)$co[2]);
- and that worked.
The $c0[0] and $co[1] works fine without any special treatment. I don't know why, but this does the trick.
The coordinates of the point $rr was also treated in a similar way:
if($tr=='V'){ //V= identifies variance (x value)
$co_x=(double)substr($inp,2); //casting into x coordinate
}
if($tr=='E'){ //E= identifies expected return (y value)
$co_y=(double)substr($inp,2); /casting into y corrdinate
}
The $rr:
$rr=array();
$rr[]=array('',$co_x,$co_y);
Your way of geting this off the ground was to invert this:
setting $co_x = $rr[0][1]; and $co_y = $rr[0][2];
putting $rr back into the co_. After casting this was not necessary.
I don't know if this is something that is related to PHP as such, or if it has to do with the properties of PHPlot.
Btw: My source of reading up on PHPlot is http://oeducador.com/phplot/phplot.pdf
and I suppose you are one of the authors. This works fine as a reference manual.
Do you also have some overview for dummies, some sort of introductory textbook giving an overall description of the PHPlot system ?
Last edit: PARonning 2015-02-13
Lots of good questions. An easier one first, though. When reading your file, fgets() returns the next line including the newline at the end. When you explode() the result, the newline is including with the last value, co[2]. So it isn't a proper numeric value, so PHPlot ignores it. Hence no Y2. You found a fix, by forcing it to cast to numeric, but a cleaner fix would be to trim() the result from fgets(). This will strip leading and trailing whitespace.
Regarding the decimals in the X tick labels: I'm pretty sure this has nothing to do with rotating the labels. Perhaps you made some other change at the same time?
But it is important to note that with X tick labels, the X values will usually not correspond to the X values in your data array. By default, PHPlot-6.0 and higher will try to use "whole" or "natural" numbers for the X tick intervals. The values I see in your screen-shot are definitely not that. Unless you are using an older version of PHPlot (5.x), perhaps you are using SetXTickIncrement() with a calculated value for the tick step. Let's see... it looks like (3.7 / 39). Is that what you are doing? If so, PHPlot is using that value, and the default is producing a lot of decimals.
You can either change your tick increment, or use SetXLabelType('data', 2) to format the labels with 2 decimal digits, for example.
Yes I am the author of the phplot.pdf manual you linked to, although it contains some older content by those listed as co-authors. But that version you have is quite old, and does not cover any of PHPlot-6.x. On the PHPlot project page, you can find the latest version, both as PDF and HTML (along with a link to download the zipped up HTML release). The project page is at http://phplot.sourceforge.net/ (also http://www.phplot.com/ points to the same site).
The manual is all I've got, sorry. I tried to make it all-inclusive, from beginner to most advanced, with lots of examples, but it's a 1-person effort...
Bingo!
$inp=trim(fgets($fifo)); does the trick. I have a library of various C functions that I wrote some time ago where "readline(..)" takes care of the newlines. So old habit made me ignore this source of error. One should not rely on old habit in new territory. I am quite new to PHP, I have have for a long time wanted to take this on, and now I do.
You are quite right, the decimals has nothing to do with rotating the labels.
It has to do with this one:
$plot->SetXTickIncrement($ti);
By removing it everyting fell into place. You have pinpointed the problem exactly. See screendump. After the dump I tried to plot without rotating the labels, and now I get a clear picture of readable numbers printed horisontally. It was all the decimals that blurred the print.
phpinfo() shows that I run PHP Version 5.5.3-1ubuntu2.6
So I understand that I must upgrade.
If this manual is a 1 person effort, I'm impressed. This is not done during a one weekend session, I'm sure about that.
One final question for now: I have browsed through the Table of Contents in the manual that I presently have downloaded.
I was looking for the possibility of 3D plotting. Earlier I used GNUplot together with C, and GNUplot has this possibility. A bit cumbersome to use, but still. I want to study further the graphical results of the caharacteristic function of a proboalility distribution. and I then will need 3 dimensions, since it involves complex numbers.
Again, thanks a lot for excellent support, I did learn a lot from this.
Edit: In the includefile located in the includepath /usr/share/php/phplot.php, I discover:
PHPLOT Version 6.1.0
I guess I have the latest PHPlot after all. The version numbers of PHP and PHPlot must of course follow different paths.
Last edit: PARonning 2015-02-14
This is your PHP version, and 5.5.x is fine as long as you are keeping up with the Ubuntu security updates. If not, the current PHP releases are 5.6.5, 5.5.21, and 5.4.37.
Never mind, I see that you found the PHPlot version: 6.1.0, which is the current release.
Unfortunately PHPlot has almost nothing in 3D plotting. The only tiny effort in that direction was the addition of the 'bubbles' plot type. While this does plot a function of 2 independent variables, the representation is 2D (plotting Z=f(X,Y) where Z maps to the diameter of the bubble), not 3D.
OK I see. Is it an interesting challenge to add 3D capabilities to PHPlot,
or is it beyond the scope of this project?