Hi! I wrote a Histogram module based on GD::Graph::bar / mixed. I need for some datasets a log scale for the y-axes. Works fine with:
# transform data sub _log_scale { my ( $self, @y ) = @_; foreach my $y (@y) { foreach my $data (@{$y}) { if (!defined $data || $data <= 0) { $data = undef; } else { $data = log($data); } } } return @y; } # now "fix" the y labels sub _y_exp_format { my ( $v ) = @_; return 0 if !defined $v; return sprintf( "%.0f", exp($v)); } if ($self->get_logscale) { $graph->set('y_number_format' => \&_y_exp_format, # 'y_min_value' => -1 ); }
My only problem is now how to display bars of size 1 (they are of course 0 in logscale and I have a lot of them). Starting y-values at -1 does not work. Some log scaled example y values:
VAR1 = [ [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 ], [ '8.51499076786104', '5.79301360838414', '5.26269018890489', '4.00733318523247', '3.04452243772342', '1.94591014905531', '2.19722457733622', '1.6094379124341', '2.30258509299405', '0', '1.09861228866811', '0.693147180559945', '1.09861228866811', '0', undef, undef, undef, undef, undef, undef, undef, undef, undef ],
I want undef values not drawn, but 0 drawn somehow. Is this possible?

In reply to GD::Graph and log scale by lima1

Title:
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, details, 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, summary, 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.