Menu

too many x axis lables.

2015-03-30
2015-03-30
  • PrakashGaonkar

    PrakashGaonkar - 2015-03-30

    I have about 240 data points (month ends as dates.) The X axis lables are crowded. I want to show only few may be 20. I have tried setnumXtics() and setXTickincrement(). It did not worked in my example below. X axis still same.

                $title = 'Weekly Chart of GDVM_Rank and Close for the Stock';
        $plot =& new PHPlot(1800,1000);
        $plot->SetImageBorderType('plain'); // For presentation in the manual
        $plot->SetPrintImage(False);  // Do not output the image
        $plot->SetTitle($title);
        $plot->SetPlotBgColor('gray');
        $plot->SetLightGridColor('black'); // So grid stands out from background
    
        $y_title1 = 'Weekly GDVM_Rank';
        $legend1 = array('Weekly Rank') ;
        $y_title2 = 'Weekly Close'  ;       
        $legend2 = array('Weekly Close');
    
                        $plot->SetDrawPlotAreaBackground(True);
            $plot->SetPlotType('stackedbars');
            $plot->SetDataType('text-data');
            $plot->SetDataValues($data1);
            $plot->SetYTitle($y_title1);
            $plot->SetXTitle(Date);
            # Set and position legend #1:
            $plot->SetLegend($legend1);
            $plot->SetLegendPixels(5, 30);
            # Set margins to leave room for plot 2 Y title on the right.
            $plot->SetMarginsPixels(120, 120);
            # Specify Y range of these data sets:
            //$plot->SetPlotAreaWorld(NULL, 0, NULL, 5000);
            $plot->SetPlotAreaWorld(NULL, 0, NULL, NULL);
            $plot->SetYTickIncrement();
            $plot->SetXLabelAngle(90);
            //$plot->SetXTickIncrement(100) ;
            $plot->SetNumXTicks(10);
            $plot->SetXTickLabelPos('none');
            $plot->SetXTickPos('none');
            $plot->SetXDataLabelPos('plotdown') ;
            $plot->SetDataColors('cyan');
            # Format Y tick labels as integers, with thousands separator:
            //$plot->SetYLabelType('data', 0);
            //$plot->TuneYAutoRange(10, 'Decimal');
            //$plot->SetYLabelType('data', 1);
            $plot->DrawGraph(); 
              echo "<img src=\"" . $plot->EncodeImage() . "\">\n";
    
     
  • lbayuk

    lbayuk - 2015-03-30

    I see you are displaying X axis data labels, not X tick labels. So changing the X tick increment or number of X ticks will not affect the labels. These are two different types of labels.

    The labels you are seeing along the X axis are in your data array ($data1[X][0] for each X). The only way to reduce the axis data label density is to clear out some of these labels from your data array (that is, replace them with empty strings). There is a sample function to do this in the PHPlot distribution: contrib/prune_labels.*

    There was a post recently on this forum ("Problems with multiple plot") where the issue of label density was also mentioned (tick labels, in that case). I took a quick look at adding a way to control this inside PHPlot, but there isn't a good place to do this. I'm not giving up on it, but will revisit it in the future.

     
  • PrakashGaonkar

    PrakashGaonkar - 2015-03-30

    yeah...it helped.

    require_once 'prune_labels.php';
    prune_labels($data1, 20);
    prune_labels($data2, 20);

     

Log in to post a comment.