I have a text-data plot and want to customize the ticks/labels on the X-axis. I was not able to find much on handling text ticks in the documentation. I want to have the ticks distributed evenly along the X-axis (the number of text items will be increasing), starting a X=0, based on the number of X items. XTickAnchor does not seem to apply to text data but I think I want the equivalent of setting it to 0. TIA.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
SetXTickAnchor is necessary due to how PHPlot assigns X values to your array when you don't specify them. Setting the X Tick Increment to 1 is not actually needed until you get to about 16 data points (where PHPlot would default to an increment of 2).
Using 'text-data' data type doesn't really fit with use of X axis tick labels. With 'text-data', you are telling PHPlot you don't care about the X values of your data - you just want them plotted at uniform intervals. X axis tick labels are meant to mark specific values on the X axis, which aren't meaningful with 'text-data'. You can, of course, use X axis data labels (the first value in each row of your data array) here.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for the reply. I'm not sure I understand all this but I'll give it a try. You are correct that I don't care what the X values are and that they should be at uniform intervals. It is where things are located that matter. For example suppose I have 3 data points. The 1st should be at X=0, the 2nd should be centered and the 3rd should be at the right end of the X-axis. In other words the end point should be at the extremes of the X- axis and the rest equally distributed between.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Your suggestion didn't work and actually did not change anything. I have 2 points at the moment. It is placing the first 1/3 along the X-Axis and the second 2/3 along the axis. What I need, as I said, with 2 points there should be one at each end of the axis.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
That's a different thing entirely. The 2 functions I used above change the X values where tick marks will be drawn. They have nothing to do with where the X values are positioned along the X axis line.
For that, you want to set the X range (the mapping between World Coordinates to Device Coordinates) with SetPlotAreaWorld(). The first argument is Xmin, which should be 0.5 for the first point when using text-data. The third argument is Xmax, which should be N-0.5 for N points. For example, if you have 3 data points, this will put the first and last on the left and right edges respectively, and the second in the middle:
$plot->SetPlotAreaWorld(0.5, NULL, 2.5);
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Works for me. Here is my test script. Set n=2 to get 2 data points per line. The points and tick marks are on the left and right edges of the plot. (Are you sure your count()==2?)
<?php# Forum 2015-08-19# Tick marks with text-data, vs number of pointsrequire_once'phplot.php';$n=2;// Number of X data points: change as wanted$data=array();for($i=0;$i<$n;$i++){$data[]=array("=$i=",$i,2*$i,3*$i,4*$i);}$plot=newPHPlot(800,800);$plot->SetLineStyles('solid');$plot->SetDataType('text-data');$plot->SetDataValues($data);$plot->SetPlotType('linepoints');$plot->SetXTickAnchor(0.5);$plot->SetXTickIncrement(1);$plot->SetPlotAreaWorld(0.5,NULL,count($data)-0.5);$plot->DrawGraph();
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hope you don't mind, but I put ~~~~ (4 tildes) around your code, to keep Markdown from eating parts of it. In answer to your P.S.: blank line and ~~~~ before the code, and ~~~~ after the code, is one way. Markdown will then leave it alone. (But it won't colorize it unless it starts with a PHP begin tag.)
Two things I noticed in your code. First, you are using $plotarray as your data array, but using a different array $finishes in SetPlotAreaWorld(). I can't tell if they are the same size, but I would definitely use count($plotarray) in SetPlotAreaWorld() just to make it clear.
The second thing is SetNumXTicks(). I would take it out, perhaps using the functions we talked about before - SetXTickIncrement and SetXTickAnchor. The problem is that using SetNumXTicks actually sets the number of intervals, not the number of ticks. Also using it overrides some of the other tick calculations.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have a text-data plot and want to customize the ticks/labels on the X-axis. I was not able to find much on handling text ticks in the documentation. I want to have the ticks distributed evenly along the X-axis (the number of text items will be increasing), starting a X=0, based on the number of X items. XTickAnchor does not seem to apply to text data but I think I want the equivalent of setting it to 0. TIA.
To use tick marks with 'text-data' data type, and have a mark below each data point, just include these:
SetXTickAnchor is necessary due to how PHPlot assigns X values to your array when you don't specify them. Setting the X Tick Increment to 1 is not actually needed until you get to about 16 data points (where PHPlot would default to an increment of 2).
Using 'text-data' data type doesn't really fit with use of X axis tick labels. With 'text-data', you are telling PHPlot you don't care about the X values of your data - you just want them plotted at uniform intervals. X axis tick labels are meant to mark specific values on the X axis, which aren't meaningful with 'text-data'. You can, of course, use X axis data labels (the first value in each row of your data array) here.
Thanks for the reply. I'm not sure I understand all this but I'll give it a try. You are correct that I don't care what the X values are and that they should be at uniform intervals. It is where things are located that matter. For example suppose I have 3 data points. The 1st should be at X=0, the 2nd should be centered and the 3rd should be at the right end of the X-axis. In other words the end point should be at the extremes of the X- axis and the rest equally distributed between.
Your suggestion didn't work and actually did not change anything. I have 2 points at the moment. It is placing the first 1/3 along the X-Axis and the second 2/3 along the axis. What I need, as I said, with 2 points there should be one at each end of the axis.
That's a different thing entirely. The 2 functions I used above change the X values where tick marks will be drawn. They have nothing to do with where the X values are positioned along the X axis line.
For that, you want to set the X range (the mapping between World Coordinates to Device Coordinates) with SetPlotAreaWorld(). The first argument is Xmin, which should be 0.5 for the first point when using text-data. The third argument is Xmax, which should be N-0.5 for N points. For example, if you have 3 data points, this will put the first and last on the left and right edges respectively, and the second in the middle:
Thanks again and I am getting closer but not quite there. That moved the first point to X=0 but the second point is now 1/3 along the axis.
$plot->SetPlotAreaWorld(.5,null,count($finishes)-.5);
count($finishes) returns 2.
Works for me. Here is my test script. Set n=2 to get 2 data points per line. The points and tick marks are on the left and right edges of the plot. (Are you sure your count()==2?)
Yes, I'm sure. There must be some other parameter I am using that is countering the setting. Here is my entire code:
P.S. What is the encoding for code? All I see is numbered lists and quote.
Last edit: lbayuk 2015-08-22
Hope you don't mind, but I put ~~~~ (4 tildes) around your code, to keep Markdown from eating parts of it. In answer to your P.S.: blank line and ~~~~ before the code, and ~~~~ after the code, is one way. Markdown will then leave it alone. (But it won't colorize it unless it starts with a PHP begin tag.)
Two things I noticed in your code. First, you are using $plotarray as your data array, but using a different array $finishes in SetPlotAreaWorld(). I can't tell if they are the same size, but I would definitely use count($plotarray) in SetPlotAreaWorld() just to make it clear.
The second thing is SetNumXTicks(). I would take it out, perhaps using the functions we talked about before - SetXTickIncrement and SetXTickAnchor. The problem is that using SetNumXTicks actually sets the number of intervals, not the number of ticks. Also using it overrides some of the other tick calculations.
Thanks. SetNumTicks was it. That should not have been there and it took new eyes to see it.