#!/usr/bin/perl use Chart::Gnuplot; #one must specify FILENAME to get data from (tab-delimited), a name for the output file, a type for output file (e.g. pdf, png, eps) and a plot title ($infile, $title, $type, $plot_title) = @ARGV; $outfile = $plot_title.'.'.$type; #add or remove colours accordingly @colour_array = ("#00308F", "#004225", "#480607", "#AF002A", "#008000", "#E25822", "#3B444B", "#7C0A02", "#848482", "#563C5C"); @data; $counter; open IN, "$infile" or die $!; $label_line = ; chomp $label_line; #find the labels data (for naming the colours in the stacked bars) @split_labels = split(/\t/, $label_line); while() { 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 colours 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 => 'Performance', 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) @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 $ds = Chart::Gnuplot::DataSet->new( xdata => \@x, ydata => \@tmp_y, title => "$legend_name", fill => {density => 0.2}, style => "histograms", color => "$pick_colours[$y-1]" ); push @all_vars, $ds; } $chart->plot2d(@all_vars);