Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I am almost there with Chart::Gnuplot.
One question still remains to be answered...
In the final step, the:
$chart->plot2d($h1, $h2, $h3...)

where $h1, $h2, $h3 etc are the various datasets created with Chart::Gnuplot::DataSet->new, how can I pass the names ($h1, $h2 etc) if I have them in an array?
My final version of the code so far is:
#!/usr/bin/perl use Chart::Gnuplot; #one must specify FILENAME to get data from (tab-delimited), a name fo +r the output file, a type for output file (e.g. pdf, png, eps) and a +plot title ($infile, $title, $type, $plot_title) = @ARGV; $outfile = $title.'.'.$type; #add or remove colours accordingly @colour_array = ("lblue", "brown", "blue", "lred", "lgreen", "yellow", + "green", "red", "purple", "orange", "pink", "dyellow"); @data; $counter; open IN, "$infile" or die $!; $label_line = <IN>; chomp $label_line; #find the labels data (for n +aming the colours in the stacked bars) @split_labels = split(/\t/, $label_line); while(<IN>) { chomp; $counter = 0; for (split/\t/,$_) { push @{$data[$counter++]}, $_; } } close IN; #x-axis labels is the row #0 in the AoA @data @x = @{$data[0]}; $total_y = @data-1; #find how many y rows we have => how many colou +rs we need (-1 because #0 is x-axis) @pick_colours = @colour_array[ 0 .. $total_y - 1 ]; # Initiate the chart object $chart = Chart::Gnuplot->new( output => $outfile, title => $title, xlabel => { text => 'Method', color => 'black', offset => "-1", font => 'Times-Roman, 20' }, ylabel => { text => $plot_title, color => 'black', offset => -1, font => 'Times-Roman, 20' }, yrange => [0, '*'], xtics => { rotate => '-270', font => 'Times-Roman, 15' }, ytics => { font => 'Times-Roman, 15' }, bg => { color => 'white', density => 0.2, }, plotbg => 'white', legend => {position => 'outside bottom'}, border => { sides => 'bottom, left', linetype => 3, width => 2, color => 'black', }, "style histogram" => 'rowstacked' ); #all the rest rows in @data are used for creating the histogram bars #create object foreach series of data (column in excel) $counter_objects=0; @all_vars=(); for $y ( 1 .. $#data ) { $legend_name = $split_labels[$y]; #get the name for the legend, + e.g 1TM, 2TM, >2TM @tmp_y = @{$data[$y]}; #create temp array $counter_objects++; $myvar.= '$h'."$counter_objects".", "; push @all_vars, $myvar; ${h."$counter_objects"} = Chart::Gnuplot::DataSet->new ( xdata => \@x, ydata => \@tmp_y, title => "$legend_name", fill => {density => 0.2}, style => "histograms", ); } $wanted = substr ($string_of_vars,0, -2); $chart->plot2d(\@all_vars);

but in the last step, it complaints, because:
Not a HASH reference at /usr/local/share/perl/5.14.2/Chart/

In reply to Re^6: Is this the correct structure? by Anonymous Monk
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
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (7)
    As of 2018-05-27 10:15 GMT
    Find Nodes?
      Voting Booth?