jthomas has asked for the wisdom of the Perl Monks concerning the following question:

Hi all

I dont know whether i named it correctly. I have been using GD::Graph for some time now. Currently i have a requirement to plot a matrix kind of graph. It's actually a kind of 3 axis.

my @x = qw (A A B B C C); my @y = qw (Q1 Q2 Q1 Q2 Q1 Q2); my @z = qw (100 200 300 100 150 100);

I tried DBD::Chart with 3 axis but the values are getting messy (not at all readable) when lot's of z values are there. So i was thinking whether there is a way where we can plot kind of a matrix graph

Where we can map A-Q1 = 100, A-Q2 = 200 etc in a two axis itself like a matrix and show the values as a points.

Replies are listed 'Best First'.
Re: Matrix kind of graph
by BrowserUk (Patriarch) on Feb 24, 2011 at 09:16 UTC

    Making a guess from your data, maybe something like this might work?

    #! perl -slw use strict; use GD::Graph::bars; my @data = ( [ qw ( A B C ) ], [ qw ( 100 300 150 ) ], [ qw ( 200 100 100 ) ], ); my $graph = GD::Graph::bars->new(400, 300); $graph->set( show_values => 1, x_label => 'Store', y_label => 'Sales', title => 'Sales/Store/Quarter', y_max_value => 400, y_min_value => 000, y_tick_number => 8, y_label_skip => 1, bargroup_spacing => 10, ) or die $graph->error; $graph->set_legend( qw[ Q1 Q2 ]); my $gd = $graph->plot(\@data) or die $graph->error; open(IMG, '>file.gif') or die $!; binmode IMG; print IMG $gd->gif; close IMG;

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      I had the same idea, but like always the best answer depends on information we don't have about the original data!

      Like whats the maximum timespan, number of stores and expected information gain.

      I guess that distinguishing up to 20 stores by color or symbols should be sufficient to represent them all into one 2D chart (Sales x Time). Connecting the points might help:

      Like here or even with perspective.

      All images found by googling for GD:Graph.

      Cheers Rolf

Re: Matrix kind of graph
by moritz (Cardinal) on Feb 24, 2011 at 07:16 UTC
    What is a "matrix graph"? What axis should it have, and what data should be plotted along which axis?

    Looking at your small excerpt it seems to me you could combine @x and @y into a single array and use it as labels on the x axis, and you could use @z as the values on the y axis.

      Hi Mortiz,

      Yes that can be done, But in my case it's going to be huge number of combination (Cartesian). So X values going to be really messy.

      My idea was, graph will be having one X-Axis with X values and one Y-Axis with Y values. There will not be any Z axis but in the canvas it'll show the values.

        So it sounds you either want a 3D plot, or a density plot/heat map where the z value is encoded in the color.

        I have done neither with Perl so far, but these key words should give you an idea what to search for. A quick search showed up tridens, which might do what you want.

Re: Matrix kind of graph
by vkon (Curate) on Feb 24, 2011 at 07:40 UTC
    I guess you want to adopt your matrix data for GraphViz and use it to build your graph
Re: Matrix kind of graph
by LanX (Saint) on Feb 24, 2011 at 11:15 UTC
    It took me some time to figure out what you might want.

    You want to represent a set of 3D points in a 2D plane with the z coordinates plotted as values?

    This can only work if 2 points never have the same x/y coordinates.

    Like showing a map for New York's skyscraper's from above by plotting the heights, this can only work because buildings "rarely" share the same coordinates.

    Are you sure your data fits into this criteria?

    Anyway the words "matrix" and "graph" are misleading, graphs are normally represented as connected lines, not plotted points.

    And representations of matrices have a equidistant grid, i.e. a tabular structure.

    If the latter is the case (and that's what your data looks like) you could simply use perl's format to plot your z-values.

    Cheers Rolf

      Hi All, thanks for the responses.

      To get more clarity, I have uploaded one sample graph here

        The linked graph is a type of scattergram, but it is quite hard to relate that to your sample data?


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
        You want to represent z-values by colors within a x/y-grid?

        Cheers Rolf

Re: Matrix kind of graph
by scorpio17 (Canon) on Feb 24, 2011 at 20:15 UTC