blib/lib/Matplotlib/Simple/Gnuplot.pm

filter: Statementstmt 91.1% 1540 / 1690 Branchbran 69.2% 601 / 868 Conditioncond 54.3% 231 / 425 MC/DCmcdc 21.8% 53 / 243 Subroutinesub 98.8% 85 / 86 Podpod 0.0% 0 / 65 totaltotal 74.3% 2510 / 3377 CC 668 SCAR 37.4
CC
668
Cov
80%
draw_bar
163.4
draw_hist2d
85.2
draw_colored_table
64.7
CRAP 42.3
« blib/lib/Matplotlib/Simple/Matplotlib.pm ↑ Summary blib/lib/Matplotlib/Simple/Ggplot2.pm »
1 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 5 ▶use feature 'say';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Matplotlib::Simple::Gnuplot;
6 # The gnuplot engine: "engine => 'gnuplot'" writes plt's figure as a gnuplot
7 # script and runs it. Matplotlib::Simple has checked the arguments, and check_engine has
8 # refused every plot type and keyword not listed below, before render() is
9 # called.
10 #
11 # Everything a figure needs -- bins, densities, quartiles, the mean and spread
12 # of "wide" runs -- is worked out here in Perl, and the script is given only
13 # numbers to draw, in datablocks, and text, through gp_str. The script does no
14 # arithmetic of its own on the caller's data, so what is drawn is what was
15 # checked.
16 #
17 # The defaults are matplotlib's, so that the same call draws the same figure:
18 # the "tab:" color cycle (rcParams axes.prop_cycle, matplotlib 3.11.2), 10
19 # bins for hist (rcParams hist.bins), whiskers at 1.5 times the interquartile
20 # range (rcParams boxplot.whiskers), the quartiles numpy.percentile's
21 # "linear" method gives, violins from scipy-style gaussian_kde densities with
22 # Scott's bandwidth, n ** (-1/5), as matplotlib.mlab.GaussianKDE computes
23 # them, scaled to half of matplotlib's default violin width of 0.5, a 6.4 by
24 # 4.8 inch figure (rcParams figure.figsize) and 100 dots per inch for a PNG
25 # (rcParams figure.dpi).
26 5 require 5.010;
27 5 our $VERSION = 0.3345;
28 5 ▶use Scalar::Util 'looks_like_number';
Subroutine BEGIN: called CC=1 SCAR=0.0
29 5 ▶use List::Util qw(max min sum);
Subroutine BEGIN: called CC=1 SCAR=0.0
30 5 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
31 5 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
32 5 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
33 5 ▶use File::Temp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
34 5 ▶use Sys::Hostname ();
Subroutine BEGIN: called CC=1 SCAR=0.0
35 5 ▶BEGIN { require Matplotlib::Simple }
Subroutine BEGIN: called CC=1 SCAR=0.0
36 5 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=6.9
37 5 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
38 5 *{$_} = \&{"Matplotlib::Simple::$_"} foreach qw(as_double axis_limits axis_scale bar_series bin_counts bool_option
39 cb_limits check_key_order check_numbers check_scatter_lengths check_scatter_values
40 check_wide_runs color_hex colormap_colors creator_note decoded_text double_literal finite_values
41 is_finite is_nan linspace logscale_axes logspace plain_text program_from_env run_script script_handle
42 svg_creator_metadata table_cells);
43 }
44 # What this engine draws: plot type => the keywords of %Matplotlib::Simple::opt it reads
45 # for that type. hexbin and venn_proportional_area are not here: gnuplot has
46 # no hexagonal binning and no area-proportional Venn layout, and neither is
47 # drawn rather than drawn as something else.
48 5 my @colorbar = ( 'cb_logscale', 'cb_max', 'cb_min', 'cblabel', 'cmap', 'colorbar_on' );
49 5 my @bar = ( 'color', 'key_order', 'label', 'log', 'logscale', 'stacked', 'width', 'xerr', 'yerr' );
50 5 my @violin = ( 'color', 'colors', 'edgecolor', 'key_order', 'logscale', 'medians', 'orientation', 'whiskers' );
51 5 our %types = (
52 bar => [@bar],
53 barh => [@bar],
54 boxplot => [ 'color', 'colors', 'key_order', 'logscale', 'orientation', 'showcaps', 'showfliers', 'showmeans' ],
55 colored_table => [ @colorbar, 'col_labels', 'default_undefined', 'mirror', 'row_labels', 'show_numbers', 'undef_color' ],
56 hist => [ 'alpha', 'bins', 'color', 'key_order', 'logscale', 'orientation', 'show_legend' ],
57 hist2d => [ @colorbar, 'cmax', 'cmin', 'density', 'key_order', 'logscale', 'show_colorbar', 'vmax', 'vmin', 'xbins', 'xmax', 'xmin', 'ybins', 'ymax', 'ymin' ],
58 imshow => [ @colorbar, 'stringmap', 'vmax', 'vmin' ],
59 pie => [ 'autopct', 'key_order', 'labeldistance', 'pctdistance' ],
60 plot => [ 'key_order', 'logscale', 'show_legend' ],
61 scatter => [ @colorbar, 'color_key', 'key_order', 'keys', 'logscale', 'show_legend' ],
62 violin => [@violin],
63 violinplot => [@violin],
64 wide => [ 'color', 'show_legend' ],
65 );
66 5 our @plot_keywords = ( 'set_title', 'set_xlabel', 'set_xlim', 'set_xscale', 'set_ylabel', 'set_ylim', 'set_yscale', 'title', 'xlabel', 'xscale', 'ylabel', 'ylim', 'yscale' );
67 5 our @figure_keywords = ( 'scale', 'scalex', 'scaley', 'suptitle' );
68  
69 5 my $engine = 'gnuplot';
70 # 1 = style => 'native' (%Matplotlib::Simple::styles): gnuplot's own colors, palette,
71 # statistics and look; 0 = matplotlib's, as everywhere else in this file. Set
72 # by render.
73 5 my $native = 0;
74 # matplotlib's figure, in inches, and a PNG's dots per inch; see the header.
75 5 my ( $fig_width, $fig_height, $png_dpi ) = ( 6.4, 4.8, 100 );
76 # The SVG terminal's units are pixels at 100 per inch, as a PNG's, so that one
77 # figure is laid out the same in both. Both take a line's width in pixels, so
78 # matplotlib's widths in points are scaled by 100/72 for them, and a font's size
79 # in a unit of their own, which by eye against matplotlib's 10-point tick labels
80 # on the same 640 by 480 PNG is 1.1 of a point. The PDF terminal takes points.
81 # Both set by render.
82 5 my ( $px_per_pt, $font_scale );
83 # Under style => 'native', each terminal's own font, line width and
84 # background; the size, and "noenhanced", which makes text read as given,
85 # are kept.
86 124 ▶sub pixels {
Subroutine pixels: called CC=1 SCAR=0.0
Pod undocumented
87 # A size in inches as whole pixels, rounded as the ggplot2 engine rounds
88 # them. "%d" cut them down, and 4.8 * 3 * 100, which is 1439.9999999999998,
89 # made "scale => 3" a PNG of 1920 by 1439, where matplotlib's is 1440.
90 124 return map { int( $_ * $png_dpi + 0.5 ) } @_;
91 }
92 my %terminal_of = ( # output_file's extension => how its terminal is set
93 122 ▶ svg => sub { my ( $w, $h ) = pixels(@_); return "svg size $w,$h dynamic noenhanced" if $native; sprintf 'svg size %d,%d dynamic font "sans,%.1f" noenhanced linewidth %.2f background "#ffffff"', $w, $h, 10 * $font_scale, $px_per_pt },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $native 61 61 122
94 2 ▶ png => sub { my ( $w, $h ) = pixels(@_); return "pngcairo size $w,$h noenhanced" if $native; sprintf 'pngcairo size %d,%d font "sans,%.1f" noenhanced linewidth %.2f background "#ffffff"', $w, $h, 10 * $font_scale, $px_per_pt },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $native 1 1 2
95 0 ▶ pdf => sub { my ( $w, $h ) = @_; return sprintf 'pdfcairo size %.4fin,%.4fin noenhanced', $w, $h if $native; sprintf 'pdfcairo size %.4fin,%.4fin font "sans,10" noenhanced', $w, $h },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if $native 0 0 0
96 5 );
97 # matplotlib's scatter markers, in the order it cycles through them for sets
98 # colored by a key, as gnuplot point types: filled where matplotlib's are.
99 # gnuplot has no left or right triangle, hexagon or thin diamond, so those
100 # take the nearest shape it has.
101 5 my @marker_cycle = ( 7, 5, 9, 13, 11, 1, 2, 3, 9, 11, 15, 7, 13 ); # o s ^ D v P X * < > p h d
102 # matplotlib's markers are 6 points across (rcParams lines.markersize); set by
103 # render to the gnuplot point size that draws them so, measured by eye on the
104 # PNG terminal against matplotlib's own.
105 5 my $point_size;
106 # matplotlib's line width, 1.5 points (rcParams lines.linewidth), as gnuplot's,
107 # whose width 1 is about 1 point at this size.
108 5 my $line_width = 1.5;
109  
110 # gnuplot's own colors, for style => 'native': "set colorsequence default",
111 # the eight linetypes gnuplot has used since 5.0, as "show linetype" lists them
112 # in gnuplot 6.0 patchlevel 0 ("dark-violet" is #9400d3 by "show colornames").
113 5 my @gnuplot_colors = ( '#9400d3', '#009e73', '#56b4e9', '#e69f00', '#f0e442', '#0072b2', '#e51e10', '#000000' );
114  
115 # State of the figure being written: the script, the datablocks waiting to be
116 # written before the next plot command, their count, the name the caller
117 # called, the points drawn (for key_place), and the corners of every box drawn
118 # (for thin_tics).
119 5 my ( $fh, @blocks, $n_blocks, $current_sub, @points, @extent );
120 5 my %tic_labels; # axis => the category labels tics() wrote on it, for thin_tics
121 # The size of one subplot, in inches, when there are several; undef for a
122 # figure of one plot, whose tics and fonts are left as they are. Set by render.
123 5 my ( $panel_w, $panel_h );
124  
125 855 ▶sub gp_str {
Subroutine gp_str: called CC=2 SCAR=7.0
Pod undocumented
126 # A Perl string as a gnuplot double-quoted string literal. Every label,
127 # key and path goes through this. Backslash and double quote are escaped,
128 # a newline is \n, and every other control character is left out, since
129 # gnuplot has no escape for most of them. The terminals are set
130 # "noenhanced", so "@", "&", "^", "_", "{" and "}" are written as they are.
131 855 my ($str) = @_;
132 855 ▶ $str = decoded_text( $str // '' );
Condition50%1/2
$str // ""
l!l
8550
MC/DC0%0/1
$str // ""
$str
Truth table50%1/2
A
A= $str
Aresult
11
00
133 855 $str =~ s/\\/\\\\/g;
134 855 $str =~ s/"/\\"/g;
135 855 $str =~ s/\r?\n/\\n/g;
136 855 $str =~ s/\t/\\t/g;
137 855 $str =~ s/[\x00-\x08\x0b-\x1f\x7f]//g;
138 855 return "\"$str\"";
139 }
140 17324 ▶sub gp_num {
Subroutine gp_num: called CC=4 SCAR=13.9
Pod undocumented
141 # A number as gnuplot reads it, with NaN for anything not finite: gnuplot
142 # draws an infinite value no better than a missing one, and matplotlib
143 # leaves both out. A finite one as double_literal writes it.
144 17324 my ($n) = @_;
145 17324 ▶ return 'NaN' if ( not defined $n ) || ( not looks_like_number($n) ) || ( not is_finite($n) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n and &looks_like_number($n) and is_finite($n) 10 17314 17324
Condition83%5/6
defined $n and &looks_like_number($n) and is_finite($n)
!ll&&!rl&&r
6417314
defined $n and &looks_like_number($n)
!ll&&!rl&&r
6017318
MC/DC66%2/3
defined $n and &looks_like_number($n) and is_finite($n)
defined $n &looks_like_number($n) is_finite($n)
Truth table75%3/4
A and B and C
A= defined $nB= &looks_like_number($n)C= is_finite($n)
ABCresult
0XX0
10X0
1100
1111
146 17314 return double_literal($n);
147 }
148 139 ▶sub gp_color {
Subroutine gp_color: called CC=2 SCAR=6.9
Pod undocumented
149 # A color from color_hex as a gnuplot rgb string. gnuplot's alpha is a
150 # transparency, 00 for opaque, written before the red.
151 139 my ($hex) = @_;
152 139 ▶ return gp_str($hex) if length $hex == 7;
Branch: 1 branch
BranchTrueFalseTotal
if length $hex == 7 124 15 139
153 15 return gp_str( sprintf '#%02x%s', 255 - hex substr( $hex, 7, 2 ), substr( $hex, 1, 6 ) );
154 }
155 98 ▶sub color_int {
Subroutine color_int: called CC=2 SCAR=7.0
Pod undocumented
156 # A color from color_hex as the integer "lc rgb variable" reads from a
157 # datablock: transparency in the top byte, as in gp_color.
158 98 my ($hex) = @_;
159 98 my $v = hex substr( $hex, 1, 6 );
160 98 ▶ $v += ( 255 - hex substr( $hex, 7, 2 ) ) * 2**24 if length $hex == 9;
Branch: 1 branch
BranchTrueFalseTotal
if length $hex == 9 0 98 98
161 98 return $v;
162 }
163 24 ▶sub with_alpha {
Subroutine with_alpha: called CC=1 SCAR=0.0
Pod undocumented
164 # A color from color_hex with its alpha set, from 0 to 1.
165 24 my ( $hex, $alpha ) = @_;
166 24 return substr( $hex, 0, 7 ) . sprintf( '%02x', int( $alpha * 255 + 0.5 ) );
167 }
168 148 ▶sub hex_of {
Subroutine hex_of: called CC=1 SCAR=0.0
Pod undocumented
169 # color_hex for this engine.
170 148 my ( $color, $what ) = @_;
171 148 return color_hex( $color, $what, $engine, $current_sub );
172 }
173 181 ▶sub cycle_color {
Subroutine cycle_color: called CC=2 SCAR=6.9
Pod undocumented
174 # The n-th color of matplotlib's default cycle, as "C0" to "C9" name it, or
175 # of gnuplot's own linetypes under style => 'native'.
176 181 ▶ return $gnuplot_colors[ $_[0] % @gnuplot_colors ] if $native;
Branch: 1 branch
BranchTrueFalseTotal
if $native 76 105 181
177 105 return hex_of( 'C' . ( $_[0] % 10 ), 'the color cycle' );
178 }
179 148 ▶sub next_color {
Subroutine next_color: called CC=2 SCAR=6.9
Pod undocumented
180 # The next color of an axes' cycle. matplotlib keeps two, one for lines and
181 # one for bars, wedges and points ("lines" and "patches"); gnuplot moves to
182 # the next linetype at every plot clause, whatever it draws, so under
183 # style => 'native' the two are one.
184 148 my ( $axes, $kind ) = @_;
185 148 ▶ return cycle_color( $axes->{ $native ? 'native' : $kind }++ );
Branch: 1 branch
BranchTrueFalseTotal
$native ? : 76 72 148
186 }
187 12 ▶sub default_palette_color {
Subroutine default_palette_color: called CC=3 SCAR=11.0
Pod undocumented
188 # gnuplot's default palette at $x from 0 to 1, as "#rrggbb": "rgbformulae
189 # 7,5,15", gnuplot's default ("help rgbformulae"), where formula 7 is
190 # sqrt(x), 5 is x^3 and 15 is sin(360x), in degrees ("show palette
191 # rgbformulae", gnuplot 6.0), each clipped to 0 .. 1.
192 12 my ($x) = @_;
193 12 my @c = ( sqrt($x), $x**3, sin( 8 * atan2( 1, 1 ) * $x ) );
194 12 ▶ return '#' . join( '', map { sprintf '%02x', int( 255 * ( $_ < 0 ? 0 : $_ > 1 ? 1 : $_ ) + 0.5 ) } @c );
Branch: 2 branches
BranchTrueFalseTotal
$_ < 0 ? : 8 28 36
$_ > 1 ? : 0 28 28
195 }
196 18 ▶sub ps {
Subroutine ps: called CC=2 SCAR=6.9
Pod undocumented
197 # The point size of a points clause, followed by a space: matplotlib's
198 # markers, or nothing, gnuplot's default, under style => 'native'.
199 18 ▶ return $native ? '' : "ps $point_size ";
Branch: 1 branch
BranchTrueFalseTotal
$native ? : 8 10 18
200 }
201 25 ▶sub lw {
Subroutine lw: called CC=2 SCAR=6.9
Pod undocumented
202 # A line's width in a clause, followed by a space: matplotlib's 1.5 points,
203 # or nothing, gnuplot's default, under style => 'native'.
204 25 ▶ return $native ? '' : "lw $line_width ";
Branch: 1 branch
BranchTrueFalseTotal
$native ? : 6 19 25
205 }
206 268 ▶sub datablock {
Subroutine datablock: called CC=5 SCAR=16.1
Pod undocumented
207 # Name a datablock holding these rows of numbers, to be written ahead of
208 # the next plot command; undef if there are no rows, which the callers
209 # leave out of the plot, since gnuplot refuses to plot an empty one.
210 268 my ($rows) = @_;
211 268 ▶ return undef if scalar @{$rows} == 0;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$rows;} == 0 7 261 268
212 261 my $name = '$d' . $n_blocks++;
213 # Where the data lie, for choosing a corner for the legend (key_place):
214 # each row's x and y and, for a boxxyerror row, its far corners.
215 261 foreach my $row ( @{$rows} ) {
216 5917 push @points, [ @{$row}[ 0, 1 ] ];
217 5917 ▶ push @points, [ $row->[2], $row->[5] ], [ $row->[3], $row->[5] ] if scalar @{$row} >= 6;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$row;} >= 6 1406 4511 5917
218 # And where the data reach, for thin_tics: a boxxyerror row's corners
219 # as well, since a bar's foot, unlike its top, is not a point drawn.
220 5917 push @extent, [ @{$row}[ 0, 1 ] ];
221 5917 ▶ push @extent, [ @{$row}[ 2, 4 ] ], [ @{$row}[ 3, 5 ] ] if scalar @{$row} >= 6;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$row;} >= 6 1406 4511 5917
222 }
223 261 push @blocks, "$name << EOD\n" . join( '', map { join( ' ', map { gp_num($_) } @{$_} ) . "\n" } @{$rows} ) . "EOD\n";
224 261 return $name;
225 }
226 96 ▶sub key_title {
Subroutine key_title: called CC=2 SCAR=6.9
Pod undocumented
227 # A legend entry for a plot clause, or none.
228 96 my ($label) = @_;
229 96 ▶ return defined $label ? 'title ' . gp_str($label) : 'notitle';
Branch: 1 branch
BranchTrueFalseTotal
defined $label ? : 60 36 96
230 }
231 82 ▶sub tics {
Subroutine tics: called CC=1 SCAR=0.0
Pod undocumented
232 # A "set xtics (...)" list of labels at positions.
233 82 my ( $axis, $labels, $positions ) = @_;
234 82 $tic_labels{$axis} = [ map { decoded_text($_) } @{$labels} ]; # for thin_tics
235 82 return "set ${axis}tics (" . join( ', ', map { gp_str( $labels->[$_] ) . ' ' . gp_num( $positions->[$_] ) } 0 .. $#{$labels} ) . ')';
236 }
237 43 ▶sub format_commas {
Subroutine format_commas: called CC=1 SCAR=0.0
Pod undocumented
238 # A count with commas between thousands, as matplotlib's boxplot and
239 # violin tick labels give it.
240 43 my $n = reverse "$_[0]";
241 43 $n =~ s/(\d{3})(?=\d)/$1,/g;
242 43 return scalar reverse $n;
243 }
244 125 ▶sub key_order_of {
Subroutine key_order_of: called CC=2 SCAR=7.0
Pod undocumented
245 # The keys of a plot's "data" in the order drawn: "key_order", or sorted.
246 125 my ( $plot, $data ) = @_;
247 125 ▶ return check_key_order({ keys => $plot->{key_order}, data => $data, option => 'key_order', sub => $current_sub }) if defined $plot->{key_order};
Branch: 1 branch
BranchTrueFalseTotal
if defined $plot->{"key_order"} 0 125 125
248 125 return sort keys %{$data};
249 }
250 55 ▶sub orientation_of {
Subroutine orientation_of: called CC=4 SCAR=14.6
Pod undocumented
251 # "vertical" or "horizontal", vertical by default.
252 55 my ($plot) = @_;
253 55 ▶ my $o = $plot->{orientation} // 'vertical';
Condition100%2/2
$plot->{"orientation"} // "vertical"
l!l
748
MC/DC100%1/1
$plot->{"orientation"} // "vertical"
$plot->{"orientation"}
Truth table100%2/2
A
A= $plot->{"orientation"}
Aresult
11
00
254 55 ▶ die "$current_sub needs either \"horizontal\" or \"vertical\", not \"$o\"" if ( ref $o ) || ( $o !~ m/^(?:horizontal|vertical)$/ );
Branch: 1 branch
BranchTrueFalseTotal
if ref $o or not $o =~ /^(?:horizontal|vertical)$/ 0 55 55
Condition33%1/3
ref $o or not $o =~ /^(?:horizontal|vertical)$/
l!l&&r!l&&!r
0055
MC/DC0%0/2
ref $o or not $o =~ /^(?:horizontal|vertical)$/
ref $o not $o =~ /^(?:horizontal|vertical)$/
Truth table33%1/3
A or not(B)
A= ref $oB= not $o =~ /^(?:horizontal|vertical)$/
ABresult
1X1
011
000
255 55 return $o;
256 }
257 71 ▶sub percentile {
Subroutine percentile: called CC=2 SCAR=6.9
Pod undocumented
258 # numpy.percentile's default ("linear") of already-sorted values.
259 71 my ( $sorted, $p ) = @_;
260 71 my $i = ( $p / 100 ) * $#{$sorted};
261 71 my $lo = POSIX::floor($i);
262 71 my $frac = $i - $lo;
263 71 ▶ return $sorted->[$lo] if $frac == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $frac == 0 33 38 71
264 38 return $sorted->[$lo] + $frac * ( $sorted->[ $lo + 1 ] - $sorted->[$lo] );
265 }
266 26 ▶sub palette {
Subroutine palette: called CC=14 SCAR=26.6
Pod undocumented
267 # The commands that color by a colormap from $lo to $hi (either undef to
268 # take it from the data), on a log scale or not, with or without a
269 # colorbar, labelled or not.
270 # An undefined cmap is gnuplot's own palette (default_cmap).
271 26 my ($args) = @_;
272 26 my @set;
273 26 ▶ if ( defined $args->{cmap} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{'cmap'}) { } 13 13 26
274 13 my @colors = colormap_colors( $args->{cmap}, $engine, $current_sub );
275 12 push @set, 'set palette defined (' . join( ', ', map { "$_ " . gp_str( $colors[$_] ) } 0 .. $#colors ) . ')';
276 12 push @set, 'set palette maxcolors 0';
277 } else {
278 13 push @set, 'set palette rgbformulae 7,5,15', 'set palette maxcolors 0';
279 }
280 25 ▶ push @set, $args->{log} ? 'set logscale cb' : 'unset logscale cb';
Branch: 1 branch
BranchTrueFalseTotal
$args->{'log'} ? : 1 24 25
281 25 ▶ push @set, 'set cbrange [' . ( defined $args->{lo} ? gp_num( $args->{lo} ) : '*' ) . ':' . ( defined $args->{hi} ? gp_num( $args->{hi} ) : '*' ) . ']';
Branch: 2 branches
BranchTrueFalseTotal
defined $args->{'lo'} ? : 25 0 25
defined $args->{'hi'} ? : 25 0 25
282 25 ▶ push @set, $args->{colorbar} ? 'set colorbox' : 'unset colorbox';
Branch: 1 branch
BranchTrueFalseTotal
$args->{'colorbar'} ? : 24 1 25
283 25 ▶ push @set, 'set cblabel ' . gp_str( $args->{label} ) if $args->{colorbar} && defined $args->{label};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"colorbar"} and defined $args->{"label"} 15 10 25
Condition100%3/3
$args->{"colorbar"} and defined $args->{"label"}
!ll&&!rl&&r
1915
MC/DC100%2/2
$args->{"colorbar"} and defined $args->{"label"}
$args->{"colorbar"} defined $args->{"label"}
Truth table100%3/3
A and B
A= $args->{"colorbar"}B= defined $args->{"label"}
ABresult
0X0
100
111
284 # A colorbar as tall as a small subplot holds fewer labels than gnuplot
285 # gives it, which ran into each other in a 2 by 2 grid.
286 25 ▶ if ( $args->{colorbar} && ( not $args->{log} ) && ( defined $panel_h ) && ( defined $args->{lo} ) && ( defined $args->{hi} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"colorbar"} and not $args->{"log"} and defined $panel_h and defined $args->{"lo"} and defined $args->{"hi"}) 3 22 25
Condition83%10/12
$args->{"colorbar"} and not $args->{"log"} and defined $panel_h and defined $args->{"lo"} and defined $args->{"hi"}
!ll&&!rl&&r
2203
$args->{"colorbar"} and not $args->{"log"} and defined $panel_h and defined $args->{"lo"}
!ll&&!rl&&r
2203
$args->{"colorbar"} and not $args->{"log"} and defined $panel_h
!ll&&!rl&&r
2203
$args->{"colorbar"} and not $args->{"log"}
!ll&&!rl&&r
1123
MC/DC60%3/5
$args->{"colorbar"} and not $args->{"log"} and defined $panel_h and defined $args->{"lo"} and defined $args->{"hi"}
$args->{"colorbar"} not $args->{"log"} defined $panel_h defined $args->{"lo"} defined $args->{"hi"}
Truth table66%4/6
A and not(B) and C and D and E
A= $args->{"colorbar"}B= not $args->{"log"}C= defined $panel_hD= defined $args->{"lo"}E= defined $args->{"hi"}
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
287 3 my $step = tick_step( $args->{lo}, $args->{hi}, tick_bins( plot_length('y'), 2 ) );
288 3 ▶ push @set, 'set cbtics ' . gp_num($step) if defined $step;
Branch: 1 branch
BranchTrueFalseTotal
if defined $step 3 0 3
289 }
290 25 return @set;
291 }
292 12 ▶sub palette_at {
Subroutine palette_at: called CC=3 SCAR=20.6
Pod undocumented
293 # The color a palette() of this colormap gives $x from 0 to 1: between
294 # the two nearest of its colors, or gnuplot's own palette for undef.
295 12 my ( $cmap, $x ) = @_;
296 12 ▶ return default_palette_color($x) unless defined $cmap;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cmap 12 0 12
297 0 my @colors = colormap_colors( $cmap, $engine, $current_sub );
298 0 my $pos = $x * $#colors;
299 0 ▶ my $i = ( $pos >= $#colors ) ? $#colors - 1 : POSIX::floor($pos);
Branch: 1 branch
BranchTrueFalseTotal
$pos >= $#colors ? : 0 0 0
300 0 my $frac = $pos - $i;
301 0 my @a = map { hex substr( $colors[$i], $_, 2 ) } ( 1, 3, 5 );
302 0 my @b = map { hex substr( $colors[ $i + 1 ], $_, 2 ) } ( 1, 3, 5 );
303 0 return '#' . join( '', map { sprintf '%02x', int( $a[$_] + $frac * ( $b[$_] - $a[$_] ) + 0.5 ) } 0 .. 2 );
304 }
305 38 ▶sub default_cmap {
Subroutine default_cmap: called CC=3 SCAR=11.0
Pod undocumented
306 # The colormap a type takes when the caller gives none: matplotlib's
307 # default for it, or undef, gnuplot's own palette, under style => 'native'.
308 38 my ( $plot, $matplotlib_default ) = @_;
309 38 ▶ return $plot->{cmap} if defined $plot->{cmap};
Branch: 1 branch
BranchTrueFalseTotal
if defined $plot->{"cmap"} 3 35 38
310 35 ▶ return $native ? undef : $matplotlib_default;
Branch: 1 branch
BranchTrueFalseTotal
$native ? : 25 10 35
311 }
312 # What thin_tics and palette need to place tics the way matplotlib's default
313 # locator, MaxNLocator(nbins = 'auto', steps = [1, 2, 2.5, 5, 10]), places them
314 # (matplotlib 3.11.2, ticker.py and axis.py): as many intervals as fit one
315 # tick label every 3 label heights along x, or every 2 along y
316 # (Axis.get_tick_space), at most 9, each a step of 1, 2, 2.5 or 5 times a power
317 # of 10.
318 25 ▶sub plot_length {
Subroutine plot_length: called CC=2 SCAR=6.9
Pod undocumented
319 # The length in points of a small subplot's axes along x or y: the
320 # subplot, less the margins gnuplot gives its tic labels, axis label and
321 # title, which are about 0.8 inch across and 0.7 inch down at this font
322 # size, as measured on the PNG terminal.
323 25 my ($axis) = @_;
324 25 ▶ return 72 * ( ( $axis eq 'x' ) ? $panel_w - 0.8 : $panel_h - 0.7 );
Branch: 1 branch
BranchTrueFalseTotal
$axis eq 'x' ? : 11 14 25
325 }
326 22 ▶sub tick_bins {
Subroutine tick_bins: called CC=3 SCAR=11.7
Pod undocumented
327 # How many intervals of tics fit an axis this many points long, with a
328 # label every $per label heights; at least 1, at most 9.
329 22 my ( $length, $per ) = @_;
330 22 my $n = int( $length / ( 10 * $per ) ); # 10: matplotlib's tick labels are 10 points (rcParams xtick.labelsize)
331 22 ▶ return $n < 1 ? 1 : $n > 9 ? 9 : $n;
Branch: 2 branches
BranchTrueFalseTotal
$n < 1 ? : 0 22 22
$n > 9 ? : 0 22 22
332 }
333 22 ▶sub tick_step {
Subroutine tick_step: called CC=8 SCAR=24.9
Pod undocumented
334 # The least step of 1, 2, 2.5, 5 or 10 times a power of 10 that covers
335 # $lo .. $hi in at most $bins intervals; undef for an empty range.
336 22 my ( $lo, $hi, $bins ) = @_;
337 22 ▶ return undef unless ( defined $lo ) && ( defined $hi ) && is_finite($lo) && is_finite($hi) && ( $hi > $lo );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lo and defined $hi and is_finite($lo) and is_finite($hi) and $hi > $lo 0 22 22
Condition33%4/12
defined $lo and defined $hi and is_finite($lo) and is_finite($hi) and $hi > $lo
!ll&&!rl&&r
0022
defined $lo and defined $hi and is_finite($lo) and is_finite($hi)
!ll&&!rl&&r
0022
defined $lo and defined $hi and is_finite($lo)
!ll&&!rl&&r
0022
defined $lo and defined $hi
!ll&&!rl&&r
0022
MC/DC0%0/5
defined $lo and defined $hi and is_finite($lo) and is_finite($hi) and $hi > $lo
defined $lo defined $hi is_finite($lo) is_finite($hi) $hi > $lo
Truth table16%1/6
A and B and C and D and E
A= defined $loB= defined $hiC= is_finite($lo)D= is_finite($hi)E= $hi > $lo
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
338 22 my $raw = ( $hi - $lo ) / $bins;
339 22 my $power = 10**POSIX::floor( log($raw) / log(10) );
340 22 foreach my $mult ( 1, 2, 2.5, 5, 10 ) {
341 74 my $step = $mult * $power;
342 # the intervals a step this size cuts the range into, at its multiples
343 74 my $n = POSIX::ceil( $hi / $step - 1e-9 ) - POSIX::floor( $lo / $step + 1e-9 );
344 74 ▶ return $step if $n <= $bins;
Branch: 1 branch
BranchTrueFalseTotal
if $n <= $bins 22 52 74
345 }
346 0 return 10 * $power;
347 }
348 26 ▶sub color_scale {
Subroutine color_scale: called CC=8 SCAR=21.4
Pod undocumented
349 # The ends of a color scale from "vmin" and "vmax" (or "cb_min" and
350 # "cb_max", which cb_limits has turned into them) and from the values,
351 # checked as matplotlib's norm_args checks them: a log scale must start
352 # above 0.
353 26 my ( $plot, $values, $log ) = @_;
354 26 cb_limits( $plot, $current_sub );
355 26 foreach my $v ( grep { defined $plot->{$_} } ( 'vmin', 'vmax' ) ) {
356 2 check_numbers( [ $plot->{$v} ], "\"$v\"", $current_sub );
357 }
358 26 my ( $lo, $hi ) = ( $plot->{vmin}, $plot->{vmax} );
359 26 my @finite = finite_values( @{$values} );
360 26 ▶ if ($log) {
Branch: 1 branch
BranchTrueFalseTotal
if ($log) { } 1 25 26
361 1 ▶ $lo = $lo // min( grep { $_ > 0 } @finite );
Condition33%1/3
$lo // &min(grep({$_ > 0;} @finite))
l!l&&r!l&&!r
010
MC/DC0%0/2
$lo // &min(grep({$_ > 0;} @finite))
$lo &min(grep({$_ > 0;} @finite))
Truth table33%1/3
A // B
A= $loB= &min(grep({$_ > 0;} @finite))
ABresult
1X1
011
000
362 1 ▶ die "\"cb_logscale\" needs a color value above 0 to start the scale at, or a \"vmin\" or \"cb_min\" above 0, and $current_sub has neither" unless defined $lo;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lo 0 1 1
363 1 ▶ die "\"cb_logscale\" cannot start at $lo in $current_sub: a log scale needs a minimum above 0" if $lo <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $lo <= 0 0 1 1
364 } else {
365 25 ▶ $lo = $lo // min(@finite);
Condition66%2/3
$lo // &min(@finite)
l!l&&r!l&&!r
1240
MC/DC0%0/2
$lo // &min(@finite)
$lo &min(@finite)
Truth table66%2/3
A // B
A= $loB= &min(@finite)
ABresult
1X1
011
000
366 }
367 26 ▶ $hi = $hi // max(@finite);
Condition66%2/3
$hi // &max(@finite)
l!l&&r!l&&!r
1250
MC/DC0%0/2
$hi // &max(@finite)
$hi &max(@finite)
Truth table66%2/3
A // B
A= $hiB= &max(@finite)
ABresult
1X1
011
000
368 26 return ( $lo, $hi );
369 }
370 230 ▶sub box_rows {
Subroutine box_rows: called CC=2 SCAR=6.9
Pod undocumented
371 # A bar, bin or box as the row of a boxxyerror datablock -- x, y, x low,
372 # x high, y low, y high -- from its position across, its extent across,
373 # and where it starts and ends along, laid across or along x.
374 230 my ( $at, $half, $from, $to, $horizontal ) = @_;
375 230 ▶ return $horizontal ? [ ( $from + $to ) / 2, $at, $from, $to, $at - $half, $at + $half ] : [ $at, ( $from + $to ) / 2, $at - $half, $at + $half, $from, $to ];
Branch: 1 branch
BranchTrueFalseTotal
$horizontal ? : 16 214 230
376 }
377 39 ▶sub boxes_clause {
Subroutine boxes_clause: called CC=4 SCAR=14.2
Pod undocumented
378 # A plot clause drawing boxxyerror rows filled in one color.
379 39 my ( $block, $color, $title, $border ) = @_;
380 39 ▶ return () unless defined $block;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $block 0 39 39
381 # A color's alpha is the density of a transparent fill: given in the
382 # color itself, the fill was drawn opaque.
383 39 ▶ my $fill = ( length $color == 9 ) ? sprintf( 'transparent solid %.3f', hex( substr $color, 7, 2 ) / 255 ) : 'solid 1.0';
Branch: 1 branch
BranchTrueFalseTotal
length $color == 9 ? : 13 26 39
384 39 ▶ return "$block using 1:2:3:4:5:6 with boxxyerror fs $fill " . ( $border ? 'border lc rgb "black"' : 'noborder' ) . ' lc rgb ' . gp_str( substr $color, 0, 7 ) . " $title";
Branch: 1 branch
BranchTrueFalseTotal
$border ? : 0 39 39
385 }
386  
387 1 ▶sub log_base {
Subroutine log_base: called CC=2 SCAR=7.2
Pod undocumented
388 # Where a bar on a log axis starts, having no 0 to start at: the power of
389 # 10 below the least of the tops, strictly, so that the least bar has a
390 # height; 0.1 if there is none above 0.
391 1 ▶ my $least = ( scalar @_ ) ? min(@_) : 1;
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ ? : 1 0 1
392 1 return 10**( POSIX::ceil( log($least) / log(10) - 1e-12 ) - 1 ); # 1e-12: so that log10(1000) read as 2.9999999999999996 is 3
393 }
394 2 ▶sub log_bar_range {
Subroutine log_bar_range: called CC=4 SCAR=14.0
Pod undocumented
395 # The range of a bar plot's log axis, as ( $bottom, $top ), and so where
396 # its bars start: matplotlib's autoscaling of the values above 0 -- the
397 # bars' tops, and the feet of stacked ones -- with its 5% margin
398 # (rcParams axes.ymargin) either side taken in decades, and a single value
399 # widened by a decade each way first, as LogLocator.nonsingular widens it.
400 # matplotlib draws a bar from 0, cut off where the axis starts; a bar of
401 # the least value is a sliver, not nothing.
402 #
403 # Under style => 'native' the bars start at log_base and gnuplot chooses the
404 # range, out to the decades on either side: ( log_base, undef ).
405 2 my @v = grep { $_ > 0 } @_;
406 2 ▶ return ( log_base(@v), undef ) if $native;
Branch: 1 branch
BranchTrueFalseTotal
if $native 1 1 2
407 1 ▶ return ( 0.1, 10 ) if scalar @v == 0; # nothing above 0: one decade either side of 1, where matplotlib leaves an empty log axis
Branch: 1 branch
BranchTrueFalseTotal
if scalar @v == 0 0 1 1
408 1 my ( $lo, $hi ) = map { log($_) / log(10) } ( min(@v), max(@v) );
409 1 ▶ ( $lo, $hi ) = ( $lo - 1, $hi + 1 ) if $lo == $hi;
Branch: 1 branch
BranchTrueFalseTotal
if $lo == $hi 0 1 1
410 1 my $margin = 0.05 * ( $hi - $lo );
411 1 return ( 10**( $lo - $margin ), 10**( $hi + $margin ) );
412 }
413 11 ▶sub category_range {
Subroutine category_range: called CC=4 SCAR=13.9
Pod undocumented
414 # The axis of boxes or violins at 1 .. n, from half a category below the
415 # first to half above the last, as matplotlib sets it.
416 # Under style => 'native', nothing: gnuplot's own autoscaling.
417 11 my ( $g, $n, $horizontal ) = @_;
418 11 ▶ return if $native;
Branch: 1 branch
BranchTrueFalseTotal
if $native 0 11 11
419 11 ▶ my $axis = $horizontal ? 'y' : 'x';
Branch: 1 branch
BranchTrueFalseTotal
$horizontal ? : 3 8 11
420 11 push @{ $g->{set} }, "set ${axis}range [0.5:" . gp_num( $n + 0.5 ) . ']';
421 11 ▶ push @{ $g->{no_margin} }, $horizontal ? ( 'top', 'bottom' ) : ( 'left', 'right' );
Branch: 1 branch
BranchTrueFalseTotal
$horizontal ? : 3 8 11
422 }
423 16 ▶sub key_place {
Subroutine key_place: called CC=12 SCAR=25.1
Pod undocumented
424 # The corner of the axes for the legend that covers the fewest data,
425 # trying them in the order matplotlib's "best" does: upper right, upper
426 # left, lower left, lower right. Each corner is the third of the axes'
427 # width and height nearest it.
428 16 ▶ my @p = grep { is_finite( $_->[0] ) && is_finite( $_->[1] ) } map { [ map { looks_like_number($_) ? $_ : 'nan' } @{$_} ] } @points;
Branch: 1 branch
BranchTrueFalseTotal
&looks_like_number($_) ? : 1308 0 1308
Condition33%1/3
is_finite($_->[0]) && is_finite($_->[1])
!ll&&!rl&&r
00654
MC/DC0%0/2
is_finite($_->[0]) && is_finite($_->[1])
is_finite($_->[0]) is_finite($_->[1])
Truth table33%1/3
A && B
A= is_finite($_->[0])B= is_finite($_->[1])
ABresult
0X0
100
111
429 16 ▶ return 'top right' if scalar @p == 0;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @p == 0 0 16 16
430 16 my ( $x0, $x1 ) = ( min( map { $_->[0] } @p ), max( map { $_->[0] } @p ) );
431 16 my ( $y0, $y1 ) = ( min( map { $_->[1] } @p ), max( map { $_->[1] } @p ) );
432 16 ▶ my ( $w, $h ) = ( ( $x1 - $x0 ) || 1, ( $y1 - $y0 ) || 1 );
Condition50%2/4
$x1 - $x0 || 1
l!l
160
$y1 - $y0 || 1
l!l
160
MC/DC0%0/1
$x1 - $x0 || 1
$x1 - $x0
MC/DC0%0/1
$y1 - $y0 || 1
$y1 - $y0
Truth table50%1/2
A
A= $x1 - $x0
Aresult
11
00
Truth table50%1/2
A
A= $y1 - $y0
Aresult
11
00
433 16 my @corners = ( [ 'top right', 1, 1 ], [ 'top left', 0, 1 ], [ 'bottom left', 0, 0 ], [ 'bottom right', 1, 0 ] );
434 16 my ( $best, $fewest );
435 16 foreach my $corner (@corners) {
436 64 my ( $name, $right, $top ) = @{$corner};
437 my $n = grep {
438 64 my $fx = ( $_->[0] - $x0 ) / $w;
439 2616 my $fy = ( $_->[1] - $y0 ) / $h;
440 2616 ▶ ( $right ? $fx >= 2 / 3 : $fx <= 1 / 3 ) && ( $top ? $fy >= 2 / 3 : $fy <= 1 / 3 );
Branch: 2 branches
BranchTrueFalseTotal
$right ? : 1308 1308 2616
$top ? : 430 430 860
Condition100%3/3
($right ? $fx >= 0.66666666666666662966 : $fx <= 0.33333333333333331483) && ($top ? $fy >= 0.66666666666666662966 : $fy <= 0.33333333333333331483)
!ll&&!rl&&r
1756537323
MC/DC100%2/2
($right ? $fx >= 0.66666666666666662966 : $fx <= 0.33333333333333331483) && ($top ? $fy >= 0.66666666666666662966 : $fy <= 0.33333333333333331483)
($right ? $fx >= 0.66666666666666662966 : $fx <= 0.33333333333333331483) ($top ? $fy >= 0.66666666666666662966 : $fy <= 0.33333333333333331483)
Truth table100%3/3
A && B
A= ($right ? $fx >= 0.66666666666666662966 : $fx <= 0.33333333333333331483)B= ($top ? $fy >= 0.66666666666666662966 : $fy <= 0.33333333333333331483)
ABresult
0X0
100
111
441 } @p;
442 64 ▶ ( $best, $fewest ) = ( $name, $n ) if ( not defined $fewest ) || ( $n < $fewest );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $fewest or $n < $fewest 30 34 64
Condition100%3/3
not defined $fewest or $n < $fewest
l!l&&r!l&&!r
161434
MC/DC100%2/2
not defined $fewest or $n < $fewest
not defined $fewest $n < $fewest
Truth table100%3/3
not(A) or B
A= not defined $fewestB= $n < $fewest
ABresult
1X1
011
000
443 }
444 16 return $best;
445 }
446 51 ▶sub draw_bar {
Subroutine draw_bar: called CC=70 SCAR=51.0
Pod undocumented
447 # bar and barh: one bar per key, or one group of bars per key, side by
448 # side or stacked, as barplot_helper draws them.
449 51 my ( $plot, $axes ) = @_;
450 51 ▶ my $horizontal = ( $plot->{plot_type} eq 'barh' ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$plot->{'plot_type'} eq 'barh' ? : 6 45 51
451 51 my $data = $plot->{data};
452 51 my %ref_counts;
453 51 $ref_counts{ ref $data->{$_} }++ foreach keys %{$data};
454 51 ▶ if ( scalar keys %ref_counts > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %ref_counts > 1) 0 51 51
455 0 die "different kinds of data were entered to $current_sub which should be simple hash or hash of arrays.";
456 }
457 51 ▶ my $form = defined $ref_counts{''} ? 'simple' : ( defined $ref_counts{ARRAY} || defined $ref_counts{HASH} ) ? 'grouped' : die "$current_sub: \"data\" is a hash of numbers, of arrays, or of hashes for $plot->{plot_type}";
Branch: 2 branches
BranchTrueFalseTotal
defined $ref_counts{''} ? : 33 18 51
defined $ref_counts{'ARRAY'} || defined $ref_counts{'HASH'} ? : 18 0 18
Condition66%2/3
defined $ref_counts{"ARRAY"} or defined $ref_counts{"HASH"}
l!l&&r!l&&!r
5130
MC/DC0%0/2
defined $ref_counts{"ARRAY"} or defined $ref_counts{"HASH"}
defined $ref_counts{"ARRAY"} defined $ref_counts{"HASH"}
Truth table66%2/3
A or B
A= defined $ref_counts{"ARRAY"}B= defined $ref_counts{"HASH"}
ABresult
1X1
011
000
458 51 my ( @series, $colors );
459 51 ▶ if ( defined $ref_counts{HASH} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $ref_counts{'HASH'}) { } 13 38 51
elsif ($form eq 'grouped') { } 5 33 38
460 # The inner keys are the series, as in barplot_helper.
461 13 @series = bar_series({ plot => $plot, sub => $current_sub });
462 9 $data = { map { my $k = $_; $k => [ @{ $data->{$k} }{@series} ] } keys %{$data} };
463 9 ▶ if ( ref $plot->{color} eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $plot->{"color"} eq "HASH") 0 9 9
464 0 my @uncolored = grep { not defined $plot->{color}{$_} } @series;
465 0 ▶ die 'the series ' . join( ', ', map { "\"$_\"" } @uncolored ) . " have no color defined in \"color\" in $current_sub" if scalar @uncolored;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @uncolored 0 0 0
466 0 $colors = [ @{ $plot->{color} }{@series} ];
467 }
468 } elsif ( $form eq 'grouped' ) {
469 5 ▶ if ( ref $plot->{color} eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $plot->{"color"} eq "HASH") 0 5 5
470 0 die "$current_sub: \"color\" is a HASH, but this data is a hash of arrays, whose series have no names to key it by: give one color per series as an array, e.g. color => ['red','blue']";
471 }
472 5 ▶ if ( defined $plot->{label} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $plot->{"label"}) 1 4 5
473 1 ▶ die "\"label\" is an array of one name per series in $current_sub" unless ref $plot->{label} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $plot->{"label"} eq "ARRAY" 0 1 1
474 1 @series = @{ $plot->{label} };
475 }
476 }
477 47 ▶ $colors = $plot->{color} if ( not defined $colors ) && ( ref $plot->{color} eq 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $colors and ref $plot->{"color"} eq "ARRAY" 0 47 47
Condition33%1/3
not defined $colors and ref $plot->{"color"} eq "ARRAY"
!ll&&!rl&&r
0470
MC/DC0%0/2
not defined $colors and ref $plot->{"color"} eq "ARRAY"
not defined $colors ref $plot->{"color"} eq "ARRAY"
Truth table33%1/3
not(A) and B
A= not defined $colorsB= ref $plot->{"color"} eq "ARRAY"
ABresult
0X0
100
111
478 47 my $stacked = bool_option( $plot->{stacked}, 'stacked', $current_sub );
479 47 ▶ if ( defined $plot->{width} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $plot->{"width"}) 1 46 47
480 1 ▶ die "\"width\" is one number for every bar in $current_sub, not a " . ref( $plot->{width} ) . ' reference' if ref $plot->{width};
Branch: 1 branch
BranchTrueFalseTotal
if ref $plot->{"width"} 0 1 1
481 1 check_numbers( [ $plot->{width} ], '"width"', $current_sub );
482 1 ▶ die "\"width\" must be a finite number for $current_sub, not \"$plot->{width}\"" unless is_finite( $plot->{width} );
Branch: 1 branch
BranchTrueFalseTotal
unless is_finite($plot->{"width"}) 0 1 1
483 }
484 47 ▶ if ( ( $form eq 'grouped' ) && ( defined $plot->{width} ) && ( not $stacked ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($form eq "grouped" and defined $plot->{"width"} and not $stacked) 1 46 47
Condition83%5/6
$form eq "grouped" and defined $plot->{"width"} and not $stacked
!ll&&!rl&&r
4601
$form eq "grouped" and defined $plot->{"width"}
!ll&&!rl&&r
33131
MC/DC66%2/3
$form eq "grouped" and defined $plot->{"width"} and not $stacked
$form eq "grouped" defined $plot->{"width"} not $stacked
Truth table75%3/4
A and B and not(C)
A= $form eq "grouped"B= defined $plot->{"width"}C= not $stacked
ABCresult
0XX0
10X0
1100
1111
485 # Left out, as the matplotlib engine leaves it: it was said to be
486 # ignored, and then divided among the series all the same.
487 1 say STDERR 'grouped, non-stacked barplots ignore width settings';
488 1 delete $plot->{width};
489 }
490 47 my @keys = key_order_of( $plot, $data );
491 47 foreach my $key (@keys) {
492 80 ▶ my @values = ( $form eq 'simple' ) ? ( $data->{$key} ) : @{ $data->{$key} };
Branch: 1 branch
BranchTrueFalseTotal
$form eq 'simple' ? : 61 19 80
493 80 ▶ my @bad = grep { ( defined $_ ) && ( not looks_like_number($_) ) } @values;
Condition33%1/3
defined $_ && !&looks_like_number($_)
!ll&&!rl&&r
0990
MC/DC0%0/2
defined $_ && !&looks_like_number($_)
defined $_ !&looks_like_number($_)
Truth table33%1/3
A && not(B)
A= defined $_B= !&looks_like_number($_)
ABresult
0X0
100
111
494 80 ▶ die 'the values "' . join( '", "', @bad ) . "\" of \"$key\" are not numbers, which $current_sub needs" if scalar @bad;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @bad 0 80 80
495 80 ▶ die "\"$key\" has an undefined value, which $current_sub cannot plot" if ( $form eq 'simple' ) && ( not defined $data->{$key} );
Branch: 1 branch
BranchTrueFalseTotal
if $form eq "simple" and not defined $data->{$key} 0 80 80
Condition66%2/3
$form eq "simple" and not defined $data->{$key}
!ll&&!rl&&r
19610
MC/DC0%0/2
$form eq "simple" and not defined $data->{$key}
$form eq "simple" not defined $data->{$key}
Truth table66%2/3
A and not(B)
A= $form eq "simple"B= not defined $data->{$key}
ABresult
0X0
100
111
496 }
497 47 ▶ my $log = ( bool_option( $plot->{log}, 'log', $current_sub ) || $plot->{logscale} ) ? 1 : 0; # "logscale" takes Perl truth, as documented
Branch: 1 branch
BranchTrueFalseTotal
bool_option($plot->{'log'}, 'log', $current_sub) || $plot->{'logscale'} ? : 2 45 47
Condition66%2/3
bool_option($plot->{"log"}, "log", $current_sub) or $plot->{"logscale"}
l!l&&r!l&&!r
2045
MC/DC50%1/2
bool_option($plot->{"log"}, "log", $current_sub) or $plot->{"logscale"}
bool_option($plot->{"log"}, "log", $current_sub) $plot->{"logscale"}
Truth table66%2/3
A or B
A= bool_option($plot->{"log"}, "log", $current_sub)B= $plot->{"logscale"}
ABresult
1X1
011
000
498 47 ▶ my $value_axis = $horizontal ? 'x' : 'y';
Branch: 1 branch
BranchTrueFalseTotal
$horizontal ? : 6 41 47
499 47 my %g = ( set => [], plot => [] );
500 47 ▶ push @{ $g{set} }, "set logscale $value_axis" if $log;
Branch: 1 branch
BranchTrueFalseTotal
if $log 2 45 47
501 47 my ( @bars, @tic_at );
502 47 ▶ if ( $form eq 'simple' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($form eq 'simple') { } 33 14 47
503 33 my @v = map { 0 + $data->{$_} } @keys;
504 33 my $base = 0;
505 33 ▶ if ($log) {
Branch: 1 branch
BranchTrueFalseTotal
if ($log) 2 31 33
506 2 ( $base, my $top ) = log_bar_range(@v);
507 2 ▶ push @{ $g{set} }, "set ${value_axis}range [" . gp_num($base) . ':' . gp_num($top) . ']' if defined $top;
Branch: 1 branch
BranchTrueFalseTotal
if defined $top 1 1 2
508 }
509 33 ▶ my $half = ( $plot->{width} // 0.8 ) / 2;
Condition50%1/2
$plot->{"width"} // "0.8"
l!l
033
MC/DC0%0/1
$plot->{"width"} // "0.8"
$plot->{"width"}
Truth table50%1/2
A
A= $plot->{"width"}
Aresult
11
00
510 33 my @colors;
511 33 ▶ if ( ref $plot->{color} eq 'HASH' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $plot->{'color'} eq 'HASH') { } 1 32 33
elsif (ref $plot->{'color'} eq 'ARRAY') { } 0 32 32
512 1 my @uncolored = grep { not defined $plot->{color}{$_} } @keys;
513 0 ▶ die 'the keys ' . join( ', ', map { "\"$_\"" } @uncolored ) . ' were not defined in the colors hash' if scalar @uncolored;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @uncolored 0 1 1
514 1 @colors = map { hex_of( $plot->{color}{$_}, "\"color\" of \"$_\"" ) } @keys;
515 } elsif ( ref $plot->{color} eq 'ARRAY' ) {
516 0 ▶ die "\"color\" is an empty array in $current_sub" if scalar @{ $plot->{color} } == 0;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$plot->{"color"};} == 0 0 0 0
517 0 @colors = map { hex_of( $plot->{color}[ $_ % @{ $plot->{color} } ], '"color"' ) } 0 .. $#keys; # matplotlib cycles a short list
518 } else {
519 32 ▶ my $one = defined $plot->{color} ? hex_of( $plot->{color}, '"color"' ) : next_color( $axes, 'patches' );
Branch: 1 branch
BranchTrueFalseTotal
defined $plot->{'color'} ? : 2 30 32
520 31 @colors = ($one) x @keys;
521 }
522 32 ▶ my @rows = map { [ @{ box_rows( $_, $half, $base, $v[$_], $horizontal ) }, color_int( $colors[$_] ) ] } grep { ( not $log ) || ( $v[$_] > 0 ) } 0 .. $#keys;
Condition66%2/3
!$log || $v[$_] > 0
l!l&&r!l&&!r
5640
MC/DC0%0/2
!$log || $v[$_] > 0
!$log $v[$_] > 0
Truth table66%2/3
not(A) || B
A= !$logB= $v[$_] > 0
ABresult
1X1
011
000
523 32 my $block = datablock( \@rows );
524 32 ▶ push @{ $g{plot} }, "$block using 1:2:3:4:5:6:7 with boxxyerror fs solid 1.0 noborder lc rgb variable notitle" if defined $block;
Branch: 1 branch
BranchTrueFalseTotal
if defined $block 32 0 32
525 32 @tic_at = 0 .. $#keys;
526 32 push @{ $g{plot} }, error_bars( $plot, \@keys, \@v, $horizontal );
527 } else {
528 14 my $n_series = max( map { scalar @{ $data->{$_} } } @keys );
529 14 my %lengths = map { scalar @{ $data->{$_} } => 1 } @keys;
530 14 ▶ die "the keys of a grouped $plot->{plot_type} hold different numbers of values; every key needs the same number" if scalar keys %lengths > 1;
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %lengths > 1 0 14 14
531 14 ▶ die "every key of \"data\" holds an empty array, so $current_sub has no bars to draw" if $n_series == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $n_series == 0 0 14 14
532 14 foreach my $err ( grep { defined $plot->{$_} } ( 'xerr', 'yerr' ) ) {
533 1 die "the gnuplot engine draws \"$err\" only for a bar plot of one bar per key, and this one is grouped";
534 }
535 13 ▶ my $width = $plot->{width} // 0.8;
Condition50%1/2
$plot->{"width"} // "0.8"
l!l
013
MC/DC0%0/1
$plot->{"width"} // "0.8"
$plot->{"width"}
Truth table50%1/2
A
A= $plot->{"width"}
Aresult
11
00
536 13 ▶ $width /= ( $n_series + 1 ) unless $stacked;
Branch: 1 branch
BranchTrueFalseTotal
unless $stacked 4 9 13
537 13 my @bottom = (0) x @keys;
538 13 my @shift = (0) x @keys;
539 13 my @drawn; # [ \@rows, color, label ] of each series
540 13 foreach my $s ( 0 .. $n_series - 1 ) {
541 26 my $color;
542 26 ▶ if ( ( defined $colors ) && ( defined $colors->[$s] ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $colors and defined $colors->[$s]) { } 0 26 26
elsif (defined $plot->{'color'} and not ref $plot->{'color'}) { } 0 26 26
Condition33%1/3
defined $colors and defined $colors->[$s]
!ll&&!rl&&r
2600
MC/DC0%0/2
defined $colors and defined $colors->[$s]
defined $colors defined $colors->[$s]
Truth table33%1/3
A and B
A= defined $colorsB= defined $colors->[$s]
ABresult
0X0
100
111
543 0 $color = hex_of( $colors->[$s], '"color"' );
544 ▶ } elsif ( ( defined $plot->{color} ) && ( not ref $plot->{color} ) ) {
Condition33%1/3
defined $plot->{"color"} and not ref $plot->{"color"}
!ll&&!rl&&r
2600
MC/DC0%0/2
defined $plot->{"color"} and not ref $plot->{"color"}
defined $plot->{"color"} not ref $plot->{"color"}
Truth table33%1/3
A and not(B)
A= defined $plot->{"color"}B= not ref $plot->{"color"}
ABresult
0X0
100
111
545 0 $color = hex_of( $plot->{color}, '"color"' );
546 } else {
547 26 $color = next_color( $axes, 'patches' );
548 }
549 26 my @rows;
550 26 foreach my $i ( 0 .. $#keys ) {
551 36 ▶ my $v = $data->{ $keys[$i] }[$s] // 0; # a missing value is no bar, as in barplot_helper
Condition50%1/2
$$data{$keys[$i]}[$s] // 0
l!l
360
MC/DC0%0/1
$$data{$keys[$i]}[$s] // 0
$$data{$keys[$i]}[$s]
Truth table50%1/2
A
A= $$data{$keys[$i]}[$s]
Aresult
11
00
552 36 ▶ my $from = $stacked ? $bottom[$i] : 0;
Branch: 1 branch
BranchTrueFalseTotal
$stacked ? : 20 16 36
553 36 push @rows, box_rows( $i + $shift[$i], $width / 2, $from, $from + $v, $horizontal );
554 36 ▶ $bottom[$i] += $v if $stacked;
Branch: 1 branch
BranchTrueFalseTotal
if $stacked 20 16 36
555 36 ▶ $shift[$i] += $width unless $stacked;
Branch: 1 branch
BranchTrueFalseTotal
unless $stacked 16 20 36
556 }
557 26 push @drawn, [ \@rows, $color, $series[$s] ];
558 }
559 13 ▶ if ($log) {
Branch: 1 branch
BranchTrueFalseTotal
if ($log) 0 13 13
560 # A log axis has no 0, so a bar starting there starts at the foot of
561 # the axis (log_bar_range), and a bar not above 0 is left out.
562 0 ▶ my ( $from, $to ) = $horizontal ? ( 2, 3 ) : ( 4, 5 );
Branch: 1 branch
BranchTrueFalseTotal
$horizontal ? : 0 0 0
563 0 my ( $base, $top ) = log_bar_range( map { @{$_}[ $from, $to ] } map { @{ $_->[0] } } @drawn );
564 0 ▶ push @{ $g{set} }, "set ${value_axis}range [" . gp_num($base) . ':' . gp_num($top) . ']' if defined $top;
Branch: 1 branch
BranchTrueFalseTotal
if defined $top 0 0 0
565 0 foreach my $series (@drawn) {
566 0 @{ $series->[0] } = grep { $_->[$to] > 0 } @{ $series->[0] };
567 0 $_->[$from] = $base foreach grep { $_->[$from] <= 0 } @{ $series->[0] };
568 }
569 }
570 13 foreach my $series (@drawn) {
571 26 push @{ $g{plot} }, boxes_clause( datablock( $series->[0] ), $series->[1], key_title( $series->[2] ) );
572 26 ▶ $g{legend} = 1 if defined $series->[2];
Branch: 1 branch
BranchTrueFalseTotal
if defined $series->[2] 20 6 26
573 }
574 13 ▶ @tic_at = map { $stacked ? $_ : $_ + ( $n_series - 1 ) * $width / 2 } 0 .. $#keys;
Branch: 1 branch
BranchTrueFalseTotal
$stacked ? : 10 8 18
575 }
576 44 ▶ push @{ $g{set} }, tics( $horizontal ? 'y' : 'x', \@keys, \@tic_at );
Branch: 1 branch
BranchTrueFalseTotal
$horizontal ? : 6 38 44
577 44 ▶ $g{categories} = $horizontal ? 'y' : 'x';
Branch: 1 branch
BranchTrueFalseTotal
$horizontal ? : 6 38 44
578 # matplotlib keeps the bars' base on the axis, with no margin below 0.
579 44 ▶ $g{no_margin} = [ $horizontal ? 'left' : 'bottom' ] unless $log;
Branch: 2 branches
BranchTrueFalseTotal
unless $log 42 2 44
$horizontal ? : 6 36 42
580 44 return \%g;
581 }
582 32 ▶sub error_bars {
Subroutine error_bars: called CC=21 SCAR=41.4
Pod undocumented
583 # The error bars of a bar plot of one bar per key: "yerr" on a bar, "xerr"
584 # on a barh, in any of the shapes barplot_helper takes.
585 32 my ( $plot, $keys, $values, $horizontal ) = @_;
586 32 ▶ my $want = $horizontal ? 'xerr' : 'yerr';
Branch: 1 branch
BranchTrueFalseTotal
$horizontal ? : 1 31 32
587 32 ▶ my $other = $horizontal ? 'yerr' : 'xerr';
Branch: 1 branch
BranchTrueFalseTotal
$horizontal ? : 1 31 32
588 32 ▶ die "the gnuplot engine draws \"$other\" on " . ( $horizontal ? 'a bar plot' : 'a barh plot' ) . " but not on $plot->{plot_type}; give \"$want\"" if defined $plot->{$other};
Branch: 2 branches
BranchTrueFalseTotal
if defined $plot->{$other} 1 31 32
$horizontal ? : 0 1 1
589 31 ▶ return () unless defined $plot->{$want};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $plot->{$want} 30 1 31
590 1 my $err = $plot->{$want};
591 1 my $n = scalar @{$keys};
592 1 my ( @low, @high );
593 1 ▶ if ( ref $err eq '' ) {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $err eq '') { } 0 1 1
elsif (ref $err eq 'ARRAY') { } 0 1 1
elsif (ref $err eq 'HASH') { } 1 0 1
594 0 check_numbers( [$err], "\"$want\"", $current_sub );
595 0 @low = @high = ($err) x $n;
596 } elsif ( ref $err eq 'ARRAY' ) {
597 0 ▶ my @rows = ( grep { ref } @{$err} ) ? @{$err} : ($err);
Branch: 1 branch
BranchTrueFalseTotal
grep({ref $_;} @{$err;}) ? : 0 0 0
598 0 ▶ die "\"$want\" is an array of one error per bar, or of two such arrays (lower, then upper), in $current_sub" if ( scalar @rows > 2 ) || ( grep { ref $_ ne 'ARRAY' } @rows );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @rows > 2 or grep {ref $_ ne "ARRAY";} @rows 0 0 0
Condition0%0/3
scalar @rows > 2 or grep {ref $_ ne "ARRAY";} @rows
l!l&&r!l&&!r
000
MC/DC0%0/2
scalar @rows > 2 or grep {ref $_ ne "ARRAY";} @rows
scalar @rows > 2 grep {ref $_ ne "ARRAY";} @rows
Truth table0%0/3
A or B
A= scalar @rows > 2B= grep {ref $_ ne "ARRAY";} @rows
ABresult
1X1
011
000
599 0 foreach my $row (@rows) {
600 0 ▶ die "\"$want\" has " . scalar( @{$row} ) . " values in a row, but $current_sub has $n bars" if scalar @{$row} != $n;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$row;} != $n 0 0 0
601 0 check_numbers( $row, "\"$want\"", $current_sub );
602 }
603 0 @low = @{ $rows[0] };
604 0 @high = @{ $rows[-1] };
605 } elsif ( ref $err eq 'HASH' ) {
606 1 foreach my $key ( @{$keys} ) {
607 2 my $e = $err->{$key};
608 2 ▶ die "\"$key\" has no \"$want\" in $current_sub" unless defined $e;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $e 0 2 2
609 2 ▶ my @pair = ( ref $e eq 'ARRAY' ) ? @{$e} : ( ref $e eq '' ) ? ( $e, $e ) : ();
Branch: 2 branches
BranchTrueFalseTotal
ref $e eq 'ARRAY' ? : 1 1 2
ref $e eq '' ? : 1 0 1
610 2 ▶ die "$want/$key should be one number, or exactly 2 items: low and high error bars" if scalar @pair != 2;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @pair != 2 0 2 2
611 2 check_numbers( \@pair, "\"$want\" of \"$key\"", $current_sub );
612 2 push @low, $pair[0];
613 2 push @high, $pair[1];
614 }
615 } else {
616 0 die ref($err) . " for $want isn't acceptable";
617 }
618 1 ▶ my @rows = map { $horizontal ? [ $values->[$_], $_, $values->[$_] - $low[$_], $values->[$_] + $high[$_] ] : [ $_, $values->[$_], $values->[$_] - $low[$_], $values->[$_] + $high[$_] ] } 0 .. $n - 1;
Branch: 1 branch
BranchTrueFalseTotal
$horizontal ? : 0 2 2
619 1 my $block = datablock( \@rows );
620 1 ▶ return ( "$block using 1:2:3:4 with " . ( $horizontal ? 'xerrorbars' : 'yerrorbars' ) . ' lc rgb "black" lw 1.5 pt 0 notitle' );
Branch: 1 branch
BranchTrueFalseTotal
$horizontal ? : 0 1 1
621 }
622 26 ▶sub sets_of {
Subroutine sets_of: called CC=2 SCAR=6.9
Pod undocumented
623 # The sets of a boxplot or violin, an array being one set with no name.
624 26 my ($plot) = @_;
625 26 ▶ return ( ref $plot->{data} eq 'ARRAY' ) ? { '' => $plot->{data} } : $plot->{data};
Branch: 1 branch
BranchTrueFalseTotal
ref $plot->{'data'} eq 'ARRAY' ? : 5 21 26
626 }
627 15 ▶sub draw_boxplot {
Subroutine draw_boxplot: called CC=28 SCAR=33.9
Pod undocumented
628 # Boxes from the quartiles, whiskers to the furthest value within 1.5
629 # interquartile ranges, the values beyond them, the median and the mean,
630 # as matplotlib's boxplot draws them with this module's defaults.
631 15 my ( $plot, $axes ) = @_;
632 15 ▶ return draw_boxplot_native( $plot, $axes ) if $native;
Branch: 1 branch
BranchTrueFalseTotal
if $native 7 8 15
633 8 ▶ my $horizontal = ( orientation_of($plot) eq 'horizontal' ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
orientation_of($plot) eq 'horizontal' ? : 2 6 8
634 8 my $sets = sets_of($plot);
635 8 my @keys = key_order_of( $plot, $sets );
636 8 ▶ my %show = map { $_ => bool_option( $plot->{$_} // 1, $_, $current_sub ) } ( 'showcaps', 'showfliers', 'showmeans' );
Condition100%2/2
$plot->{$_} // 1
l!l
222
MC/DC100%1/1
$plot->{$_} // 1
$plot->{$_}
Truth table100%2/2
A
A= $plot->{$_}
Aresult
11
00
637 8 ▶ if ( ref $plot->{color} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $plot->{"color"}) 0 8 8
638 0 die "\"color\" is one color for every box in $current_sub, not a " . ref( $plot->{color} ) . ' reference; give one color per key in "colors", e.g. colors => { A => \'red\' }';
639 }
640 8 my @face;
641 8 ▶ if ( defined $plot->{colors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $plot->{'colors'}) { } 1 7 8
642 1 ▶ die "\"colors\" is a hash of one color per key in $current_sub" unless ref $plot->{colors} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $plot->{"colors"} eq "HASH" 0 1 1
643 1 my @bad = grep { not defined $plot->{colors}{$_} } sort keys %{$sets};
644 0 ▶ die 'the data keys ' . join( ', ', map { "\"$_\"" } @bad ) . ' have no defined color' if scalar @bad;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @bad 0 1 1
645 1 @face = map { hex_of( $plot->{colors}{$_}, "\"colors\" of \"$_\"" ) } @keys;
646 } else {
647 7 ▶ @face = ( defined $plot->{color} ? hex_of( $plot->{color}, '"color"' ) : cycle_color(0) ) x @keys;
Branch: 1 branch
BranchTrueFalseTotal
defined $plot->{'color'} ? : 0 7 7
648 }
649 8 my %g = ( set => [], plot => [] );
650 0 push @{ $g{set} }, "set logscale $_" foreach logscale_axes( $plot->{logscale}, $current_sub );
651 8 my ( @boxes, @medians, @whiskers, @caps, @fliers, @means, @labels );
652 # Half of bxp's default width, 0.15 of the span of the positions, kept
653 # between 0.15 and 0.5 (Axes.bxp in matplotlib 3.11.2); its caps are half
654 # as wide as the box. It was 0.5 for any number of boxes, where matplotlib
655 # draws one box or two 0.15 wide, and three 0.3 wide.
656 8 my $half = max( 0.15, min( 0.5, 0.15 * $#keys ) ) / 2;
657 8 foreach my $i ( 0 .. $#keys ) {
658 17 my $at = $i + 1;
659 17 ▶ my @v = grep { ( defined ) && ( not is_nan($_) ) } @{ $sets->{ $keys[$i] } };
Condition33%1/3
defined $_ && !is_nan($_)
!ll&&!rl&&r
00355
MC/DC0%0/2
defined $_ && !is_nan($_)
defined $_ !is_nan($_)
Truth table33%1/3
A && not(B)
A= defined $_B= !is_nan($_)
ABresult
0X0
100
111
660 17 my @bad = grep { not looks_like_number($_) } @v;
661 17 ▶ die "$keys[$i] has non-numeric values" if scalar @bad;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @bad 0 17 17
662 17 push @labels, "$keys[$i] (" . format_commas( scalar @v ) . ')';
663 17 ▶ next if scalar @v == 0;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @v == 0 0 17 17
664 17 my @s = sort { $a <=> $b } @v;
665 17 my ( $q1, $med, $q3 ) = map { percentile( \@s, $_ ) } ( 25, 50, 75 );
666 17 my $iqr = $q3 - $q1;
667 17 my ($lo) = grep { $_ >= $q1 - 1.5 * $iqr } @s;
668 17 my ($hi) = reverse grep { $_ <= $q3 + 1.5 * $iqr } @s;
669 17 push @boxes, [ @{ box_rows( $at, $half, $q1, $q3, $horizontal ) }, color_int( $face[$i] ) ];
670 17 ▶ my $seg = sub { my ( $a1, $b1, $a2, $b2 ) = @_; return $horizontal ? [ $b1, $a1, $b2 - $b1, $a2 - $a1 ] : [ $a1, $b1, $a2 - $a1, $b2 - $b1 ] };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$horizontal ? : 10 75 85
671 17 push @medians, $seg->( $at - $half, $med, $at + $half, $med );
672 17 push @whiskers, $seg->( $at, $q1, $at, $lo ), $seg->( $at, $q3, $at, $hi );
673 17 ▶ push @caps, $seg->( $at - $half / 2, $lo, $at + $half / 2, $lo ), $seg->( $at - $half / 2, $hi, $at + $half / 2, $hi ) if $show{showcaps};
Branch: 1 branch
BranchTrueFalseTotal
if $show{"showcaps"} 17 0 17
674 17 ▶ push @fliers, map { $horizontal ? [ $_, $at ] : [ $at, $_ ] } grep { ( $_ < $lo ) || ( $_ > $hi ) } @s if $show{showfliers};
Branch: 2 branches
BranchTrueFalseTotal
if $show{"showfliers"} 16 1 17
$horizontal ? : 0 2 2
Condition66%2/3
$_ < $lo || $_ > $hi
l!l&&r!l&&!r
02348
MC/DC50%1/2
$_ < $lo || $_ > $hi
$_ < $lo $_ > $hi
Truth table66%2/3
A || B
A= $_ < $loB= $_ > $hi
ABresult
1X1
011
000
675 17 my $mean = sum(@s) / @s;
676 17 ▶ push @means, $horizontal ? [ $mean, $at ] : [ $at, $mean ] if $show{showmeans};
Branch: 2 branches
BranchTrueFalseTotal
if $show{"showmeans"} 16 1 17
$horizontal ? : 2 14 16
677 }
678 8 my $block = datablock( \@boxes );
679 8 ▶ push @{ $g{plot} }, "$block using 1:2:3:4:5:6:7 with boxxyerror fs solid 1.0 border lc rgb \"black\" lc rgb variable notitle" if defined $block;
Branch: 1 branch
BranchTrueFalseTotal
if defined $block 8 0 8
680 8 foreach my $lines ( [ \@whiskers, 'black' ], [ \@caps, 'black' ], [ \@medians, cycle_color(1) ] ) {
681 24 my $b = datablock( $lines->[0] );
682 24 ▶ push @{ $g{plot} }, "$b using 1:2:3:4 with vectors nohead lc rgb " . gp_color( $lines->[1] =~ m/^#/ ? $lines->[1] : hex_of( $lines->[1], 'a line' ) ) . ' lw 1 notitle' if defined $b;
Branch: 2 branches
BranchTrueFalseTotal
if defined $b 24 0 24
$lines->[1] =~ /^#/ ? : 8 16 24
683 }
684 8 my $b = datablock( \@fliers );
685 8 ▶ push @{ $g{plot} }, "$b using 1:2 with points pt 6 ps $point_size lc rgb \"black\" notitle" if defined $b;
Branch: 1 branch
BranchTrueFalseTotal
if defined $b 2 6 8
686 8 $b = datablock( \@means );
687 8 ▶ push @{ $g{plot} }, "$b using 1:2 with points pt 9 ps $point_size lc rgb " . gp_color( cycle_color(2) ) . ' notitle' if defined $b;
Branch: 1 branch
BranchTrueFalseTotal
if defined $b 7 1 8
688 8 ▶ push @{ $g{set} }, tics( $horizontal ? 'y' : 'x', \@labels, [ 1 .. scalar @keys ] );
Branch: 1 branch
BranchTrueFalseTotal
$horizontal ? : 2 6 8
689 8 ▶ $g{categories} = $horizontal ? 'y' : 'x';
Branch: 1 branch
BranchTrueFalseTotal
$horizontal ? : 2 6 8
690 8 category_range( \%g, scalar @keys, $horizontal );
691 8 return \%g;
692 }
693 5 ▶sub kde {
Subroutine kde: called CC=1 SCAR=0.0
Pod undocumented
694 # Gaussian kernel density of sorted values at 100 points from the least to
695 # the greatest, with Scott's bandwidth factor, n ** (-1/5), times the
696 # standard deviation with n - 1 below the line: matplotlib.mlab.GaussianKDE,
697 # which violinplot uses, evaluated as violin_stats does.
698 5 my ($s) = @_;
699 5 my $n = scalar @{$s};
700 5 my $mean = sum( @{$s} ) / $n;
701 5 my $sd = sqrt( sum( map { ( $_ - $mean )**2 } @{$s} ) / ( $n - 1 ) );
702 5 my $h = $sd * $n**( -1 / 5 );
703 5 my ( $lo, $hi ) = ( $s->[0], $s->[-1] );
704 5 my $norm = 1 / ( $n * $h * sqrt( 8 * atan2( 1, 1 ) ) );
705 5 my @at = linspace( $lo, $hi, 100 ); # violin_stats's np.linspace(min, max, 100)
706 5 return ( \@at, [ map { my $y = $_; $norm * sum( map { exp( -0.5 * ( ( $y - $_ ) / $h )**2 ) } @{$s} ) } @at ] );
707 }
708 12 ▶sub draw_violin {
Subroutine draw_violin: called CC=24 SCAR=34.4
Pod undocumented
709 # Violins as matplotlib's violinplot draws them here: the density, its
710 # extremes and median, the quartile box and whiskers, and the mean.
711 12 my ( $plot, $axes ) = @_;
712 12 ▶ return draw_violin_native( $plot, $axes ) if $native;
Branch: 1 branch
BranchTrueFalseTotal
if $native 8 4 12
713 4 ▶ my $horizontal = ( orientation_of($plot) eq 'horizontal' ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
orientation_of($plot) eq 'horizontal' ? : 1 3 4
714 4 my $sets = sets_of($plot);
715 4 my @keys = key_order_of( $plot, $sets );
716 4 ▶ my $medians = bool_option( $plot->{medians} // 1, 'medians', $current_sub );
Condition50%1/2
$plot->{"medians"} // 1
l!l
04
MC/DC0%0/1
$plot->{"medians"} // 1
$plot->{"medians"}
Truth table50%1/2
A
A= $plot->{"medians"}
Aresult
11
00
717 4 ▶ my $whiskers = bool_option( $plot->{whiskers} // 1, 'whiskers', $current_sub );
Condition50%1/2
$plot->{"whiskers"} // 1
l!l
04
MC/DC0%0/1
$plot->{"whiskers"} // 1
$plot->{"whiskers"}
Truth table50%1/2
A
A= $plot->{"whiskers"}
Aresult
11
00
718 4 ▶ if ( ref $plot->{color} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $plot->{"color"}) 0 4 4
719 0 die "\"color\" is one color for every violin in $current_sub, not a " . ref( $plot->{color} ) . ' reference; give one color per key in "colors", e.g. colors => { A => \'red\' }';
720 }
721 4 ▶ my $edge = hex_of( $plot->{edgecolor} // 'black', '"edgecolor"' );
Condition50%1/2
$plot->{"edgecolor"} // "black"
l!l
04
MC/DC0%0/1
$plot->{"edgecolor"} // "black"
$plot->{"edgecolor"}
Truth table50%1/2
A
A= $plot->{"edgecolor"}
Aresult
11
00
722 4 my @face;
723 4 ▶ if ( defined $plot->{colors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $plot->{'colors'}) { } 0 4 4
724 0 ▶ die "\"colors\" is a hash of one color per key in $current_sub" unless ref $plot->{colors} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $plot->{"colors"} eq "HASH" 0 0 0
725 0 my @bad = grep { not defined $plot->{colors}{$_} } sort keys %{$sets};
726 0 ▶ die 'the data keys ' . join( ', ', map { "\"$_\"" } @bad ) . ' have no defined color' if scalar @bad;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @bad 0 0 0
727 0 @face = map { hex_of( $plot->{colors}{$_}, "\"colors\" of \"$_\"" ) } @keys;
728 } else {
729 4 ▶ @face = ( defined $plot->{color} ? hex_of( $plot->{color}, '"color"' ) : cycle_color(0) ) x @keys;
Branch: 1 branch
BranchTrueFalseTotal
defined $plot->{'color'} ? : 0 4 4
730 }
731 4 my %g = ( set => [], plot => [] );
732 0 push @{ $g{set} }, "set logscale $_" foreach logscale_axes( $plot->{logscale}, $current_sub );
733 4 ▶ my $xy = sub { my ( $at, $v ) = @_; return $horizontal ? ( $v, $at ) : ( $at, $v ) };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$horizontal ? : 213 852 1065
734 4 my ( @lines, @quartiles, @whisk, @means, @labels );
735 4 foreach my $i ( 0 .. $#keys ) {
736 6 my $key = $keys[$i];
737 6 my $at = $i + 1;
738 6 ▶ my @v = grep { ( defined ) && looks_like_number($_) && ( not is_nan($_) ) } @{ $sets->{$key} };
Condition33%2/6
defined $_ && &looks_like_number($_) && !is_nan($_)
!ll&&!rl&&r
00303
defined $_ and &looks_like_number($_)
!ll&&!rl&&r
00303
MC/DC0%0/3
defined $_ && &looks_like_number($_) && !is_nan($_)
defined $_ &looks_like_number($_) !is_nan($_)
Truth table25%1/4
A and B && not(C)
A= defined $_B= &looks_like_number($_)C= !is_nan($_)
ABCresult
0XX0
10X0
1100
1111
739 0 ▶ die "\"$key\" has no numeric values for $current_sub to plot (" . scalar( @{ $sets->{$key} } ) . ' value(s) given, all undefined, NaN or non-numeric)' if scalar @v == 0;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @v == 0 0 6 6
740 6 my @inf = grep { not is_finite($_) } @v;
741 6 ▶ die "\"$key\" has infinite values, which $current_sub cannot draw a density for" if scalar @inf;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @inf 0 6 6
742 6 my @s = sort { $a <=> $b } @v;
743 6 ▶ die "\"$key\" has no spread -- every value is $s[0] -- so $current_sub has no density to draw" if $s[0] == $s[-1];
Branch: 1 branch
BranchTrueFalseTotal
if $s[0] == $s[-1] 1 5 6
744 5 push @labels, "$key (" . format_commas( scalar @s ) . ')';
745 5 my ( $y, $d ) = kde( \@s );
746 5 my $peak = max( @{$d} );
747 5 my @w = map { 0.25 * $_ / $peak } @{$d}; # half of matplotlib's width of 0.5 at the peak
748 5 my @outline = ( ( map { [ $xy->( $at - $w[$_], $y->[$_] ) ] } 0 .. 99 ), ( map { [ $xy->( $at + $w[$_], $y->[$_] ) ] } reverse 0 .. 99 ) );
749 5 push @outline, $outline[0];
750 5 my $body = datablock( \@outline );
751 5 push @{ $g{plot} }, "$body using 1:2 with filledcurves closed fs transparent solid 0.3 noborder lc rgb " . gp_color( substr( $face[$i], 0, 7 ) ) . ' notitle';
752 5 push @{ $g{plot} }, "$body using 1:2 with lines lc rgb " . gp_color( with_alpha( $edge, 0.3 ) ) . ' lw 1 notitle'; # the edge takes the body's alpha, as in matplotlib
753 5 ▶ my $seg = sub { my ( $a1, $v1, $a2, $v2 ) = @_; my @p = $xy->( $a1, $v1 ); my @q = $xy->( $a2, $v2 ); return [ @p, $q[0] - $p[0], $q[1] - $p[1] ] };
Subroutine __ANON__: called CC=1 SCAR=0.0
754 5 push @lines, $seg->( $at - 0.125, $s[0], $at + 0.125, $s[0] ), $seg->( $at - 0.125, $s[-1], $at + 0.125, $s[-1] ), $seg->( $at, $s[0], $at, $s[-1] );
755 5 ▶ push @lines, $seg->( $at - 0.125, percentile( \@s, 50 ), $at + 0.125, percentile( \@s, 50 ) ) if $medians;
Branch: 1 branch
BranchTrueFalseTotal
if $medians 5 0 5
756 5 ▶ if ($whiskers) {
Branch: 1 branch
BranchTrueFalseTotal
if ($whiskers) 5 0 5
757 5 my ( $q1, $q3 ) = map { percentile( \@s, $_ ) } ( 25, 75 );
758 5 my $up = min( max( $q3 + 1.5 * ( $q3 - $q1 ), $q3 ), $s[-1] );
759 5 my $dn = max( min( $q1 - 1.5 * ( $q3 - $q1 ), $q1 ), $s[0] );
760 5 push @quartiles, $seg->( $at, $q1, $at, $q3 );
761 5 push @whisk, $seg->( $at, $dn, $at, $up );
762 }
763 5 push @means, [ $xy->( $at, sum(@s) / @s ) ];
764 }
765 3 foreach my $set ( [ \@lines, cycle_color(0), 1.5 ], [ \@whisk, '#000000', 1 ], [ \@quartiles, '#000000', 5 ] ) {
766 9 my $b = datablock( $set->[0] );
767 9 ▶ push @{ $g{plot} }, "$b using 1:2:3:4 with vectors nohead lc rgb " . gp_color( $set->[1] ) . " lw $set->[2] notitle" if defined $b;
Branch: 1 branch
BranchTrueFalseTotal
if defined $b 9 0 9
768 }
769 3 my $b = datablock( \@means );
770 3 push @{ $g{plot} }, "$b using 1:2 with points pt 7 ps $point_size lc rgb \"#ff0000\" notitle";
771 3 ▶ push @{ $g{set} }, tics( $horizontal ? 'y' : 'x', \@labels, [ 1 .. scalar @keys ] );
Branch: 1 branch
BranchTrueFalseTotal
$horizontal ? : 1 2 3
772 3 ▶ $g{categories} = $horizontal ? 'y' : 'x';
Branch: 1 branch
BranchTrueFalseTotal
$horizontal ? : 1 2 3
773 3 category_range( \%g, scalar @keys, $horizontal );
774 3 return \%g;
775 }
776 # style => 'native': the boxplot, violin and hist that gnuplot computes for
777 # itself. Each set is written as one column of its values, and gnuplot's
778 # "with boxplot", "smooth kdensity" and "bins" work out the quartiles, the
779 # density and the bins from it, with gnuplot's own rules and defaults. The
780 # other types have no statistic of their own in gnuplot -- hist2d's bins, the
781 # mean and spread of "wide", a pie's angles -- and are computed in Perl under
782 # either style.
783 12 ▶sub given_faces {
Subroutine given_faces: called CC=6 SCAR=18.4
Pod undocumented
784 # The colors given for the sets of a boxplot or violin: "colors", one per
785 # key, or one "color" for all, as #rrggbb; ( undef ) x n where none is.
786 12 my ( $plot, $sets, $keys, $what ) = @_;
787 12 ▶ if ( ref $plot->{color} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $plot->{"color"}) 0 12 12
788 0 die "\"color\" is one color for every $what in $current_sub, not a " . ref( $plot->{color} ) . ' reference; give one color per key in "colors", e.g. colors => { A => \'red\' }';
789 }
790 12 ▶ if ( defined $plot->{colors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $plot->{"colors"}) 2 10 12
791 2 ▶ die "\"colors\" is a hash of one color per key in $current_sub" unless ref $plot->{colors} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $plot->{"colors"} eq "HASH" 0 2 2
792 2 my @bad = grep { not defined $plot->{colors}{$_} } sort keys %{$sets};
793 0 ▶ die 'the data keys ' . join( ', ', map { "\"$_\"" } @bad ) . ' have no defined color' if scalar @bad;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @bad 0 2 2
794 2 return map { hex_of( $plot->{colors}{$_}, "\"colors\" of \"$_\"" ) } @{$keys};
795 }
796 10 ▶ return ( defined $plot->{color} ? hex_of( $plot->{color}, '"color"' ) : undef ) x @{$keys};
Branch: 1 branch
BranchTrueFalseTotal
defined $plot->{'color'} ? : 1 9 10
797 }
798 37 ▶sub column_of {
Subroutine column_of: called CC=3 SCAR=11.3
Pod undocumented
799 # The numbers of one set, NaN and undef left out, as a datablock of one
800 # column; dies naming the set if any is not a number.
801 37 my ( $values, $key ) = @_;
802 37 ▶ my @v = grep { ( defined ) && ( not is_nan($_) ) } @{$values};
Condition33%1/3
defined $_ && !is_nan($_)
!ll&&!rl&&r
001791
MC/DC0%0/2
defined $_ && !is_nan($_)
defined $_ !is_nan($_)
Truth table33%1/3
A && not(B)
A= defined $_B= !is_nan($_)
ABresult
0X0
100
111
803 37 my @bad = grep { not looks_like_number($_) } @v;
804 37 ▶ die "$key has non-numeric values" if scalar @bad;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @bad 0 37 37
805 37 return ( datablock( [ map { [$_] } @v ] ), scalar @v );
806 }
807 7 ▶sub draw_boxplot_native {
Subroutine draw_boxplot_native: called CC=12 SCAR=24.9
Pod undocumented
808 # gnuplot's "with boxplot", one per key at 1 .. n: its own quartiles, and
809 # whiskers to the furthest value within 1.5 interquartile ranges ("set
810 # style boxplot range 1.5", its default), and its own outliers.
811 7 my ( $plot, $axes ) = @_;
812 7 ▶ if ( orientation_of($plot) eq 'horizontal' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (orientation_of($plot) eq "horizontal") 1 6 7
813 1 die "$current_sub: gnuplot's boxplot style draws its boxes upright only, so style => 'native' cannot draw orientation => 'horizontal'; style => 'matplotlib' can";
814 }
815 6 my $sets = sets_of($plot);
816 6 my @keys = key_order_of( $plot, $sets );
817 6 my @face = given_faces( $plot, $sets, \@keys, 'box' );
818 # Each as the caller gave it, or as gnuplot draws it: caps on the whiskers
819 # and the outliers, and no mean, which gnuplot's boxplot does not mark.
820 6 ▶ my %show = map { $_ => bool_option( $plot->{$_} // ( $_ eq 'showmeans' ? 0 : 1 ), $_, $current_sub ) } ( 'showcaps', 'showfliers', 'showmeans' );
Branch: 1 branch
BranchTrueFalseTotal
$_ eq 'showmeans' ? : 5 10 15
Condition100%2/2
$plot->{$_} // ($_ eq "showmeans" ? 0 : 1)
l!l
315
MC/DC100%1/1
$plot->{$_} // ($_ eq "showmeans" ? 0 : 1)
$plot->{$_}
Truth table100%2/2
A
A= $plot->{$_}
Aresult
11
00
821 6 my %g = ( set => [], plot => [] );
822 0 push @{ $g{set} }, "set logscale $_" foreach logscale_axes( $plot->{logscale}, $current_sub );
823 6 ▶ push @{ $g{set} }, 'set style boxplot nooutliers' unless $show{showfliers};
Branch: 1 branch
BranchTrueFalseTotal
unless $show{"showfliers"} 1 5 6
824 6 ▶ push @{ $g{set} }, 'set errorbars 0' unless $show{showcaps}; # the caps of the whiskers are gnuplot's error bars ("help boxplot")
Branch: 1 branch
BranchTrueFalseTotal
unless $show{"showcaps"} 1 5 6
825 6 my @labels;
826 6 foreach my $i ( 0 .. $#keys ) {
827 11 my $at = $i + 1;
828 11 my ( $block, $n ) = column_of( $sets->{ $keys[$i] }, $keys[$i] );
829 11 push @labels, "$keys[$i] (" . format_commas($n) . ')';
830 11 ▶ next unless defined $block;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $block 0 11 11
831 11 ▶ my $color = $face[$i] // next_color( $axes, 'patches' );
Condition66%2/3
$face[$i] // next_color($axes, "patches")
l!l&&r!l&&!r
380
MC/DC0%0/2
$face[$i] // next_color($axes, "patches")
$face[$i] next_color($axes, "patches")
Truth table66%2/3
A // B
A= $face[$i]B= next_color($axes, "patches")
ABresult
1X1
011
000
832 11 ▶ my $fill = defined $face[$i] ? 'fs solid 1.0 border lc rgb "black" ' : ''; # a color given fills the box, as matplotlib's does; gnuplot's own is empty
Branch: 1 branch
BranchTrueFalseTotal
defined $face[$i] ? : 3 8 11
833 11 push @{ $g{plot} }, "$block using ($at):1 with boxplot ${fill}lc rgb " . gp_color($color) . ' notitle';
834 11 ▶ if ( $show{showmeans} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($show{"showmeans"}) 2 9 11
835 # The mean as gnuplot's "stats" works it out, marked as matplotlib
836 # marks it, since gnuplot's boxplot has no mark of its own for it.
837 2 push @{ $g{set} }, "stats $block using 1 name \"box$at\" nooutput";
838 2 push @{ $g{plot} }, "$block every ::0::0 using ($at):(box${at}_mean) with points pt 9 lc rgb " . gp_color($color) . ' notitle';
839 }
840 }
841 6 push @{ $g{set} }, tics( 'x', \@labels, [ 1 .. scalar @keys ] );
842 6 $g{categories} = 'x';
843 6 return \%g;
844 }
845 8 ▶sub draw_violin_native {
Subroutine draw_violin_native: called CC=26 SCAR=33.0
Pod undocumented
846 # gnuplot's "smooth kdensity" of each set, with its own bandwidth
847 # ("help kdensity": sigma * (4/3N) ** 0.2), mirrored about the set's place
848 # at 1 .. n, with a narrow "with boxplot" inside for the quartiles and the
849 # median. gnuplot has no violin style: the density is written out with
850 # "set table" and drawn as two filled curves, as gnuplot's own violin demo
851 # (violinplot.dem) builds one. Each is 0.4 either side at its widest, so
852 # that neighbours 1 apart do not touch.
853 8 my ( $plot, $axes ) = @_;
854 8 ▶ my $horizontal = ( orientation_of($plot) eq 'horizontal' ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
orientation_of($plot) eq 'horizontal' ? : 2 6 8
855 8 my $sets = sets_of($plot);
856 8 my @keys = key_order_of( $plot, $sets );
857 8 ▶ my $medians = bool_option( $plot->{medians} // 1, 'medians', $current_sub );
Condition100%2/2
$plot->{"medians"} // 1
l!l
17
MC/DC100%1/1
$plot->{"medians"} // 1
$plot->{"medians"}
Truth table100%2/2
A
A= $plot->{"medians"}
Aresult
11
00
858 8 ▶ my $whiskers = bool_option( $plot->{whiskers} // 1, 'whiskers', $current_sub );
Condition100%2/2
$plot->{"whiskers"} // 1
l!l
17
MC/DC100%1/1
$plot->{"whiskers"} // 1
$plot->{"whiskers"}
Truth table100%2/2
A
A= $plot->{"whiskers"}
Aresult
11
00
859 8 ▶ if ( $whiskers && ( not $medians ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($whiskers and not $medians) 1 7 8
Condition100%3/3
$whiskers and not $medians
!ll&&!rl&&r
161
MC/DC100%2/2
$whiskers and not $medians
$whiskers not $medians
Truth table100%3/3
A and not(B)
A= $whiskersB= not $medians
ABresult
0X0
100
111
860 1 die "$current_sub: under style => 'native' the whiskers are gnuplot's boxplot, which always draws its median, so \"medians\" => 0 with \"whiskers\" cannot be drawn; style => 'matplotlib' can";
861 }
862 7 ▶ if ( $whiskers && $horizontal ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($whiskers and $horizontal) 1 6 7
Condition100%3/3
$whiskers and $horizontal
!ll&&!rl&&r
151
MC/DC100%2/2
$whiskers and $horizontal
$whiskers $horizontal
Truth table100%3/3
A and B
A= $whiskersB= $horizontal
ABresult
0X0
100
111
863 1 die "$current_sub: under style => 'native' the whiskers are gnuplot's boxplot, which draws upright only, so orientation => 'horizontal' needs \"whiskers\" => 0; style => 'matplotlib' draws both";
864 }
865 6 my @face = given_faces( $plot, $sets, \@keys, 'violin' );
866 6 ▶ my $edge = defined $plot->{edgecolor} ? hex_of( $plot->{edgecolor}, '"edgecolor"' ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $plot->{'edgecolor'} ? : 2 4 6
867 6 my %g = ( set => [], plot => [] );
868 0 push @{ $g{set} }, "set logscale $_" foreach logscale_axes( $plot->{logscale}, $current_sub );
869 6 ▶ push @{ $g{set} }, 'set style boxplot nooutliers' if $whiskers; # the violin is the distribution; the boxplot inside shows its middle
Branch: 1 branch
BranchTrueFalseTotal
if $whiskers 5 1 6
870 6 my @labels;
871 6 foreach my $i ( 0 .. $#keys ) {
872 10 my ( $key, $at ) = ( $keys[$i], $i + 1 );
873 10 ▶ my @v = grep { ( defined ) && looks_like_number($_) && ( not is_nan($_) ) } @{ $sets->{$key} };
Condition33%2/6
defined $_ && &looks_like_number($_) && !is_nan($_)
!ll&&!rl&&r
00544
defined $_ and &looks_like_number($_)
!ll&&!rl&&r
00544
MC/DC0%0/3
defined $_ && &looks_like_number($_) && !is_nan($_)
defined $_ &looks_like_number($_) !is_nan($_)
Truth table25%1/4
A and B && not(C)
A= defined $_B= &looks_like_number($_)C= !is_nan($_)
ABCresult
0XX0
10X0
1100
1111
874 0 ▶ die "\"$key\" has no numeric values for $current_sub to plot (" . scalar( @{ $sets->{$key} } ) . ' value(s) given, all undefined, NaN or non-numeric)' if scalar @v == 0;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @v == 0 0 10 10
875 10 ▶ die "\"$key\" has infinite values, which $current_sub cannot draw a density for" if grep { not is_finite($_) } @v;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not is_finite($_);} @v 0 10 10
876 10 ▶ die "\"$key\" has no spread -- every value is $v[0] -- so $current_sub has no density to draw" if min(@v) == max(@v);
Branch: 1 branch
BranchTrueFalseTotal
if &min(@v) == &max(@v) 0 10 10
877 10 push @labels, "$key (" . format_commas( scalar @v ) . ')';
878 10 my $block = datablock( [ map { [$_] } @v ] );
879 10 my $density = '$kd' . $n_blocks++;
880 10 push @{ $g{set} }, "set table $density", "plot $block using 1:(1) smooth kdensity", 'unset table', "stats $density using 2 name \"kd$at\" nooutput";
881 10 ▶ my $color = gp_color( $face[$i] // next_color( $axes, 'patches' ) );
Condition66%2/3
$face[$i] // next_color($axes, "patches")
l!l&&r!l&&!r
280
MC/DC0%0/2
$face[$i] // next_color($axes, "patches")
$face[$i] next_color($axes, "patches")
Truth table66%2/3
A // B
A= $face[$i]B= next_color($axes, "patches")
ABresult
1X1
011
000
882 10 ▶ my $edge_clause = defined $edge ? 'border lc rgb ' . gp_color($edge) . ' ' : 'noborder ';
Branch: 1 branch
BranchTrueFalseTotal
defined $edge ? : 3 7 10
883 10 foreach my $side ( '+', '-' ) {
884 20 my $across = "($at $side 0.4 * \$2 / kd${at}_max)";
885 20 ▶ push @{ $g{plot} }, $horizontal
Branch: 1 branch
BranchTrueFalseTotal
$horizontal ? : 2 18 20
886 ? "$density using 1:$across with filledcurves y=$at fs solid 0.5 ${edge_clause}lc rgb $color notitle"
887 : "$density using $across:1 with filledcurves x=$at fs solid 0.5 ${edge_clause}lc rgb $color notitle";
888 }
889 10 ▶ if ($whiskers) {
Branch: 2 branches
BranchTrueFalseTotal
if ($whiskers) { } 9 1 10
elsif ($medians) { } 1 0 1
890 9 push @{ $g{plot} }, "$block using ($at):1:(0.08) with boxplot fs solid 1.0 lc rgb \"black\" notitle";
891 } elsif ($medians) {
892 1 push @{ $g{set} }, "stats $block using 1 name \"vm$at\" nooutput";
893 1 ▶ my $median = $horizontal ? "(vm${at}_median):($at - 0.1):(0):(0.2)" : "($at - 0.1):(vm${at}_median):(0.2):(0)";
Branch: 1 branch
BranchTrueFalseTotal
$horizontal ? : 1 0 1
894 1 push @{ $g{plot} }, "$block every ::0::0 using $median with vectors nohead lc rgb \"black\" notitle";
895 }
896 }
897 6 ▶ push @{ $g{set} }, tics( $horizontal ? 'y' : 'x', \@labels, [ 1 .. scalar @keys ] );
Branch: 1 branch
BranchTrueFalseTotal
$horizontal ? : 1 5 6
898 6 ▶ $g{categories} = $horizontal ? 'y' : 'x';
Branch: 1 branch
BranchTrueFalseTotal
$horizontal ? : 1 5 6
899 6 return \%g;
900 }
901 19 ▶sub draw_hist_native {
Subroutine draw_hist_native: called CC=25 SCAR=33.9
Pod undocumented
902 # gnuplot's "bins" filter, one histogram per set: its own bin edges
903 # ("help bins": NBINS bins of width (HIGH - LOW) / (NBINS - 1), centered on
904 # the least and the greatest value). With no "bins" given there are 10,
905 # matplotlib's default and the ggplot2 engine's under this style: gnuplot's
906 # own number is "set samples", which is how finely it draws a function, not
907 # a rule for binning, and its 100 left a set of 300 values a row of spikes.
908 19 my ( $plot, $axes ) = @_;
909 19 ▶ if ( orientation_of($plot) eq 'horizontal' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (orientation_of($plot) eq "horizontal") 1 18 19
910 1 die "$current_sub: gnuplot's \"bins\" are drawn upright only, so style => 'native' cannot draw orientation => 'horizontal'; style => 'matplotlib' can";
911 }
912 18 ▶ my $sets = ( ref $plot->{data} eq 'ARRAY' ) ? { A => $plot->{data} } : $plot->{data};
Branch: 1 branch
BranchTrueFalseTotal
ref $plot->{'data'} eq 'ARRAY' ? : 4 14 18
913 18 foreach my $arg ( grep { ref $plot->{$_} eq 'HASH' } ( 'bins', 'color' ) ) {
914 2 my @stray = sort grep { not exists $sets->{$_} } keys %{ $plot->{$arg} };
915 0 ▶ die 'the keys ' . join( ', ', map { "\"$_\"" } @stray ) . " of \"$arg\" are not sets of \"data\" in $current_sub" if scalar @stray;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @stray 0 2 2
916 }
917 18 ▶ if ( ( ref $plot->{color} ) && ( ref $plot->{color} ne 'HASH' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $plot->{"color"} and ref $plot->{"color"} ne "HASH") 0 18 18
Condition66%2/3
ref $plot->{"color"} and ref $plot->{"color"} ne "HASH"
!ll&&!rl&&r
1710
MC/DC0%0/2
ref $plot->{"color"} and ref $plot->{"color"} ne "HASH"
ref $plot->{"color"} ref $plot->{"color"} ne "HASH"
Truth table66%2/3
A and B
A= ref $plot->{"color"}B= ref $plot->{"color"} ne "HASH"
ABresult
0X0
100
111
918 0 die "\"color\" for $current_sub is one color for every set, or a hash of one color per set, not a " . ref( $plot->{color} ) . ' reference';
919 }
920 18 my $alpha = $plot->{alpha}; # undef: gnuplot's own fill, which is none
921 18 ▶ if ( defined $alpha ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $alpha) 1 17 18
922 1 check_numbers( [$alpha], '"alpha"', $current_sub );
923 1 ▶ die "\"alpha\" is from 0 to 1 in $current_sub, not $alpha" if ( $alpha < 0 ) || ( $alpha > 1 );
Branch: 1 branch
BranchTrueFalseTotal
if $alpha < 0 or $alpha > 1 0 1 1
Condition33%1/3
$alpha < 0 or $alpha > 1
l!l&&r!l&&!r
001
MC/DC0%0/2
$alpha < 0 or $alpha > 1
$alpha < 0 $alpha > 1
Truth table33%1/3
A or B
A= $alpha < 0B= $alpha > 1
ABresult
1X1
011
000
924 }
925 18 my @keys = key_order_of( $plot, $sets );
926 18 ▶ my $legend = bool_option( $plot->{show_legend} // ( scalar keys %{$sets} > 1 ? 1 : 0 ), 'show_legend', $current_sub );
Branch: 1 branch
BranchTrueFalseTotal
scalar keys %{$sets;} > 1 ? : 11 7 18
Condition50%1/2
$plot->{"show_legend"} // (scalar keys %{$sets;} > 1 ? 1 : 0)
l!l
018
MC/DC0%0/1
$plot->{"show_legend"} // (scalar keys %{$sets;} > 1 ? 1 : 0)
$plot->{"show_legend"}
Truth table50%1/2
A
A= $plot->{"show_legend"}
Aresult
11
00
927 0 my %g = ( set => [ map { "set logscale $_" } logscale_axes( $plot->{logscale}, $current_sub ) ], plot => [] );
928 18 foreach my $set (@keys) {
929 26 ▶ my @inf = grep { looks_like_number($_) && ( not( is_nan($_) || is_finite($_) ) ) } @{ $sets->{$set} };
Condition33%2/6
&looks_like_number($_) && !(is_nan($_) || is_finite($_))
!ll&&!rl&&r
012870
is_nan($_) || is_finite($_)
l!l&&r!l&&!r
012870
MC/DC0%0/3
&looks_like_number($_) && !(is_nan($_) || is_finite($_))
&looks_like_number($_) is_nan($_) is_finite($_)
Truth table25%1/4
A && not(B || C)
A= &looks_like_number($_)B= is_nan($_)C= is_finite($_)
ABCresult
0XX0
11X0
1010
1001
930 26 ▶ die "$set has infinite values, which $current_sub cannot bin" if scalar @inf;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @inf 0 26 26
931 26 my @bad = grep { not looks_like_number($_) } @{ $sets->{$set} };
932 26 ▶ die "$set has non-numeric values; which for hist must be numeric" if scalar @bad;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @bad 0 26 26
933 26 my ($block) = column_of( $sets->{$set}, $set );
934 26 ▶ next unless defined $block;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $block 0 26 26
935 26 ▶ my $bins = ( ref $plot->{bins} eq 'HASH' ) ? $plot->{bins}{$set} : $plot->{bins};
Branch: 1 branch
BranchTrueFalseTotal
ref $plot->{'bins'} eq 'HASH' ? : 2 24 26
936 26 ▶ my $given = ( ref $plot->{color} eq 'HASH' ) ? $plot->{color}{$set} : $plot->{color};
Branch: 1 branch
BranchTrueFalseTotal
ref $plot->{'color'} eq 'HASH' ? : 2 24 26
937 26 ▶ die "\"color\" for set \"$set\" is an array, but $current_sub draws each set in one color" if ref $given;
Branch: 1 branch
BranchTrueFalseTotal
if ref $given 0 26 26
938 # native_bins checks "bins", so it is asked before native_bin_peak does
939 # arithmetic with it: "bins => 'auto'", numpy's estimator, reached the
940 # arithmetic first and died as "Argument "auto" isn't numeric in
941 # numeric gt (>)" under this file's fatal warnings.
942 26 my $native_bins = native_bins( $bins, $set );
943 20 push @extent, [ undef, 0 ], [ undef, native_bin_peak( $sets->{$set}, $bins ) ];
944 20 ▶ my $color = defined $given ? hex_of( $given, "\"color\" of \"$set\"" ) : next_color( $axes, 'patches' );
Branch: 1 branch
BranchTrueFalseTotal
defined $given ? : 2 18 20
945 20 ▶ my $fill = defined $alpha ? sprintf( 'fs transparent solid %s ', gp_num($alpha) ) : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $alpha ? : 1 19 20
946 20 ▶ push @{ $g{plot} }, "$block using 1 $native_bins with boxes ${fill}lc rgb " . gp_color($color) . ' ' . key_title( $legend ? $set : undef );
Branch: 1 branch
BranchTrueFalseTotal
$legend ? : 15 5 20
947 20 ▶ $g{legend} = 1 if $legend;
Branch: 1 branch
BranchTrueFalseTotal
if $legend 15 5 20
948 }
949 12 return \%g;
950 }
951 22 ▶sub native_bin_peak {
Subroutine native_bin_peak: called CC=9 SCAR=22.8
Pod undocumented
952 # The count in the fullest of the bins native_bins asks gnuplot for, for
953 # thin_tics, which spaces the tics of a small subplot over the range of the
954 # data: gnuplot bins these itself, so the counts were nowhere in Perl, and
955 # a native hist in a 2 by 2 grid kept gnuplot's tic every 10 from 0 to 80.
956 # The rule is gnuplot's ("help bins"): N centers from the least value to
957 # the greatest, or from "binrange" by "binwidth", each value counted at the
958 # nearest. Only the tics read this; gnuplot still draws the bars.
959 22 my ( $values, $bins ) = @_;
960 22 ▶ my @v = grep { ( defined ) && looks_like_number($_) && is_finite($_) } @{$values};
Condition33%2/6
defined $_ && &looks_like_number($_) && is_finite($_)
!ll&&!rl&&r
001265
defined $_ and &looks_like_number($_)
!ll&&!rl&&r
001265
MC/DC0%0/3
defined $_ && &looks_like_number($_) && is_finite($_)
defined $_ &looks_like_number($_) is_finite($_)
Truth table25%1/4
A and B && C
A= defined $_B= &looks_like_number($_)C= is_finite($_)
ABCresult
0XX0
10X0
1100
1111
961 22 ▶ return 0 if scalar @v == 0;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @v == 0 0 22 22
962 22 my ( $first, $width );
963 22 ▶ if ( ref $bins eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $bins eq 'ARRAY') { } 4 18 22
964 4 $width = ( $bins->[-1] - $bins->[0] ) / $#{$bins};
965 4 $first = $bins->[0] + $width / 2;
966 } else {
967 18 ▶ my $n = $bins // 10; # native_bins' default
Condition100%2/2
$bins // 10
l!l
513
MC/DC100%1/1
$bins // 10
$bins
Truth table100%2/2
A
A= $bins
Aresult
11
00
968 18 $first = min(@v);
969 18 ▶ $width = ( $n > 1 ) ? ( max(@v) - $first ) / ( $n - 1 ) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$n > 1 ? : 18 0 18
970 }
971 22 ▶ return scalar @v if $width <= 0; # every value at one center
Branch: 1 branch
BranchTrueFalseTotal
if $width <= 0 0 22 22
972 22 my %count;
973 22 $count{ POSIX::floor( ( $_ - $first ) / $width + 0.5 ) }++ foreach @v;
974 22 return max( values %count );
975 }
976 26 ▶sub native_bins {
Subroutine native_bins: called CC=13 SCAR=26.0
Pod undocumented
977 # The "bins" option of a plot clause for a hist's "bins": 10 for none, as
978 # draw_hist_native says, "bins=N" for a count, and for edges, which must be
979 # evenly spaced since gnuplot's bins are all one width, that width over
980 # the centers of the first and the last.
981 26 my ( $bins, $set ) = @_;
982 26 ▶ return 'bins=10' unless defined $bins;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bins 13 13 26
983 13 ▶ if ( ref $bins eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $bins eq "ARRAY") 4 9 13
984 4 check_numbers( $bins, '"bins"', $current_sub );
985 4 ▶ die "\"bins\" has fewer than 2 edges in $current_sub" if scalar @{$bins} < 2;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$bins;} < 2 0 4 4
986 4 ▶ die "\"bins\" must rise from edge to edge in $current_sub" if grep { $bins->[$_] <= $bins->[ $_ - 1 ] } 1 .. $#{$bins};
Branch: 1 branch
BranchTrueFalseTotal
if grep {$bins->[$_] <= $$bins[$_ - 1];} 1 .. $#{$bins;} 0 4 4
987 4 my $width = ( $bins->[-1] - $bins->[0] ) / $#{$bins};
988 # 1e-9 of the width: edges written to 10 significant figures are even
989 4 my @uneven = grep { abs( $bins->[$_] - $bins->[ $_ - 1 ] - $width ) > 1e-9 * abs($width) } 1 .. $#{$bins};
990 4 ▶ die "\"bins\" for \"$set\" has edges of different widths, but gnuplot's bins under style => 'native' are all one width; style => 'matplotlib' draws them" if scalar @uneven;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @uneven 1 3 4
991 3 return sprintf 'bins binrange [%s:%s] binwidth=%s', gp_num( $bins->[0] + $width / 2 ), gp_num( $bins->[-1] - $width / 2 ), gp_num($width);
992 }
993 9 ▶ if ( ( ref $bins ) || ( not looks_like_number($bins) ) || ( not is_finite($bins) ) || ( int($bins) != $bins ) || ( $bins < 1 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $bins or not &looks_like_number($bins) or not is_finite($bins) or int $bins != $bins or $bins < 1) 4 5 9
Condition75%9/12
ref $bins or not &looks_like_number($bins) or not is_finite($bins) or int $bins != $bins or $bins < 1
l!l&&r!l&&!r
405
ref $bins or not &looks_like_number($bins) or not is_finite($bins) or int $bins != $bins
l!l&&r!l&&!r
315
ref $bins or not &looks_like_number($bins) or not is_finite($bins)
l!l&&r!l&&!r
306
ref $bins or not &looks_like_number($bins)
l!l&&r!l&&!r
036
MC/DC40%2/5
ref $bins or not &looks_like_number($bins) or not is_finite($bins) or int $bins != $bins or $bins < 1
ref $bins not &looks_like_number($bins) not is_finite($bins) int $bins != $bins $bins < 1
Truth table50%3/6
A or not(B) or not(C) or D or E
A= ref $binsB= not &looks_like_number($bins)C= not is_finite($bins)D= int $bins != $binsE= $bins < 1
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
994 4 ▶ die "\"bins\" is a whole number of bins, or an array of their edges, for the gnuplot engine, not \"" . ( ref $bins || $bins ) . '"';
Condition33%1/3
ref $bins || $bins
l!l&&r!l&&!r
040
MC/DC0%0/2
ref $bins || $bins
ref $bins $bins
Truth table33%1/3
A || B
A= ref $binsB= $bins
ABresult
1X1
011
000
995 }
996 # gnuplot's own bin width is (HIGH - LOW) / (NBINS - 1) ("help bins"), and with
997 # one bin it refuses the plot: "x range is invalid", gnuplot 6.0.
998 5 ▶ die "\"bins\" => 1 for \"$set\": gnuplot's bins under style => 'native' are at least 2, its bin width being the range over one fewer than their number; style => 'matplotlib' draws one" if int($bins) == 1;
Branch: 1 branch
BranchTrueFalseTotal
if int $bins == 1 1 4 5
999 4 return 'bins=' . int $bins;
1000 }
1001 17 ▶sub bin_edges {
Subroutine bin_edges: called CC=12 SCAR=28.3
Pod undocumented
1002 # The edges of a hist's bins: "bins" given as edges, or as a count of
1003 # equal bins over the values' range, as numpy.histogram makes them.
1004 17 my ( $values, $bins, $what ) = @_;
1005 17 ▶ if ( ref $bins eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $bins eq "ARRAY") 3 14 17
1006 3 check_numbers( $bins, $what, $current_sub );
1007 3 ▶ die "$what has fewer than 2 edges in $current_sub" if scalar @{$bins} < 2;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$bins;} < 2 0 3 3
1008 # Two equal edges are a bin of no width, which holds nothing, as numpy
1009 # allows them; edges that fall are refused, as numpy refuses them.
1010 3 ▶ die "$what must not fall from edge to edge in $current_sub" if grep { $bins->[$_] < $bins->[ $_ - 1 ] } 1 .. $#{$bins};
Branch: 1 branch
BranchTrueFalseTotal
if grep {$bins->[$_] < $$bins[$_ - 1];} 1 .. $#{$bins;} 1 2 3
1011 2 return map { as_double($_) } @{$bins}; # see bin_count
1012 }
1013 14 ▶ if ( ( ref $bins ) || ( not looks_like_number($bins) ) || ( not is_finite($bins) ) || ( int($bins) != $bins ) || ( $bins < 1 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $bins or not &looks_like_number($bins) or not is_finite($bins) or int $bins != $bins or $bins < 1) 0 14 14
Condition33%4/12
ref $bins or not &looks_like_number($bins) or not is_finite($bins) or int $bins != $bins or $bins < 1
l!l&&r!l&&!r
0014
ref $bins or not &looks_like_number($bins) or not is_finite($bins) or int $bins != $bins
l!l&&r!l&&!r
0014
ref $bins or not &looks_like_number($bins) or not is_finite($bins)
l!l&&r!l&&!r
0014
ref $bins or not &looks_like_number($bins)
l!l&&r!l&&!r
0014
MC/DC0%0/5
ref $bins or not &looks_like_number($bins) or not is_finite($bins) or int $bins != $bins or $bins < 1
ref $bins not &looks_like_number($bins) not is_finite($bins) int $bins != $bins $bins < 1
Truth table16%1/6
A or not(B) or not(C) or D or E
A= ref $binsB= not &looks_like_number($bins)C= not is_finite($bins)D= int $bins != $binsE= $bins < 1
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
1014 0 ▶ die "$what is a whole number of bins, or an array of their edges, for the gnuplot engine, not \"" . ( ref $bins || $bins ) . '"';
Condition0%0/3
ref $bins || $bins
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $bins || $bins
ref $bins $bins
Truth table0%0/3
A || B
A= ref $binsB= $bins
ABresult
1X1
011
000
1015 }
1016 # numpy's range for no values at all, as for a set that was all NaN, is
1017 # 0 .. 1; min() of an empty list was undef, and died comparing it.
1018 14 ▶ my ( $lo, $hi ) = scalar @{$values} ? ( min( @{$values} ), max( @{$values} ) ) : ( 0, 1 );
Branch: 1 branch
BranchTrueFalseTotal
scalar @{$values;} ? : 12 2 14
1019 14 ▶ ( $lo, $hi ) = ( $lo - 0.5, $hi + 0.5 ) if $lo == $hi;
Branch: 1 branch
BranchTrueFalseTotal
if $lo == $hi 0 14 14
1020 14 return linspace( $lo, $hi, $bins + 1 );
1021 }
1022 16 ▶sub bin_count {
Subroutine bin_count: called CC=6 SCAR=18.0
Pod undocumented
1023 # How many values fall in each bin; the last bin holds its right edge.
1024 # The edges are doubles, and each value is rounded to one before it is
1025 # compared with them, as numpy compares them; see as_double.
1026 16 my ( $values, $edges ) = @_;
1027 16 my @n = (0) x ( scalar @{$edges} - 1 );
1028 16 foreach my $v ( map { as_double($_) } @{$values} ) {
1029 724 ▶ next if ( $v < $edges->[0] ) || ( $v > $edges->[-1] );
Branch: 1 branch
BranchTrueFalseTotal
if $v < $edges->[0] or $v > $edges->[-1] 0 724 724
Condition33%1/3
$v < $edges->[0] or $v > $edges->[-1]
l!l&&r!l&&!r
00724
MC/DC0%0/2
$v < $edges->[0] or $v > $edges->[-1]
$v < $edges->[0] $v > $edges->[-1]
Truth table33%1/3
A or B
A= $v < $edges->[0]B= $v > $edges->[-1]
ABresult
1X1
011
000
1030 724 my ( $l, $r ) = ( 0, $#n );
1031 724 ▶ while ( $l < $r ) { # the last edge at or below $v
Branch: 1 branch
BranchTrueFalseTotal
if ($l < $r) 2333 724 3057
1032 2333 my $m = int( ( $l + $r + 1 ) / 2 );
1033 2333 ▶ if ( $edges->[$m] <= $v ) { $l = $m } else { $r = $m - 1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($edges->[$m] <= $v) { } 1337 996 2333
1034 }
1035 724 $n[$l]++;
1036 }
1037 16 return @n;
1038 }
1039 28 ▶sub draw_hist {
Subroutine draw_hist: called CC=30 SCAR=40.2
Pod undocumented
1040 # One histogram per set, each binned over its own range, drawn see-through
1041 # so that the sets overlap, as hist_helper draws them.
1042 28 my ( $plot, $axes ) = @_;
1043 28 ▶ return draw_hist_native( $plot, $axes ) if $native;
Branch: 1 branch
BranchTrueFalseTotal
if $native 19 9 28
1044 9 ▶ my $horizontal = ( orientation_of($plot) eq 'horizontal' ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
orientation_of($plot) eq 'horizontal' ? : 0 9 9
1045 9 ▶ my $alpha = $plot->{alpha} // 0.5;
Condition50%1/2
$plot->{"alpha"} // "0.5"
l!l
09
MC/DC0%0/1
$plot->{"alpha"} // "0.5"
$plot->{"alpha"}
Truth table50%1/2
A
A= $plot->{"alpha"}
Aresult
11
00
1046 9 check_numbers( [$alpha], '"alpha"', $current_sub );
1047 9 ▶ die "\"alpha\" is from 0 to 1 in $current_sub, not $alpha" if ( $alpha < 0 ) || ( $alpha > 1 );
Branch: 1 branch
BranchTrueFalseTotal
if $alpha < 0 or $alpha > 1 0 9 9
Condition33%1/3
$alpha < 0 or $alpha > 1
l!l&&r!l&&!r
009
MC/DC0%0/2
$alpha < 0 or $alpha > 1
$alpha < 0 $alpha > 1
Truth table33%1/3
A or B
A= $alpha < 0B= $alpha > 1
ABresult
1X1
011
000
1048 9 ▶ my $sets = ( ref $plot->{data} eq 'ARRAY' ) ? { A => $plot->{data} } : $plot->{data};
Branch: 1 branch
BranchTrueFalseTotal
ref $plot->{'data'} eq 'ARRAY' ? : 3 6 9
1049 9 foreach my $arg ( grep { ref $plot->{$_} eq 'HASH' } ( 'bins', 'color' ) ) {
1050 0 my @stray = sort grep { not exists $sets->{$_} } keys %{ $plot->{$arg} };
1051 0 ▶ die 'the keys ' . join( ', ', map { "\"$_\"" } @stray ) . " of \"$arg\" are not sets of \"data\" in $current_sub" if scalar @stray;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @stray 0 0 0
1052 }
1053 9 ▶ if ( ( ref $plot->{color} ) && ( ref $plot->{color} ne 'HASH' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $plot->{"color"} and ref $plot->{"color"} ne "HASH") 0 9 9
Condition33%1/3
ref $plot->{"color"} and ref $plot->{"color"} ne "HASH"
!ll&&!rl&&r
900
MC/DC0%0/2
ref $plot->{"color"} and ref $plot->{"color"} ne "HASH"
ref $plot->{"color"} ref $plot->{"color"} ne "HASH"
Truth table33%1/3
A and B
A= ref $plot->{"color"}B= ref $plot->{"color"} ne "HASH"
ABresult
0X0
100
111
1054 0 die "\"color\" for $current_sub is one color for every set, or a hash of one color per set, not a " . ref( $plot->{color} ) . ' reference';
1055 }
1056 9 my @keys = key_order_of( $plot, $sets );
1057 9 ▶ my $legend = bool_option( $plot->{show_legend} // ( scalar keys %{$sets} > 1 ? 1 : 0 ), 'show_legend', $current_sub );
Branch: 1 branch
BranchTrueFalseTotal
scalar keys %{$sets;} > 1 ? : 5 4 9
Condition50%1/2
$plot->{"show_legend"} // (scalar keys %{$sets;} > 1 ? 1 : 0)
l!l
09
MC/DC0%0/1
$plot->{"show_legend"} // (scalar keys %{$sets;} > 1 ? 1 : 0)
$plot->{"show_legend"}
Truth table50%1/2
A
A= $plot->{"show_legend"}
Aresult
11
00
1058 0 my %log = map { $_ => 1 } logscale_axes( $plot->{logscale}, $current_sub );
1059 0 my %g = ( set => [ map { "set logscale $_" } sort keys %log ], plot => [] );
1060 9 ▶ my $count_axis = $horizontal ? 'x' : 'y';
Branch: 1 branch
BranchTrueFalseTotal
$horizontal ? : 0 9 9
1061 9 foreach my $set (@keys) {
1062 14 my @bad = grep { not looks_like_number($_) } @{ $sets->{$set} };
1063 14 ▶ die "$set has non-numeric values; which for hist must be numeric" if scalar @bad;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @bad 0 14 14
1064 14 ▶ my @inf = grep { not( is_nan($_) || is_finite($_) ) } @{ $sets->{$set} };
Condition66%2/3
is_nan($_) || is_finite($_)
l!l&&r!l&&!r
27130
MC/DC0%0/2
is_nan($_) || is_finite($_)
is_nan($_) is_finite($_)
Truth table66%2/3
A || B
A= is_nan($_)B= is_finite($_)
ABresult
1X1
011
000
1065 14 ▶ die "$set has infinite values, which $current_sub cannot bin" if scalar @inf;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @inf 0 14 14
1066 14 my @v = grep { not is_nan($_) } @{ $sets->{$set} };
1067 14 ▶ my $bins = ( ref $plot->{bins} eq 'HASH' ) ? $plot->{bins}{$set} // 10 : $plot->{bins} // 10;
Branch: 1 branch
BranchTrueFalseTotal
ref $plot->{'bins'} eq 'HASH' ? : 0 14 14
Condition50%2/4
$plot->{"bins"}{$set} // 10
l!l
00
$plot->{"bins"} // 10
l!l
311
MC/DC0%0/1
$plot->{"bins"}{$set} // 10
$plot->{"bins"}{$set}
MC/DC100%1/1
$plot->{"bins"} // 10
$plot->{"bins"}
Truth table0%0/2
A
A= $plot->{"bins"}{$set}
Aresult
11
00
Truth table100%2/2
A
A= $plot->{"bins"}
Aresult
11
00
1068 14 my @edges = bin_edges( \@v, $bins, '"bins"' );
1069 13 my @n = bin_count( \@v, \@edges );
1070 13 my $color;
1071 13 ▶ my $given = ( ref $plot->{color} eq 'HASH' ) ? $plot->{color}{$set} : $plot->{color};
Branch: 1 branch
BranchTrueFalseTotal
ref $plot->{'color'} eq 'HASH' ? : 0 13 13
1072 13 ▶ if ( ref $given ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $given) 0 13 13
1073 0 die "\"color\" for set \"$set\" is an array, but $current_sub draws each set in one color";
1074 }
1075 13 ▶ $color = defined $given ? hex_of( $given, "\"color\" of \"$set\"" ) : next_color( $axes, 'patches' );
Branch: 1 branch
BranchTrueFalseTotal
defined $given ? : 0 13 13
1076 13 ▶ my $base = $log{$count_axis} ? 0.5 : 0; # a log axis of counts starts below the least, which is 1
Branch: 1 branch
BranchTrueFalseTotal
$log{$count_axis} ? : 0 13 13
1077 13 ▶ my @rows = map { box_rows( ( $edges[$_] + $edges[ $_ + 1 ] ) / 2, ( $edges[ $_ + 1 ] - $edges[$_] ) / 2, $base, $n[$_], $horizontal ) } grep { $n[$_] > 0 || not $log{$count_axis} } 0 .. $#n;
Condition66%2/3
$n[$_] > 0 || !$log{$count_axis}
l!l&&r!l&&!r
73440
MC/DC0%0/2
$n[$_] > 0 || !$log{$count_axis}
$n[$_] > 0 !$log{$count_axis}
Truth table66%2/3
A || not(B)
A= $n[$_] > 0B= !$log{$count_axis}
ABresult
1X1
011
000
1078 13 ▶ push @{ $g{plot} }, boxes_clause( datablock( \@rows ), with_alpha( $color, $alpha ), key_title( $legend ? $set : undef ) );
Branch: 1 branch
BranchTrueFalseTotal
$legend ? : 10 3 13
1079 13 ▶ $g{legend} = 1 if $legend;
Branch: 1 branch
BranchTrueFalseTotal
if $legend 10 3 13
1080 }
1081 8 ▶ $g{no_margin} = [ $horizontal ? 'left' : 'bottom' ] unless $log{$count_axis};
Branch: 2 branches
BranchTrueFalseTotal
unless $log{$count_axis} 8 0 8
$horizontal ? : 0 8 8
1082 8 return \%g;
1083 }
1084 7 ▶sub draw_hist2d {
Subroutine draw_hist2d: called CC=42 SCAR=44.4
Pod undocumented
1085 # Counts of points in a grid of bins, colored by a colormap, as
1086 # hist2d_helper draws them; the bins are counted here.
1087 7 my ( $plot, $axes ) = @_;
1088 7 my $log_cb = bool_option( $plot->{cb_logscale}, 'cb_logscale', $current_sub );
1089 7 ▶ my $show = bool_option( $plot->{show_colorbar} // 1, 'show_colorbar', $current_sub ) && bool_option( $plot->{colorbar_on} // 1, 'colorbar_on', $current_sub );
Condition71%5/7
bool_option($plot->{'show_colorbar'} // 1, 'show_colorbar', $current_sub) && bool_option($plot->{'colorbar_on'} // 1, 'colorbar_on', $current_sub)
!ll&&!rl&&r
106
$plot->{"show_colorbar"} // 1
l!l
16
$plot->{"colorbar_on"} // 1
l!l
06
MC/DC50%1/2
bool_option($plot->{'show_colorbar'} // 1, 'show_colorbar', $current_sub) && bool_option($plot->{'colorbar_on'} // 1, 'colorbar_on', $current_sub)
bool_option($plot->{'show_colorbar'} // 1, 'show_colorbar', $current_sub) bool_option($plot->{'colorbar_on'} // 1, 'colorbar_on', $current_sub)
MC/DC100%1/1
$plot->{"show_colorbar"} // 1
$plot->{"show_colorbar"}
MC/DC0%0/1
$plot->{"colorbar_on"} // 1
$plot->{"colorbar_on"}
Truth table66%2/3
A && B
A= bool_option($plot->{'show_colorbar'} // 1, 'show_colorbar', $current_sub)B= bool_option($plot->{'colorbar_on'} // 1, 'colorbar_on', $current_sub)
ABresult
0X0
100
111
Truth table100%2/2
A
A= $plot->{"show_colorbar"}
Aresult
11
00
Truth table50%1/2
A
A= $plot->{"colorbar_on"}
Aresult
11
00
1090 7 bin_counts( $plot, $current_sub );
1091 7 my @keys = key_order_of( $plot, $plot->{data} );
1092 7 ▶ die "There must be exactly 2 keys for $current_sub" if scalar @keys != 2;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @keys != 2 0 7 7
1093 7 my ( $x, $y ) = @{ $plot->{data} }{@keys};
1094 7 ▶ die 'The length of both keys must be equal.' if scalar @{$x} != scalar @{$y};
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$x;} != scalar @{$y;} 0 7 7
1095 7 foreach my $i ( 0, 1 ) {
1096 14 my $vals = $plot->{data}{ $keys[$i] };
1097 14 ▶ my @bad = grep { ( not defined $vals->[$_] ) || ( not looks_like_number( $vals->[$_] ) ) } 0 .. $#{$vals};
Condition33%1/3
defined $vals->[$_] && &looks_like_number($vals->[$_])
!ll&&!rl&&r
003010
MC/DC0%0/2
defined $vals->[$_] && &looks_like_number($vals->[$_])
defined $vals->[$_] &looks_like_number($vals->[$_])
Truth table33%1/3
A && B
A= defined $vals->[$_]B= &looks_like_number($vals->[$_])
ABresult
0X0
100
111
1098 14 ▶ die "\"$keys[$i]\" is undefined or not a number at index " . join( ', ', @bad ) . " in $current_sub" if scalar @bad;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @bad 0 14 14
1099 }
1100 7 my %log = map { $_ => 1 } logscale_axes( $plot->{logscale}, $current_sub );
1101 7 my ( %edges, %g );
1102 7 $g{set} = [ map { "set logscale $_" } sort keys %log ];
1103 7 foreach my $i ( 0, 1 ) {
1104 13 my $axis = ( 'x', 'y' )[$i];
1105 13 my @finite = finite_values( @{ $plot->{data}{ $keys[$i] } } );
1106 13 foreach my $end ( 'min', 'max' ) {
1107 26 my $opt = "$axis$end";
1108 26 ▶ if ( defined $plot->{$opt} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $plot->{$opt}) { } 0 26 26
elsif (scalar @finite == 0) { } 0 26 26
1109 0 check_numbers( [ $plot->{$opt} ], "\"$opt\"", $current_sub );
1110 0 ▶ die "\"$opt\" must be a finite number for $current_sub, not \"$plot->{$opt}\"" unless is_finite( $plot->{$opt} );
Branch: 1 branch
BranchTrueFalseTotal
unless is_finite($plot->{$opt}) 0 0 0
1111 } elsif ( scalar @finite == 0 ) {
1112 0 die "\"$keys[$i]\" has no finite value, so $current_sub has no range to bin it over; give \"${axis}min\" and \"${axis}max\"";
1113 }
1114 }
1115 13 ▶ my $lo = $plot->{"${axis}min"} // min(@finite);
Condition33%1/3
$$plot{"${axis}min"} // &min(@finite)
l!l&&r!l&&!r
0130
MC/DC0%0/2
$$plot{"${axis}min"} // &min(@finite)
$$plot{"${axis}min"} &min(@finite)
Truth table33%1/3
A // B
A= $$plot{"${axis}min"}B= &min(@finite)
ABresult
1X1
011
000
1116 13 ▶ my $hi = $plot->{"${axis}max"} // max(@finite);
Condition33%1/3
$$plot{"${axis}max"} // &max(@finite)
l!l&&r!l&&!r
0130
MC/DC0%0/2
$$plot{"${axis}max"} // &max(@finite)
$$plot{"${axis}max"} &max(@finite)
Truth table33%1/3
A // B
A= $$plot{"${axis}max"}B= &max(@finite)
ABresult
1X1
011
000
1117 13 ▶ die "\"${axis}min\" = $lo is above \"${axis}max\" = $hi in $current_sub" if $lo > $hi;
Branch: 1 branch
BranchTrueFalseTotal
if $lo > $hi 0 13 13
1118 13 ▶ die "\"logscale\" puts $axis on a log scale, which cannot start at $lo in $current_sub: give a \"${axis}min\" above 0" if $log{$axis} && ( $lo <= 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $log{$axis} and $lo <= 0 0 13 13
Condition66%2/3
$log{$axis} and $lo <= 0
!ll&&!rl&&r
1210
MC/DC0%0/2
$log{$axis} and $lo <= 0
$log{$axis} $lo <= 0
Truth table66%2/3
A and B
A= $log{$axis}B= $lo <= 0
ABresult
0X0
100
111
1119 # Refused on a log axis, where widening by 0.5 each way could reach 0 or
1120 # below, and died taking its log ("Can't take log of -0.2"); matplotlib's
1121 # np.logspace of one value has edges that do not rise, and fails too.
1122 13 ▶ die "\"logscale\" puts $axis on a log scale, but every $axis is $lo, a range of nothing, in $current_sub; give \"${axis}min\" and \"${axis}max\"" if $log{$axis} && ( $lo == $hi );
Branch: 1 branch
BranchTrueFalseTotal
if $log{$axis} and $lo == $hi 1 12 13
Condition66%2/3
$log{$axis} and $lo == $hi
!ll&&!rl&&r
1201
MC/DC50%1/2
$log{$axis} and $lo == $hi
$log{$axis} $lo == $hi
Truth table66%2/3
A and B
A= $log{$axis}B= $lo == $hi
ABresult
0X0
100
111
1123 12 ▶ ( $lo, $hi ) = ( $lo - 0.5, $hi + 0.5 ) if $lo == $hi; # numpy's histogram2d does the same with an empty range
Branch: 1 branch
BranchTrueFalseTotal
if $lo == $hi 0 12 12
1124 12 my $n = $plot->{"${axis}bins"};
1125 12 ▶ $edges{$axis} = $log{$axis} ? [ logspace( $lo, $hi, $n + 1 ) ] : [ linspace( $lo, $hi, $n + 1 ) ]; # as the matplotlib engine writes them
Branch: 1 branch
BranchTrueFalseTotal
$log{$axis} ? : 0 12 12
1126 12 push @{ $g{set} }, "set ${axis}range [" . gp_num($lo) . ':' . gp_num($hi) . ']';
1127 }
1128 6 my @count;
1129 6 my $in_range = 0;
1130 6 foreach my $p ( 0 .. $#{$x} ) {
1131 1503 ▶ next unless is_finite( $x->[$p] ) && is_finite( $y->[$p] );
Branch: 1 branch
BranchTrueFalseTotal
unless is_finite($x->[$p]) and is_finite($y->[$p]) 0 1503 1503
Condition33%1/3
is_finite($x->[$p]) and is_finite($y->[$p])
!ll&&!rl&&r
001503
MC/DC0%0/2
is_finite($x->[$p]) and is_finite($y->[$p])
is_finite($x->[$p]) is_finite($y->[$p])
Truth table33%1/3
A and B
A= is_finite($x->[$p])B= is_finite($y->[$p])
ABresult
0X0
100
111
1132 1503 my ($xi) = bin_index( $x->[$p], $edges{x} );
1133 1503 my ($yi) = bin_index( $y->[$p], $edges{y} );
1134 1503 ▶ next unless defined $xi && defined $yi;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $xi and defined $yi 0 1503 1503
Condition33%1/3
defined $xi and defined $yi
!ll&&!rl&&r
001503
MC/DC0%0/2
defined $xi and defined $yi
defined $xi defined $yi
Truth table33%1/3
A and B
A= defined $xiB= defined $yi
ABresult
0X0
100
111
1135 1503 $count[$xi][$yi]++;
1136 1503 $in_range++;
1137 }
1138 6 foreach my $c ( grep { defined $plot->{$_} } ( 'cmin', 'cmax' ) ) {
1139 0 check_numbers( [ $plot->{$c} ], "\"$c\"", $current_sub );
1140 }
1141 6 my $density = bool_option( $plot->{density}, 'density', $current_sub );
1142 6 my ( @rows, @values );
1143 6 foreach my $i ( 0 .. $plot->{xbins} - 1 ) {
1144 77 foreach my $j ( 0 .. $plot->{ybins} - 1 ) {
1145 1129 ▶ my $c = $count[$i][$j] // 0;
Condition100%2/2
$count[$i][$j] // 0
l!l
552577
MC/DC100%1/1
$count[$i][$j] // 0
$count[$i][$j]
Truth table100%2/2
A
A= $count[$i][$j]
Aresult
11
00
1146 1129 ▶ next if ( defined $plot->{cmin} ) && ( $c < $plot->{cmin} ); # left undrawn, as matplotlib masks them
Branch: 1 branch
BranchTrueFalseTotal
if defined $plot->{"cmin"} and $c < $plot->{"cmin"} 0 1129 1129
Condition33%1/3
defined $plot->{"cmin"} and $c < $plot->{"cmin"}
!ll&&!rl&&r
112900
MC/DC0%0/2
defined $plot->{"cmin"} and $c < $plot->{"cmin"}
defined $plot->{"cmin"} $c < $plot->{"cmin"}
Truth table33%1/3
A and B
A= defined $plot->{"cmin"}B= $c < $plot->{"cmin"}
ABresult
0X0
100
111
1147 1129 ▶ next if ( defined $plot->{cmax} ) && ( $c > $plot->{cmax} );
Branch: 1 branch
BranchTrueFalseTotal
if defined $plot->{"cmax"} and $c > $plot->{"cmax"} 0 1129 1129
Condition33%1/3
defined $plot->{"cmax"} and $c > $plot->{"cmax"}
!ll&&!rl&&r
112900
MC/DC0%0/2
defined $plot->{"cmax"} and $c > $plot->{"cmax"}
defined $plot->{"cmax"} $c > $plot->{"cmax"}
Truth table33%1/3
A and B
A= defined $plot->{"cmax"}B= $c > $plot->{"cmax"}
ABresult
0X0
100
111
1148 1129 my ( $x0, $x1, $y0, $y1 ) = ( $edges{x}[$i], $edges{x}[ $i + 1 ], $edges{y}[$j], $edges{y}[ $j + 1 ] );
1149 1129 ▶ my $v = ( $density && $in_range ) ? $c / ( $in_range * ( $x1 - $x0 ) * ( $y1 - $y0 ) ) : $c;
Branch: 1 branch
BranchTrueFalseTotal
$density && $in_range ? : 0 1129 1129
Condition33%1/3
$density and $in_range
!ll&&!rl&&r
112900
MC/DC0%0/2
$density and $in_range
$density $in_range
Truth table33%1/3
A and B
A= $densityB= $in_range
ABresult
0X0
100
111
1150 1129 ▶ next if $log_cb && ( $v <= 0 ); # LogNorm leaves these undrawn
Branch: 1 branch
BranchTrueFalseTotal
if $log_cb and $v <= 0 0 1129 1129
Condition33%1/3
$log_cb and $v <= 0
!ll&&!rl&&r
112900
MC/DC0%0/2
$log_cb and $v <= 0
$log_cb $v <= 0
Truth table33%1/3
A and B
A= $log_cbB= $v <= 0
ABresult
0X0
100
111
1151 1129 push @values, $v;
1152 1129 push @rows, [ ( $x0 + $x1 ) / 2, ( $y0 + $y1 ) / 2, $x0, $x1, $y0, $y1, $v ];
1153 }
1154 }
1155 6 my ( $lo, $hi ) = color_scale( $plot, \@values, $log_cb );
1156 6 ▶ push @{ $g{set} }, palette({ cmap => default_cmap( $plot, 'gist_rainbow' ), lo => $lo, hi => $hi, log => $log_cb, colorbar => $show, label => $plot->{cblabel} // 'Density' });
Condition50%1/2
$plot->{"cblabel"} // "Density"
l!l
06
MC/DC0%0/1
$plot->{"cblabel"} // "Density"
$plot->{"cblabel"}
Truth table50%1/2
A
A= $plot->{"cblabel"}
Aresult
11
00
1157 6 my $block = datablock( \@rows );
1158 6 ▶ $g{plot} = [ defined $block ? "$block using 1:2:3:4:5:6:7 with boxxyerror fs solid 1.0 noborder lc palette notitle" : () ];
Branch: 1 branch
BranchTrueFalseTotal
defined $block ? : 6 0 6
1159 6 @g{ 'palette', 'default_xlabel', 'default_ylabel' } = ( 1, @keys );
1160 6 $g{no_margin} = [ 'left', 'right', 'top', 'bottom' ];
1161 6 return \%g;
1162 }
1163 3612 ▶sub bin_index {
Subroutine bin_index: called CC=5 SCAR=16.3
Pod undocumented
1164 # The bin of a value among edges, the last holding its right edge; undef
1165 # outside them. $v is rounded to a double, as the edges are; see bin_count.
1166 3612 my ( $v, $edges ) = @_;
1167 3612 $v = as_double($v);
1168 3612 ▶ return undef if ( $v < $edges->[0] ) || ( $v > $edges->[-1] );
Branch: 1 branch
BranchTrueFalseTotal
if $v < $edges->[0] or $v > $edges->[-1] 0 3612 3612
Condition33%1/3
$v < $edges->[0] or $v > $edges->[-1]
l!l&&r!l&&!r
003612
MC/DC0%0/2
$v < $edges->[0] or $v > $edges->[-1]
$v < $edges->[0] $v > $edges->[-1]
Truth table33%1/3
A or B
A= $v < $edges->[0]B= $v > $edges->[-1]
ABresult
1X1
011
000
1169 3612 my ( $l, $r ) = ( 0, $#{$edges} - 1 );
1170 3612 ▶ while ( $l < $r ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l < $r) 14171 3612 17783
1171 14171 my $m = int( ( $l + $r + 1 ) / 2 );
1172 14171 ▶ if ( $edges->[$m] <= $v ) { $l = $m } else { $r = $m - 1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($edges->[$m] <= $v) { } 7552 6619 14171
1173 }
1174 3612 return $l;
1175 }
1176 10 ▶sub image_clause {
Subroutine image_clause: called CC=1 SCAR=0.0
Pod undocumented
1177 # A matrix of values drawn as an image, row 0 at the top, as matplotlib's
1178 # imshow draws it.
1179 10 my ( $matrix, $g ) = @_;
1180 10 my ( $nr, $nc ) = ( scalar @{$matrix}, scalar @{ $matrix->[0] } );
1181 10 my $block = datablock($matrix);
1182 10 push @{ $g->{set} }, sprintf( 'set xrange [-0.5:%s]', gp_num( $nc - 0.5 ) ), sprintf( 'set yrange [%s:-0.5]', gp_num( $nr - 0.5 ) );
1183 10 $g->{no_margin} = [ 'left', 'right', 'top', 'bottom' ];
1184 10 return "$block matrix using 1:2:3 with image notitle";
1185 }
1186 4 ▶sub draw_imshow {
Subroutine draw_imshow: called CC=23 SCAR=33.8
Pod undocumented
1187 # A 2-D array as an image, numbers by a colormap, or strings by a
1188 # "stringmap" as categories, as imshow_helper draws them.
1189 4 my ( $plot, $axes ) = @_;
1190 4 my $data = $plot->{data};
1191 4 ▶ die "$current_sub can only accept 2-D arrays as input in \"data\", but received " . ref($data) if ref $data ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $data ne "ARRAY" 0 4 4
1192 4 my @bad_rows = grep { ref $data->[$_] ne 'ARRAY' } 0 .. $#{$data};
1193 4 ▶ die 'rows ' . join( ', ', @bad_rows ) . " of \"data\" are not array references, which $current_sub needs" if scalar @bad_rows;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @bad_rows 0 4 4
1194 4 ▶ die "$current_sub was given no data to draw" if ( scalar @{$data} == 0 ) || ( not grep { scalar @{$_} > 0 } @{$data} );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$data;} == 0 or not grep({scalar @{$_;} > 0;} @{$data;}) 0 4 4
Condition33%1/3
scalar @{$data;} == 0 or not grep({scalar @{$_;} > 0;} @{$data;})
l!l&&r!l&&!r
004
MC/DC0%0/2
scalar @{$data;} == 0 or not grep({scalar @{$_;} > 0;} @{$data;})
scalar @{$data;} == 0 not grep({scalar @{$_;} > 0;} @{$data;})
Truth table33%1/3
A or not(B)
A= scalar @{$data;} == 0B= not grep({scalar @{$_;} > 0;} @{$data;})
ABresult
1X1
011
000
1195 4 my %lengths = map { scalar @{$_} => 1 } @{$data};
1196 4 ▶ die "the rows of \"data\" have different lengths, but $current_sub draws a rectangle of cells" if scalar keys %lengths > 1;
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %lengths > 1 0 4 4
1197 4 foreach my $r ( 0 .. $#{$data} ) {
1198 7 my @undef = grep { not defined $data->[$r][$_] } 0 .. $#{ $data->[$r] };
1199 7 ▶ die "$current_sub cannot draw an undefined cell, and \"data\" has one at [$r][$undef[0]]; a NaN is drawn as an empty cell" if scalar @undef;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @undef 0 7 7
1200 }
1201 4 my $strings = grep { grep { not looks_like_number($_) } @{$_} } @{$data};
1202 4 my $log = bool_option( $plot->{cb_logscale}, 'cb_logscale', $current_sub );
1203 4 ▶ my $colorbar = bool_option( $plot->{colorbar_on} // 1, 'colorbar_on', $current_sub );
Condition50%1/2
$plot->{"colorbar_on"} // 1
l!l
04
MC/DC0%0/1
$plot->{"colorbar_on"} // 1
$plot->{"colorbar_on"}
Truth table50%1/2
A
A= $plot->{"colorbar_on"}
Aresult
11
00
1204 4 my %g = ( set => [], palette => 1 );
1205 4 ▶ if ($strings) {
Branch: 1 branch
BranchTrueFalseTotal
if ($strings) { } 1 3 4
1206 1 ▶ die "$current_sub needs a map to translate strings to integers" unless ref $plot->{stringmap} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $plot->{"stringmap"} eq "HASH" 0 1 1
1207 1 ▶ die "\"cb_logscale\" means nothing for $current_sub with a \"stringmap\": its colors are categories, not a scale" if $log;
Branch: 1 branch
BranchTrueFalseTotal
if $log 0 1 1
1208 1 ▶ die "\"cmap\" means nothing for $current_sub with a \"stringmap\": its colors are matplotlib's color cycle" if defined $plot->{cmap};
Branch: 1 branch
BranchTrueFalseTotal
if defined $plot->{"cmap"} 0 1 1
1209 1 my @strings = sort keys %{ $plot->{stringmap} };
1210 1 my %int = map { $strings[$_] => $_ } 0 .. $#strings;
1211 1 my %unmapped;
1212 1 $unmapped{$_} = 1 foreach grep { not defined $int{$_} } map { @{$_} } @{$data};
1213 0 ▶ die 'the values ' . join( ', ', map { "\"$_\"" } sort keys %unmapped ) . " of \"data\" are not keys of \"stringmap\", which $current_sub needs to give each one a color" if scalar keys %unmapped;
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %unmapped 0 1 1
1214 1 my $n = scalar @strings;
1215 # The color cycle for up to 10 categories, and gist_rainbow sampled
1216 # once per category beyond that, as imshow_helper chooses. Under style
1217 # => 'native', gnuplot's eight linetype colors, and its own palette
1218 # sampled beyond them.
1219 1 my @colors;
1220 1 ▶ if ($native) {
Branch: 1 branch
BranchTrueFalseTotal
if ($native) { } 0 1 1
1221 0 ▶ @colors = ( $n <= @gnuplot_colors ) ? map { cycle_color($_) } 0 .. $n - 1 : map { default_palette_color( $_ / ( $n - 1 ) ) } 0 .. $n - 1;
Branch: 1 branch
BranchTrueFalseTotal
$n <= @gnuplot_colors ? : 0 0 0
1222 } else {
1223 0 ▶ @colors = ( $n <= 10 ) ? map { cycle_color($_) } 0 .. $n - 1 : map { my @c = colormap_colors( 'gist_rainbow', $engine, $current_sub ); $c[ int( $_ * $#c / ( $n - 1 ) + 0.5 ) ] } 0 .. $n - 1;
Branch: 1 branch
BranchTrueFalseTotal
$n <= 10 ? : 1 0 1
1224 }
1225 1 push @{ $g{set} }, 'set palette defined (' . join( ', ', map { ( $_ . ' ' . gp_str( $colors[$_] ), ( $_ + 1 ) . ' ' . gp_str( $colors[$_] ) ) } 0 .. $n - 1 ) . ')';
1226 1 push @{ $g{set} }, 'unset logscale cb', sprintf( 'set cbrange [-0.5:%s]', gp_num( $n - 0.5 ) );
1227 1 ▶ push @{ $g{set} }, $colorbar ? ( 'set colorbox', tics( 'cb', [ map { $plot->{stringmap}{$_} } @strings ], [ 0 .. $n - 1 ] ) ) : 'unset colorbox';
Branch: 1 branch
BranchTrueFalseTotal
$colorbar ? : 1 0 1
1228 0 ▶ push @{ $g{set} }, 'set cblabel ' . gp_str( $plot->{cblabel} ) if $colorbar && defined $plot->{cblabel};
Branch: 1 branch
BranchTrueFalseTotal
if $colorbar and defined $plot->{"cblabel"} 0 1 1
Condition33%1/3
$colorbar and defined $plot->{"cblabel"}
!ll&&!rl&&r
010
MC/DC0%0/2
$colorbar and defined $plot->{"cblabel"}
$colorbar defined $plot->{"cblabel"}
Truth table33%1/3
A and B
A= $colorbarB= defined $plot->{"cblabel"}
ABresult
0X0
100
111
1229 # gnuplot leaves no room right of the colorbar for labels of its own
1230 # tics: a margin in characters as wide as the longest, the colorbar
1231 # and its gap, measured on the PNG terminal.
1232 1 ▶ push @{ $g{set} }, 'set rmargin ' . ( max( map { length $plot->{stringmap}{$_} } @strings ) + 8 + ( defined $plot->{cblabel} ? 3 : 0 ) ) if $colorbar;
Branch: 2 branches
BranchTrueFalseTotal
if $colorbar 1 0 1
defined $plot->{'cblabel'} ? : 0 1 1
1233 1 $g{plot} = [ image_clause( [ map { [ map { $int{$_} } @{$_} ] } @{$data} ], \%g ) ];
1234 } else {
1235 3 my ( $lo, $hi ) = color_scale( $plot, [ map { @{$_} } @{$data} ], $log );
1236 3 push @{ $g{set} }, palette({ cmap => default_cmap( $plot, 'viridis' ), lo => $lo, hi => $hi, log => $log, colorbar => $colorbar, label => $plot->{cblabel} });
1237 2 $g{plot} = [ image_clause( $data, \%g ) ];
1238 }
1239 3 $g{solo} = 'imshow';
1240 3 return \%g;
1241 }
1242 7 ▶sub draw_colored_table {
Subroutine draw_colored_table: called CC=32 SCAR=41.7
Pod undocumented
1243 # A table of cells colored by their values, with the row labels down the
1244 # left, the column labels along the top, and the numbers if asked for, as
1245 # colored_table_helper draws it.
1246 7 my ( $plot, $axes ) = @_;
1247 7 my ( $row_keys, $cols, $cells ) = table_cells( $plot, $current_sub );
1248 7 my @rows = @{$row_keys};
1249 7 ▶ if ( defined $plot->{row_labels} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $plot->{"row_labels"}) 0 7 7
1250 0 ▶ die "\"row_labels\" is an array of one label per row in $current_sub" unless ref $plot->{row_labels} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $plot->{"row_labels"} eq "ARRAY" 0 0 0
1251 0 ▶ die '"row_labels" has ' . scalar( @{ $plot->{row_labels} } ) . ' labels, but the table has ' . scalar(@rows) . " rows in $current_sub" if scalar @{ $plot->{row_labels} } != scalar @rows;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$plot->{"row_labels"};} != scalar @rows 0 0 0
1252 0 @rows = @{ $plot->{row_labels} };
1253 }
1254 7 ▶ if ( defined $plot->{default_undefined} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $plot->{"default_undefined"}) 0 7 7
1255 0 ▶ die "\"default_undefined\" = $plot->{default_undefined} must be a number" unless looks_like_number( $plot->{default_undefined} );
Branch: 1 branch
BranchTrueFalseTotal
unless &looks_like_number($plot->{"default_undefined"}) 0 0 0
1256 }
1257 7 my @non_numeric;
1258 7 foreach my $k1 ( @{$row_keys} ) {
1259 0 ▶ push @non_numeric, map { "$k1/$_ = \"$cells->{$k1}{$_}\"" } grep { ( defined $cells->{$k1}{$_} ) && ( not looks_like_number( $cells->{$k1}{$_} ) ) } @{$cols};
Condition66%2/3
defined $cells->{$k1}{$_} && !&looks_like_number($cells->{$k1}{$_})
!ll&&!rl&&r
6200
MC/DC0%0/2
defined $cells->{$k1}{$_} && !&looks_like_number($cells->{$k1}{$_})
defined $cells->{$k1}{$_} !&looks_like_number($cells->{$k1}{$_})
Truth table66%2/3
A && not(B)
A= defined $cells->{$k1}{$_}B= !&looks_like_number($cells->{$k1}{$_})
ABresult
0X0
100
111
1260 }
1261 7 ▶ die 'the cells ' . join( ', ', @non_numeric ) . " are not numbers, which $current_sub needs; leave a cell out, or undefined, to draw it in \"undef_color\"" if scalar @non_numeric;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @non_numeric 0 7 7
1262 7 foreach my $opt ( grep { defined $plot->{$_} } ( 'cb_min', 'cb_max' ) ) {
1263 0 ▶ die "\"$opt\" = $plot->{$opt} must be a finite number" unless looks_like_number( $plot->{$opt} ) && is_finite( $plot->{$opt} );
Branch: 1 branch
BranchTrueFalseTotal
unless &looks_like_number($plot->{$opt}) and is_finite($plot->{$opt}) 0 0 0
Condition0%0/3
&looks_like_number($plot->{$opt}) and is_finite($plot->{$opt})
!ll&&!rl&&r
000
MC/DC0%0/2
&looks_like_number($plot->{$opt}) and is_finite($plot->{$opt})
&looks_like_number($plot->{$opt}) is_finite($plot->{$opt})
Truth table0%0/3
A and B
A= &looks_like_number($plot->{$opt})B= is_finite($plot->{$opt})
ABresult
0X0
100
111
1264 }
1265 7 ▶ my @matrix = map { my $k1 = $_; [ map { $cells->{$k1}{$_} // $plot->{default_undefined} } @{$cols} ] } @{$row_keys};
Condition66%2/3
$cells->{$k1}{$_} // $plot->{"default_undefined"}
l!l&&r!l&&!r
2006
MC/DC50%1/2
$cells->{$k1}{$_} // $plot->{"default_undefined"}
$cells->{$k1}{$_} $plot->{"default_undefined"}
Truth table66%2/3
A // B
A= $cells->{$k1}{$_}B= $plot->{"default_undefined"}
ABresult
1X1
011
000
1266 7 my @values = finite_values( map { @{$_} } @matrix );
1267 7 ▶ if ( ( scalar @values == 0 ) && ( ( not defined $plot->{cb_min} ) || ( not defined $plot->{cb_max} ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @values == 0 and not defined $plot->{"cb_min"} && defined $plot->{"cb_max"}) 0 7 7
Condition16%1/6
scalar @values == 0 and not defined $plot->{"cb_min"} && defined $plot->{"cb_max"}
!ll&&!rl&&r
700
defined $plot->{'cb_min'} && defined $plot->{'cb_max'}
!ll&&!rl&&r
000
MC/DC0%0/3
scalar @values == 0 and not defined $plot->{"cb_min"} && defined $plot->{"cb_max"}
scalar @values == 0 defined $plot->{'cb_min'} defined $plot->{'cb_max'}
Truth table25%1/4
A and not(B && C)
A= scalar @values == 0B= defined $plot->{'cb_min'}C= defined $plot->{'cb_max'}
ABCresult
0XX0
1110
10X1
1101
1268 0 die "no cell of the data holds a number, so $current_sub has nothing to color by";
1269 }
1270 7 my $log = bool_option( $plot->{cb_logscale}, 'cb_logscale', $current_sub );
1271 7 ▶ my $colorbar = bool_option( $plot->{colorbar_on} // 1, 'colorbar_on', $current_sub );
Condition50%1/2
$plot->{"colorbar_on"} // 1
l!l
07
MC/DC0%0/1
$plot->{"colorbar_on"} // 1
$plot->{"colorbar_on"}
Truth table50%1/2
A
A= $plot->{"colorbar_on"}
Aresult
11
00
1272 7 my ( $lo, $hi ) = color_scale( $plot, \@values, $log );
1273 7 ▶ my $undef_color = hex_of( $plot->{undef_color} // 'gray', '"undef_color"' );
Condition50%1/2
$plot->{"undef_color"} // "gray"
l!l
07
MC/DC0%0/1
$plot->{"undef_color"} // "gray"
$plot->{"undef_color"}
Truth table50%1/2
A
A= $plot->{"undef_color"}
Aresult
11
00
1274 7 my ( $nr, $nc ) = ( scalar @rows, scalar @{$cols} );
1275 7 my %g = ( set => [], palette => 1, solo => 'colored_table' );
1276 7 push @{ $g{set} }, palette({ cmap => default_cmap( $plot, 'gist_rainbow' ), lo => $lo, hi => $hi, log => $log, colorbar => $colorbar, label => $plot->{cblabel} });
1277 7 push @{ $g{set} }, sprintf( 'set object 1 rectangle from -0.5,-0.5 to %s,%s behind fc rgb %s fs solid 1.0 noborder', gp_num( $nc - 0.5 ), gp_num( $nr - 0.5 ), gp_color($undef_color) );
1278 7 push @{ $g{set} }, 'unset xtics', 'set link x2', 'set x2tics scale 0', tics( 'x2', $cols, [ 0 .. $nc - 1 ] ), 'set ytics scale 0', tics( 'y', \@rows, [ 0 .. $nr - 1 ] );
1279 7 $g{plot} = [ image_clause( \@matrix, \%g ) ];
1280 7 my $grid = datablock( [ map { my $r = $_; map { [ $_, $r, $_ - 0.5, $_ + 0.5, $r - 0.5, $r + 0.5 ] } 0 .. $nc - 1 } 0 .. $nr - 1 ] );
1281 7 push @{ $g{plot} }, "$grid using 1:2:3:4:5:6 with boxxyerror fs empty lc rgb \"black\" lw 1 notitle";
1282 # Each number to 15 significant digits, as Perl writes it into the JSON that
1283 # matplotlib's table shows as it stands; gnuplot's "%g" kept 6, and drew
1284 # 1234567 as 1.23457e+06.
1285 7 my $number_format = 'sprintf("%.15g", $3)';
1286 7 ▶ if ( bool_option( $plot->{show_numbers}, 'show_numbers', $current_sub ) && $native ) {
Branch: 2 branches
BranchTrueFalseTotal
if (bool_option($plot->{'show_numbers'}, 'show_numbers', $current_sub) and $native) { } 4 3 7
elsif (bool_option($plot->{'show_numbers'}, 'show_numbers', $current_sub)) { } 3 0 3
Condition66%2/3
bool_option($plot->{"show_numbers"}, "show_numbers", $current_sub) and $native
!ll&&!rl&&r
034
MC/DC50%1/2
bool_option($plot->{"show_numbers"}, "show_numbers", $current_sub) and $native
bool_option($plot->{"show_numbers"}, "show_numbers", $current_sub) $native
Truth table66%2/3
A and B
A= bool_option($plot->{"show_numbers"}, "show_numbers", $current_sub)B= $native
ABresult
0X0
100
111
1287 # gnuplot's own palette runs from black, so a number written in black,
1288 # as matplotlib writes it, could not be read on the darkest cells: each
1289 # is written in white on a cell darker than mid-gray, by the cell's
1290 # luminance (ITU-R BT.709 weights, as in WCAG's relative luminance).
1291 4 ▶ my @cells = map { my $r = $_; map { [ $_, $r, $matrix[$r][$_] ] } grep { ( defined $matrix[$r][$_] ) && is_finite( $matrix[$r][$_] ) } 0 .. $nc - 1 } 0 .. $nr - 1;
Condition66%2/3
defined $matrix[$r][$_] && is_finite($matrix[$r][$_])
!ll&&!rl&&r
4012
MC/DC50%1/2
defined $matrix[$r][$_] && is_finite($matrix[$r][$_])
defined $matrix[$r][$_] is_finite($matrix[$r][$_])
Truth table66%2/3
A && B
A= defined $matrix[$r][$_]B= is_finite($matrix[$r][$_])
ABresult
0X0
100
111
1292 4 foreach my $cell (@cells) {
1293 12 ▶ my $at = ( $hi == $lo ) ? 0 : $log ? ( log( $cell->[2] > 0 ? $cell->[2] : $lo ) - log($lo) ) / ( log($hi) - log($lo) ) : ( $cell->[2] - $lo ) / ( $hi - $lo );
Branch: 3 branches
BranchTrueFalseTotal
$hi == $lo ? : 0 12 12
$log ? : 0 12 12
$cell->[2] > 0 ? : 0 0 0
1294 12 ▶ $at = $at < 0 ? 0 : $at > 1 ? 1 : $at;
Branch: 2 branches
BranchTrueFalseTotal
$at < 0 ? : 0 12 12
$at > 1 ? : 0 12 12
1295 12 my $hex = palette_at( default_cmap( $plot, 'gist_rainbow' ), $at );
1296 12 my ( $r, $gr, $b ) = map { hex( substr $hex, $_, 2 ) / 255 } ( 1, 3, 5 );
1297 12 ▶ push @{$cell}, ( 0.2126 * $r + 0.7152 * $gr + 0.0722 * $b < 0.5 ) ? 0xffffff : 0;
Branch: 1 branch
BranchTrueFalseTotal
0.2126 * $r + 0.7152 * $gr + 0.0722 * $b < 0.5 ? : 8 4 12
1298 }
1299 4 my $numbers = datablock( \@cells );
1300 4 ▶ push @{ $g{plot} }, "$numbers using 1:2:($number_format):4 with labels center tc rgb variable notitle" if defined $numbers;
Branch: 1 branch
BranchTrueFalseTotal
if defined $numbers 4 0 4
1301 } elsif ( bool_option( $plot->{show_numbers}, 'show_numbers', $current_sub ) ) {
1302 3 ▶ my $numbers = datablock( [ map { my $r = $_; map { [ $_, $r, $matrix[$r][$_] ] } grep { ( defined $matrix[$r][$_] ) && is_finite( $matrix[$r][$_] ) } 0 .. $nc - 1 } 0 .. $nr - 1 ] );
Condition66%2/3
defined $matrix[$r][$_] && is_finite($matrix[$r][$_])
!ll&&!rl&&r
208
MC/DC50%1/2
defined $matrix[$r][$_] && is_finite($matrix[$r][$_])
defined $matrix[$r][$_] is_finite($matrix[$r][$_])
Truth table66%2/3
A && B
A= defined $matrix[$r][$_]B= is_finite($matrix[$r][$_])
ABresult
0X0
100
111
1303 3 ▶ push @{ $g{plot} }, "$numbers using 1:2:($number_format) with labels center notitle" if defined $numbers;
Branch: 1 branch
BranchTrueFalseTotal
if defined $numbers 3 0 3
1304 }
1305 7 return \%g;
1306 }
1307 9 ▶sub draw_pie {
Subroutine draw_pie: called CC=15 SCAR=27.2
Pod undocumented
1308 # Wedges in matplotlib's order and colors, counterclockwise from 3
1309 # o'clock, labelled outside and, with "autopct", inside.
1310 9 my ( $plot, $axes ) = @_;
1311 9 my @keys = key_order_of( $plot, $plot->{data} );
1312 9 foreach my $key (@keys) {
1313 22 my $v = $plot->{data}{$key};
1314 22 ▶ die "\"$key\" is not a number, which $current_sub needs to size a wedge" unless looks_like_number($v);
Branch: 1 branch
BranchTrueFalseTotal
unless &looks_like_number($v) 0 22 22
1315 22 ▶ die "\"$key\" is not a finite number, which $current_sub needs to size a wedge" unless is_finite($v);
Branch: 1 branch
BranchTrueFalseTotal
unless is_finite($v) 0 22 22
1316 22 ▶ die "\"$key\" is $v, but $current_sub cannot size a wedge below 0" if $v < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $v < 0 0 22 22
1317 }
1318 9 my $total = sum( map { $plot->{data}{$_} } @keys );
1319 9 ▶ die "every wedge of $current_sub is 0, so there is no pie to divide between them" unless $total > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $total > 0 0 9 9
1320 9 my %at;
1321 9 foreach my $arg ( [ 'labeldistance', 1.1 ], [ 'pctdistance', 0.6 ] ) { # matplotlib's defaults
1322 18 my ( $name, $default ) = @{$arg};
1323 18 ▶ $at{$name} = $plot->{$name} // $default;
Condition66%2/3
$plot->{$name} // $default
l!l&&r!l&&!r
1170
MC/DC0%0/2
$plot->{$name} // $default
$plot->{$name} $default
Truth table66%2/3
A // B
A= $plot->{$name}B= $default
ABresult
1X1
011
000
1324 18 check_numbers( [ $at{$name} ], "\"$name\"", $current_sub );
1325 }
1326 9 ▶ my $pct = $plot->{autopct} // '';
Condition100%2/2
$plot->{"autopct"} // ""
l!l
81
MC/DC100%1/1
$plot->{"autopct"} // ""
$plot->{"autopct"}
Truth table100%2/2
A
A= $plot->{"autopct"}
Aresult
11
00
1327 9 ▶ if ( ( $pct ne '' ) && ( ( ref $pct ) || ( $pct !~ m/^(?:[^%]|%%)*%[-+ 0#]*\d*(?:\.\d+)?[dieEfFgG](?:[^%]|%%)*$/ ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pct ne "" and ref $pct || !($pct =~ /^(?:[^%]|%%)*%[-+ 0#]*\d*(?:\.\d+)?[dieEfFgG](?:[^%]|%%)*$/)) 1 8 9
Condition83%5/6
$pct ne "" and ref $pct || !($pct =~ /^(?:[^%]|%%)*%[-+ 0#]*\d*(?:\.\d+)?[dieEfFgG](?:[^%]|%%)*$/)
!ll&&!rl&&r
171
ref $pct or not $pct =~ /^(?:[^%]|%%)*%[-+ 0#]*\d*(?:\.\d+)?[dieEfFgG](?:[^%]|%%)*$/
l!l&&r!l&&!r
017
MC/DC66%2/3
$pct ne "" and ref $pct || !($pct =~ /^(?:[^%]|%%)*%[-+ 0#]*\d*(?:\.\d+)?[dieEfFgG](?:[^%]|%%)*$/)
$pct ne "" ref $pct not $pct =~ /^(?:[^%]|%%)*%[-+ 0#]*\d*(?:\.\d+)?[dieEfFgG](?:[^%]|%%)*$/
Truth table75%3/4
A and B or not(C)
A= $pct ne ""B= ref $pctC= not $pct =~ /^(?:[^%]|%%)*%[-+ 0#]*\d*(?:\.\d+)?[dieEfFgG](?:[^%]|%%)*$/
ABCresult
0XX0
1000
11X1
1011
1328 1 die "\"autopct\" is a format with one number in it, such as '%1.1f%%', for the gnuplot engine, not \"$pct\": a Python function is matplotlib's alone";
1329 }
1330 8 my %g = ( set => [ 'set size ratio -1', 'unset border', 'unset xtics', 'unset ytics', 'set xrange [-1.25:1.25]', 'set yrange [-1.25:1.25]' ], solo => 'pie', no_margin => [ 'left', 'right', 'top', 'bottom' ] );
1331 8 my ( @wedges, $angle );
1332 8 $angle = 0;
1333 8 my $pi = 4 * atan2( 1, 1 );
1334 8 foreach my $i ( 0 .. $#keys ) {
1335 21 my $sweep = 360 * $plot->{data}{ $keys[$i] } / $total;
1336 21 push @wedges, [ 0, 0, 1, $angle, $angle + $sweep, color_int( next_color( $axes, 'patches' ) ) ];
1337 21 my $mid = ( $angle + $sweep / 2 ) * $pi / 180;
1338 21 my ( $cx, $cy ) = ( cos $mid, sin $mid );
1339 21 ▶ my $align = ( $cx * $at{labeldistance} < 0 ) ? 'right' : 'left'; # as matplotlib aligns them
Branch: 1 branch
BranchTrueFalseTotal
$cx * $at{'labeldistance'} < 0 ? : 14 7 21
1340 21 push @{ $g{set} }, sprintf( 'set label %s at %s,%s %s front', gp_str( $keys[$i] ), gp_num( $cx * $at{labeldistance} ), gp_num( $cy * $at{labeldistance} ), $align );
1341 21 ▶ if ( $pct ne '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pct ne "") 20 1 21
1342 20 my $text = sprintf $pct, 100 * $plot->{data}{ $keys[$i] } / $total;
1343 20 push @{ $g{set} }, sprintf( 'set label %s at %s,%s center front', gp_str($text), gp_num( $cx * $at{pctdistance} ), gp_num( $cy * $at{pctdistance} ) );
1344 }
1345 21 $angle += $sweep;
1346 }
1347 8 my $block = datablock( [ grep { $_->[4] > $_->[3] } @wedges ] );
1348 8 $g{plot} = ["$block using 1:2:3:4:5:6 with circles fs solid 1.0 noborder lc rgb variable notitle"];
1349 8 return \%g;
1350 }
1351 16 ▶sub check_xy {
Subroutine check_xy: called CC=11 SCAR=32.6
Pod undocumented
1352 # Die unless x and y are arrays of numbers of one length, naming the line.
1353 16 my ( $xy, $what ) = @_;
1354 16 ▶ die "$what must be [ \\\@x, \\\@y ] in $current_sub" unless ( ref $xy eq 'ARRAY' ) && ( scalar @{$xy} == 2 ) && ( ref $xy->[0] eq 'ARRAY' ) && ( ref $xy->[1] eq 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $xy eq "ARRAY" and scalar @{$xy;} == 2 and ref $xy->[0] eq "ARRAY" and ref $xy->[1] eq "ARRAY" 0 16 16
Condition33%3/9
ref $xy eq "ARRAY" and scalar @{$xy;} == 2 and ref $xy->[0] eq "ARRAY" and ref $xy->[1] eq "ARRAY"
!ll&&!rl&&r
0016
ref $xy eq "ARRAY" and scalar @{$xy;} == 2 and ref $xy->[0] eq "ARRAY"
!ll&&!rl&&r
0016
ref $xy eq "ARRAY" and scalar @{$xy;} == 2
!ll&&!rl&&r
0016
MC/DC0%0/4
ref $xy eq "ARRAY" and scalar @{$xy;} == 2 and ref $xy->[0] eq "ARRAY" and ref $xy->[1] eq "ARRAY"
ref $xy eq "ARRAY" scalar @{$xy;} == 2 ref $xy->[0] eq "ARRAY" ref $xy->[1] eq "ARRAY"
Truth table20%1/5
A and B and C and D
A= ref $xy eq "ARRAY"B= scalar @{$xy;} == 2C= ref $xy->[0] eq "ARRAY"D= ref $xy->[1] eq "ARRAY"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1355 0 ▶ die "$what has " . scalar( @{ $xy->[0] } ) . ' x values but ' . scalar( @{ $xy->[1] } ) . " y values in $current_sub: x & y must be of equal length" if scalar @{ $xy->[0] } != scalar @{ $xy->[1] };
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$xy->[0];} != scalar @{$xy->[1];} 0 16 16
1356 16 foreach my $axis ( 0, 1 ) {
1357 32 ▶ my @bad = grep { ( not defined ) || ( not looks_like_number($_) ) } @{ $xy->[$axis] };
Condition33%1/3
defined $_ && &looks_like_number($_)
!ll&&!rl&&r
00422
MC/DC0%0/2
defined $_ && &looks_like_number($_)
defined $_ &looks_like_number($_)
Truth table33%1/3
A && B
A= defined $_B= &looks_like_number($_)
ABresult
0X0
100
111
1358 0 ▶ die "$what has " . ( $axis ? 'y' : 'x' ) . ' values that are undefined or not numbers ("' . join( '", "', map { $_ // 'undef' } @bad[ 0 .. min( $#bad, 4 ) ] ) . "\") in $current_sub" if scalar @bad;
Branch: 2 branches
BranchTrueFalseTotal
if scalar @bad 0 32 32
$axis ? : 0 0 0
Condition0%0/2
$_ // "undef"
l!l
00
MC/DC0%0/1
$_ // "undef"
$_
Truth table0%0/2
A
A= $_
Aresult
11
00
1359 }
1360 }
1361 12 ▶sub draw_plot {
Subroutine draw_plot: called CC=18 SCAR=30.3
Pod undocumented
1362 # Lines: one [ \@x, \@y ] pair, an array of them, or a hash of them (or of
1363 # y values alone, against 0 .. n-1), each in the next color of the cycle,
1364 # as plot_helper draws them.
1365 12 my ( $plot, $axes ) = @_;
1366 12 ▶ my $legend = bool_option( $plot->{show_legend} // 1, 'show_legend', $current_sub );
Condition50%1/2
$plot->{"show_legend"} // 1
l!l
012
MC/DC0%0/1
$plot->{"show_legend"} // 1
$plot->{"show_legend"}
Truth table50%1/2
A
A= $plot->{"show_legend"}
Aresult
11
00
1367 0 my %g = ( set => [ map { "set logscale $_" } logscale_axes( $plot->{logscale}, $current_sub ) ], plot => [] );
1368 12 my $data = $plot->{data};
1369 12 my @lines; # [ \@x, \@y, label ]
1370 12 ▶ if ( ref $data eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $data eq 'ARRAY') { } 7 5 12
elsif (ref $data eq 'HASH') { } 5 0 5
1371 7 ▶ $data = [$data] if ( scalar @{$data} == 2 ) && ( ref $data->[0] eq 'ARRAY' ) && ( ref $data->[1] eq 'ARRAY' ) && ( ref $data->[0][0] ne 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$data;} == 2 and ref $data->[0] eq "ARRAY" and ref $data->[1] eq "ARRAY" and ref $data->[0][0] ne "ARRAY" 6 1 7
Condition44%4/9
scalar @{$data;} == 2 and ref $data->[0] eq "ARRAY" and ref $data->[1] eq "ARRAY" and ref $data->[0][0] ne "ARRAY"
!ll&&!rl&&r
016
scalar @{$data;} == 2 and ref $data->[0] eq "ARRAY" and ref $data->[1] eq "ARRAY"
!ll&&!rl&&r
007
scalar @{$data;} == 2 and ref $data->[0] eq "ARRAY"
!ll&&!rl&&r
007
MC/DC25%1/4
scalar @{$data;} == 2 and ref $data->[0] eq "ARRAY" and ref $data->[1] eq "ARRAY" and ref $data->[0][0] ne "ARRAY"
scalar @{$data;} == 2 ref $data->[0] eq "ARRAY" ref $data->[1] eq "ARRAY" ref $data->[0][0] ne "ARRAY"
Truth table40%2/5
A and B and C and D
A= scalar @{$data;} == 2B= ref $data->[0] eq "ARRAY"C= ref $data->[1] eq "ARRAY"D= ref $data->[0][0] ne "ARRAY"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1372 7 foreach my $i ( 0 .. $#{$data} ) {
1373 8 check_xy( $data->[$i], "index $i" );
1374 8 push @lines, [ @{ $data->[$i] }, undef ];
1375 }
1376 } elsif ( ref $data eq 'HASH' ) {
1377 5 foreach my $set ( key_order_of( $plot, $data ) ) {
1378 8 my $xy = $data->{$set};
1379 8 ▶ die "$set must have two arrays, x and y coordinates, or one array of y values" unless ref $xy eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $xy eq "ARRAY" 0 8 8
1380 8 my $n_refs = grep { ref } @{$xy};
1381 8 ▶ if ( ( $n_refs == 0 ) && ( scalar @{$xy} > 0 ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($n_refs == 0 and scalar @{$xy;} > 0) { } 3 5 8
elsif ($n_refs < scalar @{$xy;}) { } 0 5 5
Condition66%2/3
$n_refs == 0 and scalar @{$xy;} > 0
!ll&&!rl&&r
503
MC/DC50%1/2
$n_refs == 0 and scalar @{$xy;} > 0
$n_refs == 0 scalar @{$xy;} > 0
Truth table66%2/3
A and B
A= $n_refs == 0B= scalar @{$xy;} > 0
ABresult
0X0
100
111
1382 3 $xy = [ [ 0 .. $#{$xy} ], $xy ];
1383 5 } elsif ( $n_refs < scalar @{$xy} ) {
1384 0 die "$current_sub: set \"$set\" mixes arrays with plain values: it must be [ \\\@x, \\\@y ] or one array of y values";
1385 }
1386 8 check_xy( $xy, "set \"$set\"" );
1387 8 ▶ push @lines, [ @{$xy}, $legend ? $set : undef ];
Branch: 1 branch
BranchTrueFalseTotal
$legend ? : 8 0 8
1388 }
1389 } else {
1390 0 die "$current_sub: \"data\" is a [ \\\@x, \\\@y ] pair, an array of them, or a hash of them";
1391 }
1392 12 foreach my $line (@lines) {
1393 16 my ( $x, $y, $label ) = @{$line};
1394 16 my $block = datablock( [ map { [ $x->[$_], $y->[$_] ] } 0 .. $#{$x} ] );
1395 16 my $color = next_color( $axes, 'lines' );
1396 16 ▶ next unless defined $block;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $block 0 16 16
1397 16 push @{ $g{plot} }, "$block using 1:2 with lines " . lw() . "lc rgb " . gp_color($color) . ' ' . key_title($label);
1398 16 ▶ $g{legend} = 1 if defined $label;
Branch: 1 branch
BranchTrueFalseTotal
if defined $label 8 8 16
1399 }
1400 12 return \%g;
1401 }
1402 17 ▶sub draw_scatter {
Subroutine draw_scatter: called CC=27 SCAR=34.5
Pod undocumented
1403 # Points: one set of 2 or 3 keys, the third coloring the points by a
1404 # colormap, or a hash of such sets, each in its own color or, colored by a
1405 # key, its own marker, as scatter_helper draws them.
1406 17 my ( $plot, $axes ) = @_;
1407 17 my $data = $plot->{data};
1408 17 ▶ die "scatter only takes 1) hashes of arrays (single or 2) hash of hash of arrays; but " . ref($data) . ' was entered' unless ref $data eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "HASH" 0 17 17
1409 17 my %ref_counts;
1410 17 $ref_counts{ ref $data->{$_} }++ foreach keys %{$data};
1411 17 ▶ die "different kinds of data were entered to $current_sub; should be simple hash or hash of arrays." if scalar keys %ref_counts > 1;
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %ref_counts > 1 0 17 17
1412 17 ▶ my $single = defined $ref_counts{ARRAY} ? 1 : defined $ref_counts{HASH} ? 0 : die 'Could not determine scatter type for the data.';
Branch: 2 branches
BranchTrueFalseTotal
defined $ref_counts{'ARRAY'} ? : 13 4 17
defined $ref_counts{'HASH'} ? : 4 0 4
1413 17 ▶ die "$current_sub: \"key_order\" orders the sets of a hash of sets; for the axes of a single set, use \"keys\"" if $single && defined $plot->{key_order};
Branch: 1 branch
BranchTrueFalseTotal
if $single and defined $plot->{"key_order"} 0 17 17
Condition66%2/3
$single and defined $plot->{"key_order"}
!ll&&!rl&&r
4130
MC/DC0%0/2
$single and defined $plot->{"key_order"}
$single defined $plot->{"key_order"}
Truth table66%2/3
A and B
A= $singleB= defined $plot->{"key_order"}
ABresult
0X0
100
111
1414 17 my $log_cb = bool_option( $plot->{cb_logscale}, 'cb_logscale', $current_sub );
1415 17 ▶ my $colorbar = bool_option( $plot->{colorbar_on} // 1, 'colorbar_on', $current_sub );
Condition50%1/2
$plot->{"colorbar_on"} // 1
l!l
017
MC/DC0%0/1
$plot->{"colorbar_on"} // 1
$plot->{"colorbar_on"}
Truth table50%1/2
A
A= $plot->{"colorbar_on"}
Aresult
11
00
1416 0 my %g = ( set => [ map { "set logscale $_" } logscale_axes( $plot->{logscale}, $current_sub ) ], plot => [] );
1417 17 ▶ my $by_case = sub { lc $a cmp lc $b || $a cmp $b };
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
lc $a cmp lc $b or $a cmp $b 43 0 43
1418 20 ▶ my $axes_of = sub { # ( \@x_and_y_keys, $color_key ) of one set
Subroutine __ANON__: called CC=12 SCAR=27.7
1419 20 my ( $set, $where ) = @_;
1420 20 ▶ my @keys = defined $plot->{keys} ? check_key_order({ keys => $plot->{keys}, data => $set, option => 'keys', sub => $current_sub . $where }) : sort $by_case keys %{$set};
Branch: 1 branch
BranchTrueFalseTotal
defined $plot->{'keys'} ? : 0 20 20
1421 20 my $n = scalar keys %{$set};
1422 20 ▶ die "scatterplots can only take 2 or 3 keys as data, but $current_sub received $n$where" if ( $n != 2 ) && ( $n != 3 );
Branch: 1 branch
BranchTrueFalseTotal
if $n != 2 and $n != 3 0 20 20
Condition66%2/3
$n != 2 and $n != 3
!ll&&!rl&&r
8120
MC/DC0%0/2
$n != 2 and $n != 3
$n != 2 $n != 3
Truth table66%2/3
A and B
A= $n != 2B= $n != 3
ABresult
0X0
100
111
1423 20 my $color_key;
1424 20 ▶ if ( defined $plot->{color_key} ) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $plot->{'color_key'}) { } 2 18 20
elsif (scalar @keys == 3) { } 10 8 18
elsif ($n == 3) { } 0 8 8
1425 2 $color_key = $plot->{color_key};
1426 2 ▶ die "\"$color_key\" isn't defined for this scatter$where" unless defined $set->{$color_key};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $set->{$color_key} 2 0 2
1427 0 @keys = grep { $_ ne $color_key } @keys;
1428 } elsif ( scalar @keys == 3 ) {
1429 10 $color_key = pop @keys;
1430 } elsif ( $n == 3 ) {
1431 0 my %named = map { $_ => 1 } @keys;
1432 0 ($color_key) = grep { not $named{$_} } sort $by_case keys %{$set};
1433 }
1434 18 ▶ die "$current_sub needs one key for x and one for y$where, but \"keys\" and \"color_key\" leave " . scalar(@keys) if scalar @keys != 2;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @keys != 2 0 18 18
1435 18 ▶ check_scatter_values( $set->{$_}, "\"$_\"$where", $current_sub ) foreach ( @keys, defined $color_key ? $color_key : () );
Branch: 1 branch
BranchTrueFalseTotal
defined $color_key ? : 10 8 18
1436 18 ▶ check_scatter_lengths( $set, [ @keys, defined $color_key ? $color_key : () ], $where, $current_sub );
Branch: 1 branch
BranchTrueFalseTotal
defined $color_key ? : 10 8 18
1437 18 return ( \@keys, $color_key );
1438 17 };
1439 17 my @drawn; # [ label, \%set, \@keys, $color_key ]
1440 17 ▶ if ($single) {
Branch: 1 branch
BranchTrueFalseTotal
if ($single) { } 13 4 17
1441 13 push @drawn, [ undef, $data, $axes_of->( $data, '' ) ];
1442 } else {
1443 4 ▶ my $legend = bool_option( $plot->{show_legend} // 1, 'show_legend', $current_sub );
Condition50%1/2
$plot->{"show_legend"} // 1
l!l
04
MC/DC0%0/1
$plot->{"show_legend"} // 1
$plot->{"show_legend"}
Truth table50%1/2
A
A= $plot->{"show_legend"}
Aresult
11
00
1444 4 my @order = key_order_of( $plot, $data );
1445 4 foreach my $name (@order) {
1446 7 my $inner = $data->{$name};
1447 7 ▶ my $set = ( ( scalar keys %{$inner} > 0 ) && ( not grep { ref } values %{$inner} ) ) ? { map { $_ => [ $inner->{$_} ] } keys %{$inner} } : $inner;
Branch: 1 branch
BranchTrueFalseTotal
scalar keys %{$inner;} > 0 && !grep({ref $_;} values %{$inner;}) ? : 2 5 7
Condition66%2/3
scalar keys %{$inner;} > 0 and not grep({ref $_;} values %{$inner;})
!ll&&!rl&&r
052
MC/DC50%1/2
scalar keys %{$inner;} > 0 and not grep({ref $_;} values %{$inner;})
scalar keys %{$inner;} > 0 not grep({ref $_;} values %{$inner;})
Truth table66%2/3
A and not(B)
A= scalar keys %{$inner;} > 0B= not grep({ref $_;} values %{$inner;})
ABresult
0X0
100
111
1448 7 ▶ push @drawn, [ $legend ? $name : undef, $set, $axes_of->( $set, " of set \"$name\"" ) ];
Branch: 1 branch
BranchTrueFalseTotal
$legend ? : 7 0 7
1449 }
1450 }
1451 15 my @z = map { finite_values( @{ $_->[1]{ $_->[3] } } ) } grep { defined $_->[3] } @drawn;
1452 15 my $colored = grep { defined $_->[3] } @drawn;
1453 15 ▶ if ($colored) {
Branch: 1 branch
BranchTrueFalseTotal
if ($colored) 10 5 15
1454 10 my ( $lo, $hi ) = color_scale( $plot, \@z, $log_cb );
1455 10 my ($cb_key) = map { $_->[3] } grep { defined $_->[3] } @drawn;
1456 10 ▶ push @{ $g{set} }, palette({ cmap => default_cmap( $plot, 'gist_rainbow' ), lo => $lo, hi => $hi, log => $log_cb, colorbar => $colorbar, label => $plot->{cblabel} // $cb_key });
Condition66%2/3
$plot->{"cblabel"} // $cb_key
l!l&&r!l&&!r
190
MC/DC0%0/2
$plot->{"cblabel"} // $cb_key
$plot->{"cblabel"} $cb_key
Truth table66%2/3
A // B
A= $plot->{"cblabel"}B= $cb_key
ABresult
1X1
011
000
1457 10 $g{palette} = 1;
1458 }
1459 15 my $marker_i = 0;
1460 15 foreach my $d (@drawn) {
1461 18 my ( $label, $set, $keys, $color_key ) = @{$d};
1462 18 my ( $x, $y ) = @{$set}{ @{$keys} };
1463 18 ▶ if ( defined $color_key ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $color_key) { } 10 8 18
1464 10 my $c = $set->{$color_key};
1465 10 ▶ my $pt = $single ? 7 : $marker_cycle[ $marker_i++ % @marker_cycle ];
Branch: 1 branch
BranchTrueFalseTotal
$single ? : 10 0 10
1466 10 ▶ my $block = datablock( [ map { [ $x->[$_], $y->[$_], ( $log_cb && $c->[$_] <= 0 ) ? 'NaN' : $c->[$_] ] } 0 .. $#{$x} ] );
Branch: 1 branch
BranchTrueFalseTotal
$log_cb && $c->[$_] <= 0 ? : 0 29 29
Condition66%2/3
$log_cb and $c->[$_] <= 0
!ll&&!rl&&r
2720
MC/DC0%0/2
$log_cb and $c->[$_] <= 0
$log_cb $c->[$_] <= 0
Truth table66%2/3
A and B
A= $log_cbB= $c->[$_] <= 0
ABresult
0X0
100
111
1467 10 ▶ push @{ $g{plot} }, "$block using 1:2:3 with points " . ( $native ? '' : "pt $pt " ) . ps() . "lc palette " . key_title($label) if defined $block;
Branch: 2 branches
BranchTrueFalseTotal
if defined $block 10 0 10
$native ? : 6 4 10
1468 } else {
1469 8 my $block = datablock( [ map { [ $x->[$_], $y->[$_] ] } 0 .. $#{$x} ] );
1470 8 my $color = next_color( $axes, 'patches' );
1471 8 ▶ push @{ $g{plot} }, "$block using 1:2 with points " . ( $native ? '' : 'pt 7 ' ) . ps() . "lc rgb " . gp_color($color) . ' ' . key_title($label) if defined $block;
Branch: 2 branches
BranchTrueFalseTotal
if defined $block 8 0 8
$native ? : 2 6 8
1472 }
1473 18 ▶ $g{legend} = 1 if defined $label;
Branch: 1 branch
BranchTrueFalseTotal
if defined $label 6 12 18
1474 }
1475 15 @g{ 'default_xlabel', 'default_ylabel' } = @{ $drawn[0][2] };
1476 15 return \%g;
1477 }
1478 6 ▶sub interpolate {
Subroutine interpolate: called CC=5 SCAR=17.8
Pod undocumented
1479 # numpy.interp of sorted x and y at each of @at, NaN outside x's range or
1480 # beside a NaN y.
1481 6 my ( $x, $y, $at ) = @_;
1482 6 my @out;
1483 6 foreach my $v ( @{$at} ) {
1484 606 my $j = bin_index( $v, $x ); # the segment $v is in; undef outside x's range
1485 606 ▶ if ( not defined $j ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $j) { } 0 606 606
elsif ($j == $#{$x;} or $$x[$j + 1] == $x->[$j]) { } 0 606 606
1486 0 push @out, 'nan';
1487 606 ▶ } elsif ( ( $j == $#{$x} ) || ( $x->[ $j + 1 ] == $x->[$j] ) ) {
Condition33%1/3
$j == $#{$x;} or $$x[$j + 1] == $x->[$j]
l!l&&r!l&&!r
00606
MC/DC0%0/2
$j == $#{$x;} or $$x[$j + 1] == $x->[$j]
$j == $#{$x;} $$x[$j + 1] == $x->[$j]
Truth table33%1/3
A or B
A= $j == $#{$x;}B= $$x[$j + 1] == $x->[$j]
ABresult
1X1
011
000
1488 0 push @out, $y->[$j];
1489 } else {
1490 606 push @out, $y->[$j] + ( $y->[ $j + 1 ] - $y->[$j] ) * ( $v - $x->[$j] ) / ( $x->[ $j + 1 ] - $x->[$j] );
1491 }
1492 }
1493 6 return @out;
1494 }
1495 3 ▶sub draw_wide {
Subroutine draw_wide: called CC=19 SCAR=30.4
Pod undocumented
1496 # Repeated runs of a curve: each run faintly, their mean, and a band one
1497 # standard deviation either side of it, as write_wide_group draws them.
1498 3 my ( $plot, $axes ) = @_;
1499 3 ▶ my $legend = bool_option( $plot->{show_legend} // 1, 'show_legend', $current_sub );
Condition50%1/2
$plot->{"show_legend"} // 1
l!l
03
MC/DC0%0/1
$plot->{"show_legend"} // 1
$plot->{"show_legend"}
Truth table50%1/2
A
A= $plot->{"show_legend"}
Aresult
11
00
1500 3 my %g = ( set => [], plot => [] );
1501 3 my @groups; # [ \@runs, color, label ]
1502 3 ▶ if ( ref $plot->{data} eq 'HASH' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $plot->{'data'} eq 'HASH') { } 1 2 3
elsif (ref $plot->{'data'} eq 'ARRAY') { } 2 0 2
1503 1 ▶ die "$current_sub: \"data\" is a HASH of groups, so \"color\" must be a HASH of one color per group" if ( defined $plot->{color} ) && ( ref $plot->{color} ne 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if defined $plot->{"color"} and ref $plot->{"color"} ne "HASH" 0 1 1
Condition33%1/3
defined $plot->{"color"} and ref $plot->{"color"} ne "HASH"
!ll&&!rl&&r
100
MC/DC0%0/2
defined $plot->{"color"} and ref $plot->{"color"} ne "HASH"
defined $plot->{"color"} ref $plot->{"color"} ne "HASH"
Truth table33%1/3
A and B
A= defined $plot->{"color"}B= ref $plot->{"color"} ne "HASH"
ABresult
0X0
100
111
1504 1 my $i = 0;
1505 1 foreach my $group ( sort keys %{ $plot->{data} } ) {
1506 1 check_wide_runs( $plot->{data}{$group}, "group \"$group\"", $current_sub );
1507 1 ▶ my $color = defined $plot->{color}{$group} ? hex_of( $plot->{color}{$group}, "\"color\" of \"$group\"" ) : cycle_color($i);
Branch: 1 branch
BranchTrueFalseTotal
defined $plot->{'color'}{$group} ? : 0 1 1
1508 1 ▶ push @groups, [ $plot->{data}{$group}, $color, $legend ? $group : undef ];
Branch: 1 branch
BranchTrueFalseTotal
$legend ? : 1 0 1
1509 1 $i++;
1510 }
1511 } elsif ( ref $plot->{data} eq 'ARRAY' ) {
1512 2 ▶ die "$current_sub: \"data\" is one unlabelled group, so \"color\" must be a single color, not a " . ref( $plot->{color} ) . ' reference' if ref $plot->{color};
Branch: 1 branch
BranchTrueFalseTotal
if ref $plot->{"color"} 0 2 2
1513 2 check_wide_runs( $plot->{data}, '"data"', $current_sub );
1514 2 ▶ push @groups, [ $plot->{data}, ( defined $plot->{color} ? hex_of( $plot->{color}, '"color"' ) : $native ? cycle_color(0) : hex_of( 'b', '"color"' ) ), undef ];
Branch: 2 branches
BranchTrueFalseTotal
defined $plot->{'color'} ? : 1 1 2
$native ? : 0 1 1
1515 } else {
1516 0 die "$current_sub cannot take ref type \"" . ref( $plot->{data} ) . '" for "data"';
1517 }
1518 3 foreach my $group (@groups) {
1519 3 my ( $runs, $color, $label ) = @{$group};
1520 3 my @xs = map { finite_values( @{ $_->[0] } ) } @{$runs};
1521 3 my ( $lo, $hi ) = ( min(@xs), max(@xs) );
1522 3 my @at = linspace( $lo, $hi, 101 ); # as the matplotlib engine's np.linspace(min, max, 101)
1523 3 my @ys;
1524 3 foreach my $run ( @{$runs} ) {
1525 6 my @order = sort { $run->[0][$a] <=> $run->[0][$b] } 0 .. $#{ $run->[0] }; # Perl's sort is stable, as argsort(kind = 'stable')
1526 6 my @x = @{ $run->[0] }[@order];
1527 6 my @y = @{ $run->[1] }[@order];
1528 6 my $block = datablock( [ map { [ $x[$_], $y[$_] ] } 0 .. $#x ] );
1529 6 push @{ $g{plot} }, "$block using 1:2 with lines " . lw() . "lc rgb " . gp_color( with_alpha( $color, 0.15 ) ) . ' notitle';
1530 6 push @ys, [ interpolate( \@x, \@y, \@at ) ];
1531 }
1532 3 my ( @mean_rows, @band_rows );
1533 3 foreach my $k ( 0 .. $#at ) {
1534 303 my @v = grep { not is_nan($_) } map { $_->[$k] } @ys;
1535 303 ▶ if ( scalar @v == 0 ) { # no run reaches here: a gap, as matplotlib leaves it
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @v == 0) 0 303 303
1536 0 push @mean_rows, [ $at[$k], 'nan' ];
1537 0 push @band_rows, [ $at[$k], 'nan', 'nan' ];
1538 0 next;
1539 }
1540 303 my $mean = sum(@v) / @v;
1541 303 my $sd = sqrt( sum( map { ( $_ - $mean )**2 } @v ) / @v ); # numpy's std, n below the line
1542 303 push @mean_rows, [ $at[$k], $mean ];
1543 303 push @band_rows, [ $at[$k], $mean - $sd, $mean + $sd ];
1544 }
1545 3 my $band = datablock( \@band_rows );
1546 3 ▶ push @{ $g{plot} }, "$band using 1:2:3 with filledcurves fs transparent solid 0.3 noborder lc rgb " . gp_color($color) . ' notitle' if defined $band;
Branch: 1 branch
BranchTrueFalseTotal
if defined $band 3 0 3
1547 3 my $mean = datablock( \@mean_rows );
1548 3 ▶ push @{ $g{plot} }, "$mean using 1:2 with lines " . lw() . "lc rgb " . gp_color($color) . ' ' . key_title($label) if defined $mean;
Branch: 1 branch
BranchTrueFalseTotal
if defined $mean 3 0 3
1549 3 ▶ $g{legend} = 1 if defined $label;
Branch: 1 branch
BranchTrueFalseTotal
if defined $label 1 2 3
1550 }
1551 3 return \%g;
1552 }
1553 5 my %draw = (
1554 bar => \&draw_bar, barh => \&draw_bar, boxplot => \&draw_boxplot, colored_table => \&draw_colored_table,
1555 hist => \&draw_hist, hist2d => \&draw_hist2d, imshow => \&draw_imshow, pie => \&draw_pie,
1556 plot => \&draw_plot, scatter => \&draw_scatter, violin => \&draw_violin, violinplot => \&draw_violin,
1557 wide => \&draw_wide,
1558 );
1559 35 ▶sub one_text {
Subroutine one_text: called CC=2 SCAR=7.0
Pod undocumented
1560 # A text option as plain_text reads it; one value, not one per call.
1561 35 my ( $plot, $option ) = @_;
1562 35 my $value = $plot->{$option};
1563 35 ▶ die "$current_sub: \"$option\" is one piece of text for the gnuplot engine, not a " . ref($value) . ' reference' if ref $value;
Branch: 1 branch
BranchTrueFalseTotal
if ref $value 0 35 35
1564 35 return plain_text( $value, $option, $engine, $current_sub );
1565 }
1566 135 ▶sub thin_tics {
Subroutine thin_tics: called CC=32 SCAR=38.5
Pod undocumented
1567 # In a subplot of several, the tic commands that leave room between the
1568 # labels, as matplotlib's locator does (tick_step): gnuplot chooses its
1569 # tics by the range alone, and a 2 by 2 grid of a 6.4 by 4.8 inch figure
1570 # had a count axis labelled every 10 from 0 to 80, the labels touching. A
1571 # number axis gets a step; an axis of category labels too long for the
1572 # room between them gets a smaller font, as small as 6 points. None for a
1573 # figure of one plot or a log axis. Under style => 'native' too, since a
1574 # label running into the next is no part of gnuplot's look: in a native
1575 # 2 by 2 grid the counts up a hist and "Mark" and "Matthew" overlapped.
1576 135 my ( $graphs, $plot, $margin ) = @_;
1577 135 ▶ return () unless defined $panel_w;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $panel_w 120 15 135
1578 15 my @set = map { @{ $_->[1]{set} } } @{$graphs};
1579 15 my @out;
1580 15 foreach my $axis ( 'x', 'y' ) {
1581 30 ▶ my $i = ( $axis eq 'x' ) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$axis eq 'x' ? : 15 15 30
1582 30 ▶ next if grep { m/^(?:set logscale \Q$axis\E|unset \Q$axis\Etics)$/ } @set;
Branch: 1 branch
BranchTrueFalseTotal
if grep {/^(?:set logscale \Q$axis\E|unset \Q$axis\Etics)$/;} @set 8 22 30
1583 22 ▶ next if grep { ( defined $plot->{$_} ) && ( axis_scale( $plot->{$_}, $_, $engine, $current_sub ) eq 'log' ) } ( $axis eq 'x' ) ? ( 'xscale', 'set_xscale' ) : ( 'yscale', 'set_yscale' );
Branch: 2 branches
BranchTrueFalseTotal
if grep {defined $plot->{$_} and axis_scale($plot->{$_}, $_, $engine, $current_sub) eq "log";} $axis eq "x" ? ("xscale", "set_xscale") : ("yscale", "set_yscale") 0 22 22
$axis eq 'x' ? : 11 11 22
Condition33%1/3
defined $plot->{$_} && axis_scale($plot->{$_}, $_, $engine, $current_sub) eq 'log'
!ll&&!rl&&r
4400
MC/DC0%0/2
defined $plot->{$_} && axis_scale($plot->{$_}, $_, $engine, $current_sub) eq 'log'
defined $plot->{$_} axis_scale($plot->{$_}, $_, $engine, $current_sub) eq 'log'
Truth table33%1/3
A && B
A= defined $plot->{$_}B= axis_scale($plot->{$_}, $_, $engine, $current_sub) eq 'log'
ABresult
0X0
100
111
1584 22 my $labels = $tic_labels{$axis};
1585 22 ▶ if ( defined $labels ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $labels) 3 19 22
1586 # Category labels. Measured on the PNG of a 2 by 2 grid, where
1587 # "Mark" and "Matthew" ran together: a character is 0.55 of the
1588 # font size across on average, neighbours need 0.6 of a character
1589 # between them, and the n categories of a bar plot, with its bars'
1590 # widths and margins, span about n + 1 of the room between two;
1591 # up the side, a label needs 1.3 of the font size.
1592 3 ▶ next if scalar @{$labels} < 2;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$labels;} < 2 0 3 3
1593 3 my $room = plot_length($axis) / ( scalar( @{$labels} ) + 1 );
1594 my $need = ( $axis eq 'x' )
1595 3 ▶ ? 0.55 * max( map { ( length( $labels->[$_] ) + length( $labels->[ $_ - 1 ] ) ) / 2 + 0.6 } 1 .. $#{$labels} )
Branch: 1 branch
BranchTrueFalseTotal
$axis eq 'x' ? : 3 0 3
1596 : 1.3;
1597 3 my $points = $room / ( $need * $font_scale ); # the size that fits, as matplotlib's 10-point tick labels are sized here
1598 3 ▶ push @out, sprintf( 'set %stics font ",%.1f"', $axis, max( 6, $points ) * $font_scale ) if $points < 10;
Branch: 1 branch
BranchTrueFalseTotal
if $points < 10 3 0 3
1599 3 next;
1600 }
1601 # The range: as set, by the plot or the caller, or the data's with the
1602 # margins write_axes gives it.
1603 19 my ( $lo, $hi );
1604 19 foreach my $line (@set) {
1605 45 ▶ ( $lo, $hi ) = ( $1, $2 ) if $line =~ m/^set \Q$axis\Erange \[([-+0-9.eE]+):([-+0-9.eE]+)\]$/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^set \Q$axis\Erange \[([-+0-9.eE]+):([-+0-9.eE]+)\]$/ 0 45 45
1606 }
1607 19 ▶ foreach my $option ( ( $axis eq 'x' ) ? ('set_xlim') : ( 'set_ylim', 'ylim' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
$axis eq 'x' ? : 8 11 19
1608 30 ▶ next unless defined $plot->{$option};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $plot->{$option} 30 0 30
1609 0 my ( $l, $h ) = axis_limits( $plot->{$option}, $option, $engine, $current_sub );
1610 0 ▶ $lo = $l if defined $l;
Branch: 1 branch
BranchTrueFalseTotal
if defined $l 0 0 0
1611 0 ▶ $hi = $h if defined $h;
Branch: 1 branch
BranchTrueFalseTotal
if defined $h 0 0 0
1612 }
1613 19 ▶ if ( ( not defined $lo ) || ( not defined $hi ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $lo and defined $hi) 19 0 19
Condition33%1/3
defined $lo and defined $hi
!ll&&!rl&&r
1900
MC/DC0%0/2
defined $lo and defined $hi
defined $lo defined $hi
Truth table33%1/3
A and B
A= defined $loB= defined $hi
ABresult
0X0
100
111
1614 19 ▶ my @v = grep { ( defined ) && looks_like_number($_) && is_finite($_) } map { $_->[$i] } @extent;
Condition66%4/6
defined $_ && &looks_like_number($_) && is_finite($_)
!ll&&!rl&&r
3020494
defined $_ and &looks_like_number($_)
!ll&&!rl&&r
3020494
MC/DC33%1/3
defined $_ && &looks_like_number($_) && is_finite($_)
defined $_ &looks_like_number($_) is_finite($_)
Truth table50%2/4
A and B && C
A= defined $_B= &looks_like_number($_)C= is_finite($_)
ABCresult
0XX0
10X0
1100
1111
1615 19 ▶ next if scalar @v == 0;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @v == 0 0 19 19
1616 19 my ( $dlo, $dhi ) = ( min(@v), max(@v) );
1617 19 ▶ my ( $low_side, $high_side ) = ( $axis eq 'x' ) ? ( 'left', 'right' ) : ( 'bottom', 'top' );
Branch: 1 branch
BranchTrueFalseTotal
$axis eq 'x' ? : 8 11 19
1618 19 ▶ $lo //= $dlo - ( $margin->{$low_side} ? 0.05 * ( $dhi - $dlo ) : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$margin->{$low_side} ? : 15 4 19
Condition50%1/2
$lo //= $dlo - ($margin->{$low_side} ? "0.05" * ($dhi - $dlo) : 0)
l!l
019
MC/DC0%0/1
$lo //= $dlo - ($margin->{$low_side} ? "0.05" * ($dhi - $dlo) : 0)
$lo
Truth table50%1/2
A
A= $lo
Aresult
11
00
1619 19 ▶ $hi //= $dhi + ( $margin->{$high_side} ? 0.05 * ( $dhi - $dlo ) : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$margin->{$high_side} ? : 19 0 19
Condition50%1/2
$hi //= $dhi + ($margin->{$high_side} ? "0.05" * ($dhi - $dlo) : 0)
l!l
019
MC/DC0%0/1
$hi //= $dhi + ($margin->{$high_side} ? "0.05" * ($dhi - $dlo) : 0)
$hi
Truth table50%1/2
A
A= $hi
Aresult
11
00
1620 }
1621 19 ▶ ( $lo, $hi ) = ( $hi, $lo ) if $lo > $hi; # imshow's y runs downward
Branch: 1 branch
BranchTrueFalseTotal
if $lo > $hi 0 19 19
1622 19 ▶ my $step = tick_step( $lo, $hi, tick_bins( plot_length($axis), ( $axis eq 'x' ) ? 3 : 2 ) );
Branch: 1 branch
BranchTrueFalseTotal
$axis eq 'x' ? : 8 11 19
1623 19 ▶ push @out, "set ${axis}tics " . gp_num($step) if defined $step;
Branch: 1 branch
BranchTrueFalseTotal
if defined $step 19 0 19
1624 }
1625 15 return @out;
1626 }
1627 163 ▶sub write_axes {
Subroutine write_axes: called CC=34 SCAR=35.8
Pod undocumented
1628 # One plot, with its "add" graphs drawn first, on the same axes, as
1629 # matplotlib draws them.
1630 163 my ( $plot, $where ) = @_;
1631 163 my $axes = { lines => 0, patches => 0, native => 0 }; # matplotlib's two color cycles are the axes': one for lines, one for bars, wedges and scatter points; gnuplot's one, under style => 'native' (next_color)
1632 163 @points = ();
1633 163 @extent = ();
1634 163 %tic_labels = ();
1635 163 ▶ my @graphs = map { [ $_, $draw{ $_->{plot_type} }->( $_, $axes ) ] } ( @{ $plot->{add} // [] }, $plot );
Condition100%2/2
$plot->{"add"} // []
l!l
18145
MC/DC100%1/1
$plot->{"add"} // []
$plot->{"add"}
Truth table100%2/2
A
A= $plot->{"add"}
Aresult
11
00
1636 139 ▶ if ( scalar @graphs > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @graphs > 1) 2 137 139
1637 2 my @solo = grep { defined $_->[1]{solo} } @graphs;
1638 2 ▶ die "$current_sub: the gnuplot engine draws plot_type \"$solo[0][1]{solo}\" on axes of its own, so it cannot share them with an \"add\" graph$where" if scalar @solo;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @solo 1 1 2
1639 1 foreach my $kind ( 'palette', 'categories' ) {
1640 2 my @with = grep { $_->[1]{$kind} } @graphs;
1641 2 ▶ next if scalar @with < 2;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @with < 2 2 0 2
1642 0 ▶ die "$current_sub: the gnuplot engine has one " . ( $kind eq 'palette' ? 'color scale' : 'set of category labels' ) . ' per plot, and plot types ' . join( ' and ', map { "\"$_->[0]{plot_type}\"" } @with ) . " each have their own$where";
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'palette' ? : 0 0 0
1643 }
1644 }
1645 138 say {$fh} 'reset';
1646 138 print {$fh} @blocks;
1647 138 @blocks = ();
1648 138 say {$fh} 'set encoding utf8';
1649 # matplotlib's 5% margin round the data (rcParams axes.xmargin and
1650 # ymargin), but none below a bar or a bin, which sit on the axis.
1651 138 my %margin = map { $_ => 'graph 0.05' } ( 'left', 'right', 'top', 'bottom' );
1652 138 ▶ $margin{$_} = 0 foreach map { @{ $_->[1]{no_margin} // [] } } @graphs;
Condition100%2/2
$_->[1]{"no_margin"} // []
l!l
8356
MC/DC100%1/1
$_->[1]{"no_margin"} // []
$_->[1]{"no_margin"}
Truth table100%2/2
A
A= $_->[1]{"no_margin"}
Aresult
11
00
1653 # Under style => 'native', none of matplotlib's look: gnuplot's own tics,
1654 # fill, error bar caps, and autoscaling out to the next tic.
1655 138 ▶ if ( not $native ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($native) 70 68 138
1656 70 say {$fh} 'set tics out nomirror';
1657 70 say {$fh} 'set style fill solid 1.0 noborder';
1658 70 say {$fh} 'set errorbars 0'; # matplotlib's error bars have no caps (rcParams errorbar.capsize)
1659 70 say {$fh} 'set autoscale fix';
1660 70 say {$fh} 'set offsets ' . join( ', ', @margin{ 'left', 'right', 'top', 'bottom' } );
1661 }
1662 138 say {$fh} $_ foreach map { @{ $_->[1]{set} } } @graphs;
1663 138 my %text;
1664 138 foreach my $pair ( [ 'title', 'set_title' ], [ 'xlabel', 'set_xlabel' ], [ 'ylabel', 'set_ylabel' ] ) {
1665 410 my ( $short, $long ) = @{$pair};
1666 # "title" wins over "set_title", as plt's rename of one to the other
1667 410 ▶ my $given = defined $plot->{$short} ? $short : defined $plot->{$long} ? $long : undef;
Branch: 2 branches
BranchTrueFalseTotal
defined $plot->{$short} ? : 33 377 410
defined $plot->{$long} ? : 1 376 377
1668 410 ▶ $text{$short} = one_text( $plot, $given ) if defined $given;
Branch: 1 branch
BranchTrueFalseTotal
if defined $given 34 376 410
1669 }
1670 136 foreach my $axis ( 'x', 'y' ) {
1671 272 ▶ next if defined $text{"${axis}label"};
Branch: 1 branch
BranchTrueFalseTotal
if defined $text{"${axis}label"} 4 268 272
1672 268 my ($default) = grep { defined } map { $_->[1]{"default_${axis}label"} } @graphs;
1673 268 ▶ $text{"${axis}label"} = $default if defined $default;
Branch: 1 branch
BranchTrueFalseTotal
if defined $default 42 226 268
1674 }
1675 136 ▶ say {$fh} "set title " . gp_str( $text{title} ) . ( $native ? '' : sprintf( ' font ",%.1f"', 12 * $font_scale ) ) if defined $text{title}; # matplotlib's title is 12 points (rcParams axes.titlesize)
Branch: 2 branches
BranchTrueFalseTotal
if defined $text{"title"} 28 108 136
$native ? : 2 26 28
1676 136 say {$fh} "set ${_} " . gp_str( $text{$_} ) foreach grep { defined $text{$_} } ( 'xlabel', 'ylabel' );
1677 136 foreach my $range ( [ 'set_xlim', 'x' ], [ 'set_ylim', 'y' ], [ 'ylim', 'y' ] ) {
1678 406 my ( $option, $axis ) = @{$range};
1679 406 ▶ next unless defined $plot->{$option};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $plot->{$option} 401 5 406
1680 5 my ( $lo, $hi ) = axis_limits( $plot->{$option}, $option, $engine, $current_sub );
1681 4 ▶ say {$fh} "set ${axis}range [" . ( defined $lo ? gp_num($lo) : '*' ) . ':' . ( defined $hi ? gp_num($hi) : '*' ) . ']';
Branch: 2 branches
BranchTrueFalseTotal
defined $lo ? : 3 1 4
defined $hi ? : 4 0 4
1682 }
1683 135 foreach my $option ( grep { defined $plot->{$_} } ( 'xscale', 'set_xscale', 'yscale', 'set_yscale' ) ) {
1684 3 ▶ my $axis = ( $option =~ m/x/ ) ? 'x' : 'y';
Branch: 1 branch
BranchTrueFalseTotal
$option =~ /x/ ? : 0 3 3
1685 3 ▶ say {$fh} ( ( axis_scale( $plot->{$option}, $option, $engine, $current_sub ) eq 'log' ) ? "set logscale $axis" : "unset logscale $axis" );
Branch: 1 branch
BranchTrueFalseTotal
axis_scale($plot->{$option}, $option, $engine, $current_sub) eq 'log' ? : 2 1 3
1686 }
1687 135 say {$fh} $_ foreach thin_tics( \@graphs, $plot, \%margin );
1688 135 ▶ if ( ( grep { $_->[1]{legend} } @graphs ) && $native ) {
Branch: 2 branches
BranchTrueFalseTotal
if (grep {$_->[1]{'legend'};} @graphs and $native) { } 15 120 135
elsif (grep {$_->[1]{'legend'};} @graphs) { } 16 104 120
Condition100%3/3
grep {$_->[1]{"legend"};} @graphs and $native
!ll&&!rl&&r
1041615
MC/DC100%2/2
grep {$_->[1]{"legend"};} @graphs and $native
grep {$_->[1]{"legend"};} @graphs $native
Truth table100%3/3
A and B
A= grep {$_->[1]{"legend"};} @graphsB= $native
ABresult
0X0
100
111
1689 # gnuplot's own place for the key, but opaque: gnuplot draws each entry
1690 # as it draws that clause, so later bars covered the earlier entries of a
1691 # grouped or stacked bar plot, and its legend could not be read.
1692 15 say {$fh} 'set key default';
1693 15 say {$fh} 'set key opaque';
1694 121 } elsif ( grep { $_->[1]{legend} } @graphs ) {
1695 16 say {$fh} 'set key inside ' . key_place() . ' opaque box reverse Left samplen 2 spacing 1.1 width 1 vertical maxcols 1';
1696 } else {
1697 104 say {$fh} 'unset key';
1698 }
1699 135 my @clauses = map { @{ $_->[1]{plot} } } @graphs;
1700 135 ▶ if ( scalar @clauses == 0 ) { # nothing finite to draw: the axes alone, as matplotlib leaves them
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @clauses == 0) 0 135 135
1701 0 ▶ say {$fh} 'set xrange [0:1]' unless grep { /^set xrange/ } map { @{ $_->[1]{set} } } @graphs;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {/^set xrange/;} map({@{$_->[1]{"set"};};} @graphs) 0 0 0
1702 0 say {$fh} 'set yrange [0:1]';
1703 0 @clauses = ('NaN notitle');
1704 }
1705 135 say {$fh} 'plot ' . join( ", \\\n\t", @clauses );
1706 }
1707 # The SVGs each script draws, which are given their creator note once it has
1708 # run: script's path => [ [ output_file, creator_note ], ... ]. A shared "fh"
1709 # gathers every figure written into it, and is run by the last.
1710 5 my %svg_notes;
1711 2 ▶sub creator_user {
Subroutine creator_user: called CC=6 SCAR=19.0
Pod undocumented
1712 # Who is running gnuplot, found as Python's getpass.getuser() finds the user
1713 # for the matplotlib engine's note (Python 3.14, Lib/getpass.py): the first
1714 # of these variables that is set, then the password database.
1715 2 foreach my $name ( 'LOGNAME', 'USER', 'LNAME', 'USERNAME' ) {
1716 5 ▶ return decoded_text( $ENV{$name} ) if ( defined $ENV{$name} ) && ( $ENV{$name} ne '' );
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{$name} and $ENV{$name} ne "" 1 4 5
Condition66%2/3
defined $ENV{$name} and $ENV{$name} ne ""
!ll&&!rl&&r
401
MC/DC50%1/2
defined $ENV{$name} and $ENV{$name} ne ""
defined $ENV{$name} $ENV{$name} ne ""
Truth table66%2/3
A and B
A= defined $ENV{$name}B= $ENV{$name} ne ""
ABresult
0X0
100
111
1717 }
1718 1 my $user = eval { ( getpwuid $< )[0] }; # getpwuid dies as unimplemented on MSWin32
1719 1 ▶ return ( ( defined $user ) && ( $user ne '' ) ) ? decoded_text($user) : 'unknown user';
Branch: 1 branch
BranchTrueFalseTotal
defined $user && $user ne '' ? : 1 0 1
Condition33%1/3
defined $user and $user ne ""
!ll&&!rl&&r
001
MC/DC0%0/2
defined $user and $user ne ""
defined $user $user ne ""
Truth table33%1/3
A and B
A= defined $userB= $user ne ""
ABresult
0X0
100
111
1720 }
1721 2 ▶sub creator_svg {
Subroutine creator_svg: called CC=8 SCAR=21.6
Pod undocumented
1722 # Give an SVG gnuplot has drawn into $drawn the note matplotlib gives its
1723 # own, in <dc:title>, and write it to $file. gnuplot has no way to write
1724 # metadata, nor to read the user or the host, so this is done here once it
1725 # has run, and not by a script written with "execute => 0" and run later.
1726 # gnuplot's own <title>Gnuplot</title>, which a browser shows as the
1727 # figure's name, and its <desc>, whose version this note now carries, are
1728 # taken out: the note is all the metadata an SVG from matplotlib has.
1729 #
1730 # $drawn is a temporary file (see render), so that $file is written once.
1731 # gnuplot wrote $file and this wrote it again, so that a viewer watching
1732 # the file saw it written twice: Eye of GNOME 45.3 stopped reloading it.
1733 # $drawn may be $file itself.
1734 2 my ( $drawn, $file, $note, $version ) = @_;
1735 2 my $host = eval { Sys::Hostname::hostname() }; # dies when it cannot find the name
1736 2 ▶ $host = ( ( defined $host ) && ( $host ne '' ) ) ? decoded_text($host) : 'unknown host';
Branch: 1 branch
BranchTrueFalseTotal
defined $host && $host ne '' ? : 2 0 2
Condition33%1/3
defined $host and $host ne ""
!ll&&!rl&&r
002
MC/DC0%0/2
defined $host and $host ne ""
defined $host $host ne ""
Truth table33%1/3
A and B
A= defined $hostB= $host ne ""
ABresult
0X0
100
111
1737 2 $note = decoded_text($note) . ", gnuplot $version, by " . creator_user() . " on $host";
1738 2 $note =~ s/&/&amp;/g; # first, or the escapes below would be escaped again
1739 2 $note =~ s/</&lt;/g;
1740 2 $note =~ s/>/&gt;/g;
1741 2 ▶ open my $in, '<:raw', $drawn or die "$current_sub: can't read \"$drawn\", which gnuplot was to write: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $in, "<:raw", $drawn or die qq[${current_sub}: can't read "$drawn", which gnuplot was to write: $!] 2 0 2
1742 2 my $svg = do { local $/; <$in> };
1743 2 ▶ close $in or die "$current_sub: can't close \"$drawn\": $!";
Branch: 1 branch
BranchTrueFalseTotal
close $in or die qq[${current_sub}: can't close "$drawn": $!] 2 0 2
1744 2 $svg =~ s{<title>Gnuplot</title>\n}{};
1745 2 $svg =~ s{<desc>Produced by GNUPLOT[^<]*</desc>\n}{};
1746 2 my ( $before, $after ) = svg_creator_metadata();
1747 2 ▶ $svg =~ s{(<svg\b[^>]*>)}{$1 . Encode::encode( 'UTF-8', $before . $note . $after )}e
Branch: 1 branch
BranchTrueFalseTotal
$svg =~ s/(<svg\b[^>]*>)/$1 . &Encode::encode("UTF-8", $before . $note . $after);/e or die qq[${current_sub}: "$file" has no <svg> tag for the creator note to follow] 2 0 2
1748 or die "$current_sub: \"$file\" has no <svg> tag for the creator note to follow";
1749 2 ▶ open my $out, '>:raw', $file or die "$current_sub: can't write \"$file\": $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $out, ">:raw", $file or die qq[${current_sub}: can't write "$file": $!] 2 0 2
1750 2 print {$out} $svg;
1751 2 ▶ close $out or die "$current_sub: can't close \"$file\": $!";
Branch: 1 branch
BranchTrueFalseTotal
close $out or die qq[${current_sub}: can't close "$file": $!] 2 0 2
1752 }
1753 153 ▶sub render {
Subroutine render: called CC=36 SCAR=36.3
Pod undocumented
1754 # plt's figure as a gnuplot script, which is run unless "execute" is false.
1755 # Returns the script's path. Takes what Matplotlib::Simple::Matplotlib::render does.
1756 153 my ( $args, $context ) = @_;
1757 153 $current_sub = $context->{sub};
1758 153 ▶ $native = ( ( $context->{style} // 'native' ) eq 'native' ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
($context->{'style'} // 'native') eq 'native' ? : 78 75 153
Condition50%1/2
$context->{"style"} // "native"
l!l
1530
MC/DC0%0/1
$context->{"style"} // "native"
$context->{"style"}
Truth table50%1/2
A
A= $context->{"style"}
Aresult
11
00
1759 153 ( $n_blocks, @blocks ) = (0);
1760 153 my $file = $args->{output_file};
1761 153 my ($ext) = ( $file =~ m/\.([^.\/\\]+)\z/ );
1762 153 ▶ $ext = lc( $ext // '' );
Condition50%1/2
$ext // ""
l!l
1530
MC/DC0%0/1
$ext // ""
$ext
Truth table50%1/2
A
A= $ext
Aresult
11
00
1763 153 ▶ $px_per_pt = ( $ext eq 'pdf' ) ? 1 : 100 / 72;
Branch: 1 branch
BranchTrueFalseTotal
$ext eq 'pdf' ? : 0 153 153
1764 153 ▶ $font_scale = ( $ext eq 'pdf' ) ? 1 : 1.1;
Branch: 1 branch
BranchTrueFalseTotal
$ext eq 'pdf' ? : 0 153 153
1765 # In 15 digits, as a double perl stringifies it; a quadmath perl wrote all 36.
1766 153 $point_size = sprintf '%.15g', 1.1 * $px_per_pt;
1767 153 ▶ if ( not defined $terminal_of{$ext} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $terminal_of{$ext}) 1 152 153
1768 1 die "$current_sub: the gnuplot engine writes " . join( ', ', map { ".$_" } sort keys %terminal_of ) . " files, and \"$file\" is none of them; engine => 'matplotlib' writes the rest";
1769 }
1770 152 my ( $w, $h ) = ( $fig_width, $fig_height );
1771 152 ▶ $w *= $args->{scale} // 1;
Condition100%2/2
$args->{"scale"} // 1
l!l
3149
MC/DC100%1/1
$args->{"scale"} // 1
$args->{"scale"}
Truth table100%2/2
A
A= $args->{"scale"}
Aresult
11
00
1772 152 ▶ $h *= $args->{scale} // 1;
Condition100%2/2
$args->{"scale"} // 1
l!l
3149
MC/DC100%1/1
$args->{"scale"} // 1
$args->{"scale"}
Truth table100%2/2
A
A= $args->{"scale"}
Aresult
11
00
1773 152 ▶ $w *= $args->{scalex} // 1;
Condition100%2/2
$args->{"scalex"} // 1
l!l
1151
MC/DC100%1/1
$args->{"scalex"} // 1
$args->{"scalex"}
Truth table100%2/2
A
A= $args->{"scalex"}
Aresult
11
00
1774 152 ▶ $h *= $args->{scaley} // 1;
Condition50%1/2
$args->{"scaley"} // 1
l!l
0152
MC/DC0%0/1
$args->{"scaley"} // 1
$args->{"scaley"}
Truth table50%1/2
A
A= $args->{"scaley"}
Aresult
11
00
1775 152 ▶ my @plots = $context->{single_plot} ? ( [ $args, '' ] ) : map { [ $args->{plots}[$_], " at subplot $_" ] } 0 .. $#{ $args->{plots} };
Branch: 1 branch
BranchTrueFalseTotal
$context->{'single_plot'} ? : 145 7 152
1776 152 ▶ ( $panel_w, $panel_h ) = ( $args->{nrows} * $args->{ncols} > 1 ) ? ( $w / $args->{ncols}, $h / $args->{nrows} ) : ( undef, undef );
Branch: 1 branch
BranchTrueFalseTotal
$args->{'nrows'} * $args->{'ncols'} > 1 ? : 4 148 152
1777 # Everything is drawn into a string first, so that a plot refused part
1778 # way leaves nothing of the figure in a shared "fh".
1779 152 my $script = '';
1780 152 ▶ open $fh, '>:encoding(UTF-8)', \$script or die "can't write to a string: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">:encoding(UTF-8)", \$script or die "can't write to a string: $!" 152 0 152
1781 152 foreach my $plot (@plots) {
1782 163 write_axes( @{$plot} );
1783 }
1784 124 close $fh;
1785 124 ▶ my $suptitle = defined $args->{suptitle} ? one_text( $args, 'suptitle' ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $args->{'suptitle'} ? : 1 123 124
1786 124 ▶ my $multiplot = ( ( scalar @plots > 1 ) || ( defined $suptitle ) ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
scalar @plots > 1 || defined $suptitle ? : 5 119 124
Condition100%3/3
scalar @plots > 1 or defined $suptitle
l!l&&r!l&&!r
41119
MC/DC100%2/2
scalar @plots > 1 or defined $suptitle
scalar @plots > 1 defined $suptitle
Truth table100%3/3
A or B
A= scalar @plots > 1B= defined $suptitle
ABresult
1X1
011
000
1787 # A lexical, not $fh: the file is flushed and closed when it goes out of
1788 # scope, as Matplotlib::Simple::Matplotlib's is, so that the script is whole when the
1789 # caller reads it.
1790 124 my $out = script_handle( $args, '.gp', $current_sub );
1791 124 ( my $note = creator_note($current_sub) ) =~ s/[\r\n]+/ /g; # a comment ends at the line's end
1792 124 say {$out} "# $note";
1793 # Each figure from a clean slate: a shared "fh" holds several, and gnuplot
1794 # keeps every setting from one plot to the next.
1795 124 say {$out} 'reset session';
1796 124 say {$out} 'set encoding utf8';
1797 124 say {$out} 'set terminal ' . $terminal_of{$ext}->( $w, $h );
1798 124 say {$out} 'set output ' . gp_str($file);
1799 124 ▶ say {$out} "set multiplot layout $args->{nrows},$args->{ncols}" . ( defined $suptitle ? ' title ' . gp_str($suptitle) : '' ) if $multiplot;
Branch: 2 branches
BranchTrueFalseTotal
if $multiplot 5 119 124
defined $suptitle ? : 1 4 5
1800 124 print {$out} Encode::decode( 'UTF-8', $script );
1801 124 ▶ say {$out} 'unset multiplot' if $multiplot;
Branch: 1 branch
BranchTrueFalseTotal
if $multiplot 5 119 124
1802 124 say {$out} 'unset output';
1803 # To STDERR, where "print" writes, for creator_svg to read once the script
1804 # has run. GPVAL_VERSION is a number, such as 6.0, and the patch level text.
1805 124 say {$out} 'print sprintf("Matplotlib::Simple gnuplot %.1f.%s", GPVAL_VERSION, GPVAL_PATCHLEVEL)';
1806 124 ▶ push @{ $svg_notes{ $out->filename } }, [ $file, creator_note($current_sub) ] if $ext eq 'svg';
Branch: 1 branch
BranchTrueFalseTotal
if $ext eq "svg" 122 2 124
1807 124 ▶ if ( $args->{execute} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"execute"}) 1 123 124
1808 # gnuplot runs a copy of the script in which each SVG is drawn into a
1809 # temporary file, which creator_svg then writes to output_file once,
1810 # with its note (see creator_svg). The script itself, whose path is
1811 # returned and which may be run again by hand, still names output_file.
1812 # The copy has the script's lines, so gnuplot's messages give the
1813 # right line numbers. An SVG named by more than one figure of a shared
1814 # "fh" holds the last, as gnuplot would have left it.
1815 1 ▶ $out->flush or die "$current_sub: can't flush \"" . $out->filename . "\": $!";
Branch: 1 branch
BranchTrueFalseTotal
$out->flush or die qq[${current_sub}: can't flush "] . $out->filename . qq[": $!] 1 0 1
1816 1 ▶ open my $in, '<:raw', $out->filename or die "$current_sub: can't read \"" . $out->filename . "\": $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $in, "<:raw", $out->filename or die qq[${current_sub}: can't read "] . $out->filename . qq[": $!] 1 0 1
1817 1 my $copy = do { local $/; <$in> };
1818 1 ▶ close $in or die "$current_sub: can't close \"" . $out->filename . "\": $!";
Branch: 1 branch
BranchTrueFalseTotal
close $in or die qq[${current_sub}: can't close "] . $out->filename . qq[": $!] 1 0 1
1819 1 my ( %drawn, @svgs );
1820 1 ▶ foreach my $svg ( @{ delete $svg_notes{ $out->filename } // [] } ) {
Condition50%1/2
delete $svg_notes{$out->filename} // []
l!l
10
MC/DC0%0/1
delete $svg_notes{$out->filename} // []
delete $svg_notes{$out->filename}
Truth table50%1/2
A
A= delete $svg_notes{$out->filename}
Aresult
11
00
1821 2 my ( $svg_file, $svg_note ) = @{$svg};
1822 2 ▶ if ( not exists $drawn{$svg_file} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $drawn{$svg_file}) 1 1 2
1823 1 $drawn{$svg_file} = File::Temp->new( DIR => File::Spec->tmpdir, TEMPLATE => 'matplotlib-simple-XXXXXX', SUFFIX => '.svg', UNLINK => 1 );
1824 1 ▶ close $drawn{$svg_file} or die "$current_sub: can't close \"" . $drawn{$svg_file}->filename . "\": $!";
Branch: 1 branch
BranchTrueFalseTotal
close $drawn{$svg_file} or die qq[${current_sub}: can't close "] . $drawn{$svg_file}->filename . qq[": $!] 1 0 1
1825 1 my ( $from, $to ) = map { Encode::encode( 'UTF-8', 'set output ' . gp_str($_) ) } ( $svg_file, $drawn{$svg_file}->filename );
1826 1 $copy =~ s/^\Q$from\E(?=\r?\n)/$to/mg;
1827 }
1828 2 @svgs = ( ( grep { $_->[0] ne $svg_file } @svgs ), [ $svg_file, $svg_note ] );
1829 }
1830 1 my $run = File::Temp->new( DIR => File::Spec->tmpdir, TEMPLATE => 'matplotlib-simple-XXXXXX', SUFFIX => '.gp', UNLINK => 1 );
1831 1 ▶ binmode $run, ':raw' or die "Can't binmode(\$run, ':raw'): $!";
Branch: 1 branch
BranchTrueFalseTotal
binmode $run, ":raw" or die "Can't binmode(\$run, ':raw'): $!" 1 0 1
1832 1 ▶ print {$run} $copy or die "$current_sub: can't write \"" . $run->filename . "\": $!";
Branch: 1 branch
BranchTrueFalseTotal
print {$run;} $copy or die qq[${current_sub}: can't write "] . $run->filename . qq[": $!] 1 0 1
1833 1 ▶ close $run or die "$current_sub: can't close \"" . $run->filename . "\": $!";
Branch: 1 branch
BranchTrueFalseTotal
close $run or die qq[${current_sub}: can't close "] . $run->filename . qq[": $!] 1 0 1
1834 1 ▶ my $stderr = run_script( [ program_from_env('MATPLOTLIB_SIMPLE_GNUPLOT') // 'gnuplot', $run->filename ] );
Condition50%1/2
program_from_env("MATPLOTLIB_SIMPLE_GNUPLOT") // "gnuplot"
l!l
01
MC/DC0%0/1
program_from_env("MATPLOTLIB_SIMPLE_GNUPLOT") // "gnuplot"
program_from_env("MATPLOTLIB_SIMPLE_GNUPLOT")
Truth table50%1/2
A
A= program_from_env("MATPLOTLIB_SIMPLE_GNUPLOT")
Aresult
11
00
1835 1 my ($version) = $stderr =~ m/^Matplotlib::Simple gnuplot (\S+)$/m;
1836 1 foreach my $svg (@svgs) {
1837 1 ▶ creator_svg( $drawn{ $svg->[0] }->filename, @{$svg}, $version // 'of unknown version' );
Condition50%1/2
$version // "of unknown version"
l!l
10
MC/DC0%0/1
$version // "of unknown version"
$version
Truth table50%1/2
A
A= $version
Aresult
11
00
1838 }
1839 }
1840 124 say 'will write ' . "\e[36;103m$file\e[0m";
1841 124 return $out->filename;
1842 }
1843 5 1;
« blib/lib/Matplotlib/Simple/Matplotlib.pm ↑ Summary blib/lib/Matplotlib/Simple/Ggplot2.pm »