From bf9a8e082d661653550bbe9df2b5d0bbee6df373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Redzy=C5=84ski?= Date: Mon, 15 Jun 2020 20:43:48 +0200 Subject: [PATCH] plots: add smooth template --- dvc/repo/plots/template.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/dvc/repo/plots/template.py b/dvc/repo/plots/template.py index 7713c0d8cb..d81775bd08 100644 --- a/dvc/repo/plots/template.py +++ b/dvc/repo/plots/template.py @@ -168,12 +168,46 @@ class DefaultScatterTemplate(Template): } +class SmoothLinearTemplate(Template): + DEFAULT_NAME = "smooth" + + DEFAULT_CONTENT = { + "$schema": "https://vega.github.io/schema/vega-lite/v4.json", + "data": {"values": Template.METRIC_DATA_ANCHOR}, + "title": Template.TITLE_ANCHOR, + "mark": {"type": "line"}, + "encoding": { + "x": { + "field": Template.X_ANCHOR, + "type": "quantitative", + "title": Template.X_LABEL_ANCHOR, + }, + "y": { + "field": Template.Y_ANCHOR, + "type": "quantitative", + "title": Template.Y_LABEL_ANCHOR, + "scale": {"zero": False}, + }, + "color": {"field": "rev", "type": "nominal"}, + }, + "transform": [ + { + "loess": Template.Y_ANCHOR, + "on": Template.X_ANCHOR, + "groupby": ["rev"], + "bandwidth": 0.3, + } + ], + } + + class PlotTemplates: TEMPLATES_DIR = "plots" TEMPLATES = [ DefaultLinearTemplate, DefaultConfusionTemplate, DefaultScatterTemplate, + SmoothLinearTemplate, ] @cached_property