579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
|
# File 'lib/charty/backends/pyplot.rb', line 579
def univariate_histogram(hist, name, variable_name, stat,
alpha, color, key_color, color_mapper,
multiple, element, fill, shrink)
mid_points = hist.edges.each_cons(2).map {|a, b| a + (b - a) / 2 }
orient = variable_name == :x ? :v : :h
width = shrink * (hist.edges[1] - hist.edges[0])
kw = {align: :edge}
color = if color.nil?
key_color.to_rgb
else
color_mapper[color].to_rgb
end
alpha = 1r unless fill
if fill
kw[:facecolor] = color.to_rgba(alpha: alpha).to_hex_string
if multiple == :stack || multiple == :fill || element == :bars
kw[:edgecolor] = @default_edgecolor.to_hex_string
else
kw[:edgecolor] = color.to_hex_string
end
elsif element == :bars
kw.delete(:facecolor)
kw[:edgecolor] = color.to_rgba(alpha: alpha).to_hex_string
else
kw[:color] = color.to_rgba(alpha: alpha).to_hex_string
end
kw[:label] = name unless name.nil?
ax = @pyplot.gca
if orient == :v
ax.bar(mid_points, hist.weights, width, **kw)
else
ax.barh(mid_points, hist.weights, width, **kw)
end
end
|