This example shows the use of SetYTickAnchor to tell PHPlot that we want a tick mark and label at a specific value.
Example 5.37. Setting a Y Tick Anchor
First, here is the example without a Y tick anchor. Note that there is no Y tick mark or label at the X axis Y=0.
<?php # PHPlot Example: Using a Y tick anchor to force a tick at 0. # This requires PHPlot >= 5.4.0 require_once 'phplot.php'; # The variable $set_anchor can be set to a value in another script # which calls this script, to set the Y anchor to that value. if (isset($set_anchor)) $case = "with Y tick anchor at $set_anchor"; else $case = "without Y tick anchor"; # Function to plot: function f($x) { if ($x == 0) return 0; return 5 + 8 * sin(200 * M_PI / $x); } $data = array(); for ($x = 0; $x < 500; $x++) $data[] = array('', $x, f($x)); $plot = new PHPlot(800, 600); $plot->SetImageBorderType('plain'); // For presentation in the manual $plot->SetTitle("Example $case"); $plot->SetDataType('data-data'); $plot->SetDataValues($data); $plot->SetPlotType('lines'); $plot->SetXTickLabelPos('none'); $plot->SetXTickPos('none'); if (isset($set_anchor)) $plot->SetYTickAnchor($set_anchor); $plot->DrawGraph();
Using SetYTickAnchor(0) tells PHPlot to shift the Y tick marks and labels to place a tick mark at Y=0.
<?php # PHPlot Example: Using a Y tick anchor to force a tick at 0. # This sets a variable and calls the script directly above. $set_anchor = 0; require_once 'ytickanchor.php';