Menu

Arbitrary lines showing on overlaid plots

Mark
2013-01-11
2013-01-11
  • Mark

    Mark - 2013-01-11

    Hi,

    I've successfully overlaid charts in the past, however it seems that with the following data set (included below) a random solid black line appears in the middle of the chart. I have encountered a solid black line before, but it was positioned at the top of the plot area and no reason for concern.

    My thoughts are that the left and right grid lines are lined up and solidifying in a solid black line, instead of the standard gray grid lines.

    Any ideas?

    <?php
    
    $array1 = array(array('', 21.367), array('', 18.595), array('', 19.423), array('', 22.066), array('', 22.112), array('', 23.806), array('', 23.075), array('', 27.569), array('', 28.97), array('', 29.948), array('', 29.133), array('', 29.15), array('', 27.616), array('', 26.58), array('', 27.573), array('', 23.991), array('', 23.977), array('', 19.626), array('', 16.224), array('', 12.634), array('', 13.273), array('', 9.696), array('', 11.224), array('', 11.224), array('', 9.863), array('', 9.704), array('', 9.714), array('', 9.136), array('', 9.587), array('', 12.175), array('', 11.972), array('', 12.456), array('', 10.384), array('', 18.054), array('', 17.184), array('', 17.312), array('', 17.428), array('', 18.177), array('', 18.336), array('', 17.366));
    $array2 = array(array('', 7.670), array('', 7.760), array('', 7.860), array('', 7.710), array('', 7.640), array('', 7.820), array('', 7.800), array('', 7.570), array('', 7.710), array('', 7.540), array('', 7.570), array('', 7.440), array('', 7.420), array('', 7.400), array('', 7.490), array('', 7.510), array('', 7.480), array('', 7.410), array('', 7.420), array('', 7.430), array('', 7.490), array('', 7.500), array('', 7.420), array('', 7.400), array('', 7.330), array('', 7.340), array('', 7.340), array('', 7.370), array('', 7.410), array('', 7.520), array('', 7.570), array('', 7.630), array('', 7.640), array('', 7.440), array('', 7.440), array('', 7.420), array('', 7.460), array('', 7.550), array('', 7.610), array('', 7.670));
    
    require_once("phplot.php");
    
    $plot = new PHPlot(600, 400);
    
    $plot->SetPrintImage(FALSE); 
    
    $plot->SetPlotAreaPixels(40, 40, 560, 360); 
    
    //Plot 1
    
    $plot->SetPlotType('lines');
    $plot->SetDataValues($array1);
    $plot->SetDataType('text-data');
    
    $plot->SetDataColors(array('red',"SkyBlue")); 
    $plot->SetLineWidths(2);
    
    $plot->SetDrawDashedGrid(FALSE); 
    
    $plot->SetYTickPos('none'); 
    $plot->SetYLabelType('data', 0); 
    
    $plot->SetYTitle("Sales ('000)", 'plotleft');
    
    $plot->SetLegendPosition(0, 0, 'image', 0, 0, 50, 40);
    $plot->SetLegend(array("Sales", "Temperature"));
    $plot->SetLegendStyle("left", "left"); 
    
    $plot->SetYTickIncrement(4); 
    
    $plot->DrawGraph();
    
    //Plot 2
    
    $plot->SetDrawPlotAreaBackground(FALSE);
    $plot->SetDrawYGrid(FALSE); 
    $plot->SetPlotAreaWorld(NULL); 
    
    $plot->SetPlotType('lines');
    $plot->SetDataValues($array2);
    $plot->SetDataType('text-data');
    
    $plot->SetDataColors(array('SkyBlue'));
    $plot->SetLineWidths(2);
    
    $plot->SetYTitle("Temperature (C)", 'plotright');
    $plot->SetYTickLabelPos('plotright'); 
    
    $plot->SetLegend(NULL); 
    
    $plot->SetYTickIncrement(1); 
    
    $plot->DrawGraph();
    
    $plot->PrintImage(); 
    ?>
    
     
  • lbayuk

    lbayuk - 2013-01-11

    To fix this, add the following call anywhere in the second plot setup, for example right after SetPlotAreaWorld(NULL):

    $plot->SetXAxisPosition('');
    

    That errant line you were seeing (and I admit this had me puzzled until I played around with it a bit) is the X axis line of the second plot. The X axis position was calculated at Y=8 for the first plot. It was drawn at the bottom, where it belongs, for the first plot. For the second plot, you told PHPlot to recalculate the World coordinate mapping, which it did, resulting in a Y range of 6 to 9. But without being explicitly told to recalculate the axis lines, PHPlot uses the same Y=8 from the first plot for the X axis line in the second plot, and now draws it at Y=8 according to the new (right-side) scale.

    Reference: http://phplot.sourceforge.net/phplotdocs/adv-multiplot.html#adv-multiplot-axis

     
  • Mark

    Mark - 2013-01-11

    Makes sense - thanks for quick reply!

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.