Class: Polars::SeriesPlot
- Inherits:
-
Object
- Object
- Polars::SeriesPlot
- Defined in:
- lib/polars/series_plot.rb
Overview
Series.plot namespace.
Instance Method Summary collapse
-
#hist ⇒ Vega::LiteChart
Draw histogram.
-
#kde ⇒ Vega::LiteChart
Draw kernel density estimate plot.
-
#line ⇒ Vega::LiteChart
Draw line plot.
Instance Method Details
#hist ⇒ Vega::LiteChart
Draw histogram.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/polars/series_plot.rb', line 16 def hist encoding = { x: {field: @series_name, bin: true}, y: {aggregate: "count"} } Vega.lite .data(@df.rows(named: true)) .mark(type: "bar", tooltip: true) .encoding(encoding) .config(axis: {labelFontSize: 12}) end |
#kde ⇒ Vega::LiteChart
Draw kernel density estimate plot.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/polars/series_plot.rb', line 32 def kde if @series_name == "density" msg = "cannot use `plot.kde` when Series name is `'density'`" raise ArgumentError, msg end encoding = { x: {field: @series_name, type: "quantitative"}, y: {field: "density", type: "quantitative"} } Vega.lite .data(@df.rows(named: true)) .transform(density: @series_name, as: [@series_name, "density"]) .mark(type: "area", tooltip: true) .encoding(encoding) .config(axis: {labelFontSize: 12}) end |
#line ⇒ Vega::LiteChart
Draw line plot.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/polars/series_plot.rb', line 54 def line if @series_name == "index" msg = "cannot call `plot.line` when Series name is 'index'" raise ArgumentError, msg end encoding = { x: {field: "index", type: "quantitative"}, y: {field: @series_name, type: "quantitative"} } Vega.lite .data(@df.with_row_index.rows(named: true)) .mark(type: "line", tooltip: true) .encoding(encoding) .config(axis: {labelFontSize: 12}) end |