... Further: if your difficulty is that you were expecting the GD::Graph::multi to automatically disambiguate the two axis: that's not going to happen. But you can do it yourself. For example, in the modified version of the code below, I use the elements of the $opts{use_axis} array to set the value of $opts{types} to 'lines' (for the left axis) or 'points' (for the right axis).
#!/usr/bin/perl use warnings; use strict; use GD::Graph::mixed; my @data = ( ["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"], [ 1, 4, 9, 16, 25, 36, 49, 64, 81], # +wants left: 0 .. 100 'x**2', [ 1, 1.4, 1.7, 2, 2.2, 2.4, 2.6, 2.8, 3], # +wants right: 0 .. 5 '~sqrt(x)' [ 99, 88, 77, 66, 55, 44, 33, 22, 11], # +wants left: 0 .. 100 '11*(10-x)', [ 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5], # +wants right: 0 .. 5 '0.5x', [ 1, 2, 3, 4, 5, 4, 3, 2, 1], # +wants right: 0 .. 5 '123454321' [ 98, 76, 54, 32, 10, '', '', '', ''], # +wants left: 0 .. 100 'descend', ); my $my_graph = new GD::Graph::mixed( ); my %opts = ( transparent => '0', x_label => 'nth', y1_label => 'big', y2_label => 'small', title => 'Using two axes', y1_max_value => 100, y2_max_value => 5, y_tick_number => 8, y_label_skip => 2, long_ticks => 1, use_axis => [1,2,1,2,2,1], # big, small, big, small, small, b +ig legend_placement => 'BR', x_labels_vertical => 1, x_label_position => 1/2, two_axes => 1, legend_marker_width => 100, l_margin => 10, b_margin => 10, r_margin => 20, t_margin => 10, show_values => 1, ); $opts{types} = [ (undef, 'lines', 'points')[@{$opts{use_axis}}] ]; # +if use_axis[n]==0, don't graph; if use_axis[n]==1, graph with lines; +if use_axis[n]==2, graph with points $my_graph->set(%opts); $my_graph->set_legend( 'x**2', '~sqrt(x)', '11*(10-x)', '0.5x', '12345 +4321', 'descend'); save_it($my_graph, \@data, 'out1.png'); # second graph, same as the first (except for use_axis) $opts{use_axis} = [1,2,1,1,1,1]; # big, small, big, big +<will shrink>, big<will shrink>, big $opts{types} = [ (undef, 'lines', 'points')[@{$opts{use_axis}}] ]; my $second_graph = new GD::Graph::mixed( ); $second_graph->set(%opts); $second_graph->set_legend( 'x**2', '~sqrt(x)', '11*(10-x)', '0.5x', '1 +23454321', 'descend'); save_it($second_graph, \@data, 'out2.png'); sub save_it { my ($graph, $data_ref, $fname) = @_; my $gd = $graph->plot($data_ref) or die $graph->error; open(my $img, '>', $fname) or die "$fname: $!\n"; binmode $img; print {$img} $gd->png; close $img; }
update: added images to imgur: out1.png, out2.png
In reply to Re^2: Usage of use_axis
by pryrt
in thread Usage of use_axis
by Sarat1729
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |