Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I couldn't see how to do stacked bars with Chart::Gnuplot. This example uses GD::Graph.

#!perl use strict; use GD; use GD::Graph::bars; use GD::Graph::hbars; # read header for y legend chomp( my $header = <DATA> ); my (undef,@y_legend) = split /\s+/,$header; # read rows of data my @data=(); while (<DATA>){ chomp; my @col = split /\s+/,$_; for my $i (0..$#col){ push @{$data[$i]},$col[$i]; } } # create vertical stacked bars graph # use hbars->new for horiz stacked bars my $my_graph = GD::Graph::bars->new(1000,500); $my_graph->set( x_label => 'Method', y_label => 'Y label', title => 'Stacked Bar', cumulate => 2, bar_spacing => 5, transparent => 0, ); # Allowed # white, lgray, gray, dgray, black, lblue, blue, dblue, gold, lyellow, + yellow, # dyellow, lgreen, green, dgreen, lred, red, dred, lpurple, purple, dp +urple, lorange, # orange, pink, dpink, marine, cyan, lbrown, dbrown. my @colour_array = qw(lblue dbrown blue lred lgreen yellow green red purple orange pink dyellow); $my_graph->set( dclrs => \@colour_array ); # text sizes # gdGiantFont, gdLargeFont, gdMediumBoldFont, gdSmallFont , gdTinyFont $my_graph->set_x_label_font(gdGiantFont); $my_graph->set_x_axis_font(gdSmallFont); $my_graph->set_y_label_font(gdGiantFont); $my_graph->set_y_axis_font(gdMediumBoldFont); $my_graph->set_title_font(gdGiantFont); $my_graph->set_legend_font(gdGiantFont); $my_graph->set_legend( @y_legend ); # plot my $img = $my_graph->plot(\@data); # save open(IMG, '>file.png') or die $!; binmode IMG; print IMG $img->png; __DATA__ METHOD 0TM 1TM 2TM >2TM method1 3 68 18 10 method2 3 80 10 6 method3 3 87 9 1 method4 5 83 9 3 method5 6 75 15 4 method6 14 77 6 3 method7 12 82 2 3 method8 9 84 3 3 method9 13 68 16 3 method10 5 65 20 9 method11 9 64 20 7 method12 5 68 18 9 method13 6 82 9 2 method14 11 79 8 2 method15 6 69 20 5 method16 5 80 11 3 method17 1 68 17 14

In reply to Re^5: Is this the correct structure? by poj
in thread Is this the correct structure? by Anonymous Monk

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    [1nickt]: ambrus perhaps you know where the keys are?
    [ww]: OTOH, -- for ads suggesting that being good at games is somehow eq "greatness"
    [ambrus]: 1nickg: obviously the gamers don't know. but anyway, I need the whole room backlit, because watching a monitor in a dark room (like many people do) is tiring for my eyes, even more so than doing it in a lit room.
    [1nickt]: ambrus I agree. I suspect one's eyes are always trying to adjust across the boundary between very bright and very dark ... like a camera's autofocus struggling to choose the target.

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (18)
    As of 2017-03-27 13:55 GMT
    Find Nodes?
      Voting Booth?
      Should Pluto Get Its Planethood Back?

      Results (320 votes). Check out past polls.