mirror of
https://github.com/red-data-tools/YouPlot.git
synced 2025-05-05 22:31:11 +08:00
Try to add density plot
This commit is contained in:
parent
305489d591
commit
71afa3cda7
@ -43,6 +43,7 @@ module Uplot
|
|||||||
parsers['barplot'] = parsers['bar']
|
parsers['barplot'] = parsers['bar']
|
||||||
parsers['boxplot'] = parsers['box']
|
parsers['boxplot'] = parsers['box']
|
||||||
parsers['count'] = parsers['c'] # barplot -c
|
parsers['count'] = parsers['c'] # barplot -c
|
||||||
|
parsers['densityplot'] = parsers['density']
|
||||||
parsers.default = nil
|
parsers.default = nil
|
||||||
|
|
||||||
main_parser.banner = <<~MSG
|
main_parser.banner = <<~MSG
|
||||||
@ -87,6 +88,8 @@ module Uplot
|
|||||||
when 'count', 'c'
|
when 'count', 'c'
|
||||||
@count = true
|
@count = true
|
||||||
barplot(data, headers)
|
barplot(data, headers)
|
||||||
|
when 'density'
|
||||||
|
density(data, headers)
|
||||||
end.render($stderr)
|
end.render($stderr)
|
||||||
|
|
||||||
print input if @output
|
print input if @output
|
||||||
@ -132,11 +135,12 @@ module Uplot
|
|||||||
|
|
||||||
def line(data, headers)
|
def line(data, headers)
|
||||||
if data.size == 1
|
if data.size == 1
|
||||||
@params[:name] ||= headers[0] if headers
|
@params[:ylabel] ||= headers[0] if headers
|
||||||
y = data[0]
|
y = data[0]
|
||||||
x = (1..y.size).to_a
|
x = (1..y.size).to_a
|
||||||
else
|
else
|
||||||
@params[:name] ||= headers[1] if headers
|
@params[:xlabel] ||= headers[0] if headers
|
||||||
|
@params[:ylabel] ||= headers[1] if headers
|
||||||
x = data[0]
|
x = data[0]
|
||||||
y = data[1]
|
y = data[1]
|
||||||
end
|
end
|
||||||
@ -148,6 +152,7 @@ module Uplot
|
|||||||
def lines(data, headers)
|
def lines(data, headers)
|
||||||
data.map! { |series| series.map(&:to_f) }
|
data.map! { |series| series.map(&:to_f) }
|
||||||
@params[:name] ||= headers[1] if headers
|
@params[:name] ||= headers[1] if headers
|
||||||
|
@params[:xlabel] ||=headers[0] if headers
|
||||||
plot = UnicodePlot.lineplot(data[0], data[1], **@params.compact)
|
plot = UnicodePlot.lineplot(data[0], data[1], **@params.compact)
|
||||||
2.upto(data.size - 1) do |i|
|
2.upto(data.size - 1) do |i|
|
||||||
UnicodePlot.lineplot!(plot, data[0], data[i], name: headers[i])
|
UnicodePlot.lineplot!(plot, data[0], data[i], name: headers[i])
|
||||||
@ -158,6 +163,7 @@ module Uplot
|
|||||||
def scatter(data, headers)
|
def scatter(data, headers)
|
||||||
data.map! { |series| series.map(&:to_f) }
|
data.map! { |series| series.map(&:to_f) }
|
||||||
@params[:name] ||= headers[1] if headers
|
@params[:name] ||= headers[1] if headers
|
||||||
|
@params[:xlabel] ||=headers[0] if headers
|
||||||
plot = UnicodePlot.scatterplot(data[0], data[1], **@params.compact)
|
plot = UnicodePlot.scatterplot(data[0], data[1], **@params.compact)
|
||||||
2.upto(data.size - 1) do |i|
|
2.upto(data.size - 1) do |i|
|
||||||
UnicodePlot.scatterplot!(plot, data[0], data[i], name: headers[i])
|
UnicodePlot.scatterplot!(plot, data[0], data[i], name: headers[i])
|
||||||
@ -165,6 +171,17 @@ module Uplot
|
|||||||
plot
|
plot
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def density(data, headers)
|
||||||
|
data.map! { |series| series.map(&:to_f) }
|
||||||
|
@params[:name] ||= headers[1] if headers
|
||||||
|
@params[:xlabel] ||=headers[0] if headers
|
||||||
|
plot = UnicodePlot.densityplot(data[0], data[1], **@params.compact)
|
||||||
|
2.upto(data.size - 1) do |i|
|
||||||
|
UnicodePlot.densityplot!(plot, data[0], data[i], name: headers[i])
|
||||||
|
end
|
||||||
|
plot
|
||||||
|
end
|
||||||
|
|
||||||
def boxplot(data, headers)
|
def boxplot(data, headers)
|
||||||
headers ||= (1..data.size).to_a
|
headers ||= (1..data.size).to_a
|
||||||
data.map! { |series| series.map(&:to_f) }
|
data.map! { |series| series.map(&:to_f) }
|
||||||
|
Loading…
Reference in New Issue
Block a user