Menu

Multiplots

Ingo
2010-04-06
2012-09-07
  • Ingo

    Ingo - 2010-04-06

    Hey guys,

    I am currenty working on a project using phplot for reporting purposes.

    To keep long things short, I need to display a dynamic number of companys each
    one in a single plot on the same page. So I have n plots, depending on how
    many companys are currently acitve.

    I worked all my way through and everything looks just fine. But than I noticed
    that there might be an issue while calculation the size of the total image. So
    I am facing two problems:

    • Eighter some text on the x-axis is getting cut or even some parts of the actuall plot
    • Or there is a lot of white space beneath the last plot. (So the overall plot size is to high)

    Jesus, I hope you get the point.... :-/

    I just found a work around and added some if-statements to determine how many
    plots I need to display and then I am correcting the hight of the image...
    What I found out is that the global size of the image needs to be reduced till
    I have at least 5 plots. After that is seams to be stabil. But I am not
    getting why??

    Here is my code for the global and plot size:

    if($num_getlfdfirmennr=='1') {
            $plot_y = $num_getlfdfirmennr * 350;
        }
        else if($num_getlfdfirmennr=='2') {
            $plot_y = $num_getlfdfirmennr * 320;
        }
        else if($num_getlfdfirmennr=='3') {
            $plot_y = $num_getlfdfirmennr * 310;
        }
        else if($num_getlfdfirmennr=='4') {
            $plot_y = $num_getlfdfirmennr * 305;
        }
        else {
            $plot_y = $num_getlfdfirmennr * 300;
        }
        $plot = new PHPlot(950, $plot_y);
    
    /***** PLOT POSITION *****/
            $xStart = 60; $yStart = 75; $xEnd = 930; $yEnd = 325;
    /***** END - PLOT POSITION *****/
    
    // Disable auto-output:
    $plot->SetPrintImage(0);
    
    for($y=1;$y<=$num_getlfdfirmennr;$y++) {
        // BUILD PLOTS
        # Set up area for first plot:
        //$plot->SetPlotAreaPixels(60, 70, 930, 350);
    
        if($y==1) {
            $plot->SetPlotAreaPixels($xStart, $yStart, $xEnd, $yEnd);
        }
        else { -> This is the distance between the plots while having more than one plot to be generated
            $xStart = 60; $yStart = $yEnd+40; $xEnd = 930; $yEnd = $yEnd+290;
            $plot->SetPlotAreaPixels($xStart, $yStart, $xEnd, $yEnd);       
        }
    

    I really hope anyone knews about this or maybe there is a little bug in the
    calculation itself... I don't know...

    I know it is very hard to understand what I am trying to say but I can explain
    it in more detail if you want/need or also give you a link to a website.

    Thank you so much for you time!

    Ingo

     
  • Ingo

    Ingo - 2010-04-06

    Sorry, it seams I messed up with the code tag... again:

        if($num_getlfdfirmennr=='1') {
            $plot_y = $num_getlfdfirmennr * 350;
        }
        else if($num_getlfdfirmennr=='2') {
            $plot_y = $num_getlfdfirmennr * 320;
        }
        else if($num_getlfdfirmennr=='3') {
            $plot_y = $num_getlfdfirmennr * 310;
        }
        else if($num_getlfdfirmennr=='4') {
            $plot_y = $num_getlfdfirmennr * 305;
        }
        else {
            $plot_y = $num_getlfdfirmennr * 300;
        }
        $plot = new PHPlot(950, $plot_y);
    
    /***** POSITIONIERUNG DER DIAGRAMME *****/
            $xStart = 60; $yStart = 75; $xEnd = 930; $yEnd = 325;
    /***** POSITIONIERUNG DER DIAGRAMME *****/
    
    // Disable auto-output:
    $plot->SetPrintImage(0);
    
    for($y=1;$y<=$num_getlfdfirmennr;$y++) {
        // DIAGRAMME AUFBAUEN
        # Set up area for first plot:
        //$plot->SetPlotAreaPixels(60, 70, 930, 350);
    
        if($y==1) {
            $plot->SetPlotAreaPixels($xStart, $yStart, $xEnd, $yEnd);
        }
        else {
            $xStart = 60; $yStart = $yEnd+40; $xEnd = 930; $yEnd = $yEnd+290;
            $plot->SetPlotAreaPixels($xStart, $yStart, $xEnd, $yEnd);       
        }
    
     
  • lbayuk

    lbayuk - 2010-04-06

    I'm pretty sure you just have a small error in calculating the size and plot
    area. It's hard to tell because (I think) you posted a version that you fixed
    up to work, rather than the one that doesn't work. But if I take out the IF
    statements and just leave

     $plot_y = $num_getlfdfirmennr * 300;
    

    for all the cases, then I see that the image grows 300 pixels for each new
    plot, but the plot area (SetPlotAreaPixels) only grows by 290 for each plot
    ($yEnd += 290). So it will start squishing out your plots and leave a lot of
    empty space at the bottom.

    Remember that the plot area is smaller than the image size, but the Y limits
    of the plot area must still increase by the same amount as the image grows.

    This older thread might help too: https://sourceforge.net/projects/phplot/for
    ums/forum/46382/topic/1827868

     
  • lbayuk

    lbayuk - 2010-04-06

    Sorry, "plot area only grows by 290 for each plot" should be: "plot area
    position only increases by 290 for each plot."

     
  • Ingo

    Ingo - 2010-04-06

    Sorry for posting my "fixed" code... It is a little strange... assume there is
    just one plot, what I do is the following:

    $plot = new PHPlot(950, 350);
    $plot->SetPlotAreaPixels(60, 75, 930, 325);
    

    which is absolutly ok! It may be because of the title within the plot that I
    need a little more height.

    If there are two plots I need to do this:

    $plot = new PHPlot(950, 640(320*2 for 2 plots));
    $plot->SetPlotAreaPixels(60, 365(=yEnd first plot +40), 930, 615 (=yEnd first plot +290));
    

    The thrid plot goes like:

    $plot = new PHPlot(950, 930(310*3 for 3 plots));
    $plot->SetPlotAreaPixels(60, 405(=yEnd 2. plot +40), 930, 905 (=yEnd 2. plot +290));
    

    Depending on how many plots need to be drawn I need to fix the overall image
    height with the if statements, otherwise there is eighter not enough or way to
    less space. All plot have the exact same height an starting position but for
    some reason the overall image height needs to be ajusted every time.

    I also figured out that this is only needed for the first 5 plots! After that
    every plot is drawn perfect using an increase of 300px for each plot.

    I don't know how to explain otherwise :-/ I also calculated the sizes by hand
    verything looks ok the way I am doing it. Yesterday I checked it over and over
    again an tested it out but the only way to get it drawn correctly was to build
    up this IF statements.

    If will check out the thread you mentioned above! Thank you!

    If you might have any additional idea!?

     
  • lbayuk

    lbayuk - 2010-04-06

    Here's how I do it. These are pieces taken from a PHPlot test script I use.
    (Hope this helps. There is nothing special about the first 5, just the first 1
    needs extra space above it for the overall title.)

    Part 1: Setup

    $n_plots = 8;               // Number of plots to draw
    $height_of_each_plot = 300; // Plot area height for of each plot
    $title_space = 50;          // Space at top of first plot, for overall title
    $space_below_plots = 60;    // Space below each plot, including axis label
    

    Part 2: Calculate image size and create PHPlot object:

    $image_height = $n_plots * ($height_of_each_plot + $space_below_plots) + $title_space;          
    $plot = new PHPlot(800, $image_height);
    

    Part 3: Loop creating plots:

    $y1 = $title_space;                    // Top of plot area
    $y2 = $y1 + $height_of_each_plot;      // Bottom of plot area
    for($i = 0; $i < $n_plots; $i++) {
       $plot->SetPlotAreaPixels(80, $y1, 740,$y2);
    
    ... Setup and draw the plot here ...
    
       $y1 = $y2 + $space_below_plots;    // Step to next plot position
       $y2 = $y1 + $height_of_each_plot;  // Step to next plot position
    }
    
     
  • lbayuk

    lbayuk - 2010-04-06

    This BBcode stuff is really annoying... two tries to post that and it is still
    messed up. The Part 3 "code" marker got lost somehow. Trying one more time:

    Part 3: Loop creating plots:

    $y1 = $title_space;                    // Top of plot area
    $y2 = $y1 + $height_of_each_plot;      // Bottom of plot area
    for($i = 0; $i < $n_plots; $i++) {
       $plot->SetPlotAreaPixels(80, $y1, 740,$y2);
       ... Setup and draw the plot here ...
       $y1 = $y2 + $space_below_plots;    // Step to next plot position
       $y2 = $y1 + $height_of_each_plot;  // Step to next plot position
    }
    
     
  • Ingo

    Ingo - 2010-04-07

    I just copyed your code and edited it just a little bit to fit my width and it
    is just awesome! Now every plot looks perfect without having these IF-
    statements to correct my messed up calculation... If just tested it with 1 up
    to 13 plots and all of them look exactly the same growing the way they should!

    I can't thank you enough for you help! If I have a minute I will try to figure
    out what the problem with my code is... I quess it might be something around
    the plot height + bottom area. Especially if there is no title (plot 2 to n)
    :-/ hmmm...

    Again thank you very much for your kind support! I love working with PHPLOT so
    much :-D

     

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.