Menu

Displaying the Y inversed

Itamar
2010-12-07
2012-09-07
  • Itamar

    Itamar - 2010-12-07

    I have information that needs to be displayed where 1 is the top of the axis
    and everything higher than 1 is below (for example alexa rank) is it possible?

     
  • lbayuk

    lbayuk - 2010-12-07

    There is no direct way to do this. I can't even think of how it might be
    implemented, since so much depends on the axis direction. However, you can
    'simulate' it by (1) inverting and offsetting the data, and (2) using a custom
    Y label format function to display the 'fake' values. Here is a quick stand-
    alone example. Note: This forum isn't friendly for copying and pasting code
    (Sourceforge knows about it but has not chosen to do anything) - someday I
    will set something better up for this purpose. Sorry.

    <?php
    # Simulated inversion of Y axis
    require_once 'phplot.php';
    
    # The original data:
    $data = array(
      array('A', 3),
      array('B', 2),
      array('C', 1),
      array('D', 4),
      array('E', 8),
    );
    
    # Offset and invert the data:
    $offset = 11; // Must be bigger than all values
    foreach ($data as &$row) $row[1] = $offset - $row[1];
    unset($row); // See PHP manual on foreach with references
    
    $p = new PHPlot;
    $p->SetTitle('Invert Y axis');
    $p->SetDataType('text-data');
    $p->SetDataValues($data);
    $p->SetPlotType('bars');
    $p->SetXTickPos('none');
    $p->SetYLabelType('custom', create_function('$y', "return ($offset-\$y);"));
    $p->SetPlotAreaWorld(NULL, 0, NULL, $offset-1);
    
    $p->DrawGraph();
    
     

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.