Menu

PHPlot Multiple Plots in one image

2016-05-02
2016-05-10
  • Manuel Müller

    Manuel Müller - 2016-05-02

    Hey guys :)

    maybe I found a bug in PHPlot or I'm too silly for using PHPlot the right way :D
    Here's the issue:

    I do a sql query which gives me a resultset. One of my own functions gives me a array in the right format for PHPlot (data-data). This query runs in a foreach loop. -> I want to draw multiple plots in one image.

    I tried like this:


     $plot = new PHPlot();
        //um mehrere plots zu bauen:
        $plot->SetPrintImage(False);
    
    
        # Need some different colors; <-- array of arrays because one colorset for every graph? 
        $colors = array(array('orange'), array('blue'), array('maroon'), array('red'), array('peru'),
            array('cyan'), array('black'), array('gold'), array('purple'), array('YellowGreen'),
            array('SkyBlue'), array('green'), array('SlateBlue'), array('navy'), array('aquamarine1'),
            array('violet'), array('salmon'), array('brown'), array('pink'), array('DimGrey'));
    
     $plot->SetDataColors($colors); //Setzen der Farbe
    
     foreach($block_id_array as $key => $bid)
    
        //foreach ($block_id_array as $bid) 
        {
    
            $query_inner = "SELECT Block_Column, Value FROM values WHERE Block_ID = '".$bid."'";
            $result_inner = $mydbcomm->GetFlatArrayFromQuery($query_inner);
    
            print_r($result_inner);
            echo "<br><br><br><br>";
    
            $leg = $checkedTemps_array[$key];
    
            $query_name = "SELECT Name FROM Mdm_block WHERE Block_ID = '".$bid."'";
            $result_name = $mydbcomm->GetFlatArrayFromQuery($query_inner);
    
            $name = $result_name[1]; //blöder Name. muss noch etwas besseres her
    
            $data = simpleplot_array($result_inner);
            print_r($data);
            echo "<br><br><br><br>";
    
    
            //Daten aus GET Variable holen:
    
            $title_x = $result_inner[0];
            $title_y = $result_inner[2];
    
            $plot->SetDataType('data-data'); //Formatierung der Eingangsdaten
            $plot->SetDataValues($data); //Übergabe der Daten
            $plot->SetDataColors($colors[$key]); //Setzen der Farbe
            $plot->SetLegend("Temp: ".$leg); // Legende Setzen <------ COLOR IS WRONG
    
    
    
            $plot->SetTitle("Name: ".$name);
            $plot->SetXTitle($title_x);
            $plot->SetYTitle($title_y);
    
            //$plot->SetPlotAreaWorld(NULL, 0, NULL, 0);
    
    
    
            $plot->DrawGraph();
        }
    
        $plot->PrintImage();
    }
    else{
        echo "Error";
    
    }
    

    Draw my plots works fine, but every object in the legend has the same color oO
    Thank you very much for your time and help!

    Greetings,

    Manuel Müller

     

    Last edit: Manuel Müller 2016-05-02
  • lbayuk

    lbayuk - 2016-05-03

    Let's back up a bit and see what you are trying to do with multi-plot.

    There are two main use-cases for multi-plot: tiled plots and overlay plots.

    With tiled plots, you are having PHPlot draw more than one complete plot (axis lines, data points, etc) on a single image, usually side-by-side or up-and-down or in a grid pattern. To do this, you use SetPlotAreaPixels() before each plot, in order to set its position in the image.

    Overlay plots are used to show more than one type or range of data on the same plot - for example, a bar chart overlayed with a line plot. To do this, you use SetPlotType() between plots, or perhaps some other function to change the range.

    In your code, you are using neither SetPlotAreaPixels(), nor changing the plot type or range, between the individual plots. So I don't see why you are using multiple-plots.

    For more information, see multiple plots per image in the manual.

    If instead you are just trying to draw multiple data sets on a plot - such as a number of lines of data, which use the same scale - then you do not need to use multiple plots. All you need is a single plot, with a data array containing all your data sets. This avoids the complexity and quirks of multi-plots.

     
  • Manuel Müller

    Manuel Müller - 2016-05-10

    Okay, thank you very much, I appreciate your help!
    I will try again with your tips...

     

Log in to post a comment.

MongoDB Logo MongoDB