Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dvc/command/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ def _add_props_arguments(parser):
help="Provided CSV ot TSV datafile does not have a header.",
)
parser.add_argument("--title", default=None, help="Plot title.")
parser.add_argument("--xlab", default=None, help="X axis title.")
parser.add_argument("--ylab", default=None, help="Y axis title.")
parser.add_argument("--x-label", default=None, help="X axis label.")
parser.add_argument("--y-label", default=None, help="Y axis lebel.")


def _add_output_arguments(parser):
Expand Down
4 changes: 2 additions & 2 deletions dvc/output/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class BaseOutput:
PARAM_PLOT_TEMPLATE = "template"
PARAM_PLOT_X = "x"
PARAM_PLOT_Y = "y"
PARAM_PLOT_XLAB = "xlab"
PARAM_PLOT_YLAB = "ylab"
PARAM_PLOT_X_LABEL = "x_label"
PARAM_PLOT_Y_LABEL = "y_label"
PARAM_PLOT_TITLE = "title"
PARAM_PLOT_CSV_HEADER = "csv_header"
PARAM_PERSIST = "persist"
Expand Down
25 changes: 13 additions & 12 deletions dvc/repo/plots/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class Template:
X_ANCHOR = "<DVC_METRIC_X>"
Y_ANCHOR = "<DVC_METRIC_Y>"
TITLE_ANCHOR = "<DVC_METRIC_TITLE>"
X_TITLE_ANCHOR = "<DVC_METRIC_X_TITLE>"
Y_TITLE_ANCHOR = "<DVC_METRIC_Y_TITLE>"
X_LABEL_ANCHOR = "<DVC_METRIC_X_LABEL>"
Y_LABEL_ANCHOR = "<DVC_METRIC_Y_LABEL>"

def __init__(self, templates_dir):
self.plot_templates_dir = templates_dir
Expand Down Expand Up @@ -119,15 +119,15 @@ def _check_field_exists(data, field):
@staticmethod
def _replace_metadata_anchors(result_content, props):
props.setdefault("title", "")
props.setdefault("xlab", props.get("x"))
props.setdefault("ylab", props.get("y"))
props.setdefault("x_label", props.get("x"))
props.setdefault("y_label", props.get("y"))

replace_pairs = [
(Template.TITLE_ANCHOR, "title"),
(Template.X_ANCHOR, "x"),
(Template.Y_ANCHOR, "y"),
(Template.X_TITLE_ANCHOR, "xlab"),
(Template.Y_TITLE_ANCHOR, "ylab"),
(Template.X_LABEL_ANCHOR, "x_label"),
(Template.Y_LABEL_ANCHOR, "y_label"),
]
for anchor, key in replace_pairs:
value = props.get(key)
Expand Down Expand Up @@ -170,12 +170,12 @@ class DefaultLinearTemplate(Template):
"x": {
"field": Template.X_ANCHOR,
"type": "quantitative",
"title": Template.X_TITLE_ANCHOR,
"title": Template.X_LABEL_ANCHOR,
},
"y": {
"field": Template.Y_ANCHOR,
"type": "quantitative",
"title": Template.Y_TITLE_ANCHOR,
"title": Template.Y_LABEL_ANCHOR,
"scale": {"zero": False},
},
"color": {"field": "rev", "type": "nominal"},
Expand All @@ -195,13 +195,13 @@ class DefaultConfusionTemplate(Template):
"field": Template.X_ANCHOR,
"type": "nominal",
"sort": "ascending",
"title": Template.X_TITLE_ANCHOR,
"title": Template.X_LABEL_ANCHOR,
},
"y": {
"field": Template.Y_ANCHOR,
"type": "nominal",
"sort": "ascending",
"title": Template.Y_TITLE_ANCHOR,
"title": Template.Y_LABEL_ANCHOR,
},
"color": {"aggregate": "count", "type": "quantitative"},
"facet": {"field": "rev", "type": "nominal"},
Expand All @@ -220,12 +220,12 @@ class DefaultScatterTemplate(Template):
"x": {
"field": Template.X_ANCHOR,
"type": "quantitative",
"title": Template.X_TITLE_ANCHOR,
"title": Template.X_LABEL_ANCHOR,
},
"y": {
"field": Template.Y_ANCHOR,
"type": "quantitative",
"title": Template.Y_TITLE_ANCHOR,
"title": Template.Y_LABEL_ANCHOR,
"scale": {"zero": False},
},
"color": {"field": "rev", "type": "nominal"},
Expand Down Expand Up @@ -275,6 +275,7 @@ def get_template(self, path):

def __init__(self, dvc_dir):
self.dvc_dir = dvc_dir
print("PlotTemplates.__init__")

if not os.path.exists(self.templates_dir):
makedirs(self.templates_dir, exist_ok=True)
Expand Down
4 changes: 2 additions & 2 deletions dvc/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
BaseOutput.PARAM_PLOT_TEMPLATE: str,
BaseOutput.PARAM_PLOT_X: str,
BaseOutput.PARAM_PLOT_Y: str,
BaseOutput.PARAM_PLOT_XLAB: str,
BaseOutput.PARAM_PLOT_YLAB: str,
BaseOutput.PARAM_PLOT_X_LABEL: str,
BaseOutput.PARAM_PLOT_Y_LABEL: str,
BaseOutput.PARAM_PLOT_TITLE: str,
BaseOutput.PARAM_PLOT_CSV_HEADER: bool,
}
Expand Down
5 changes: 3 additions & 2 deletions scripts/completion/dvc.bash
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ _dvc_move_COMPGEN=_dvc_compgen_files
_dvc_params='diff'
_dvc_params_diff='--all --show-json --show-md --no-path'
_dvc_plots='show diff'
_dvc_plots_show='-t --template -o --out -x -y --show-json --no-csv-header --title --xlab --ylab'
_dvc_plots_diff='-t --template --targets -o --out -x -y --show-json --no-csv-header --title --xlab --ylab'
_dvc_plots_show='-t --template -o --out -x -y --show-json --no-csv-header --title --x-label --y-label'
_dvc_plots_diff='-t --template --targets -o --out -x -y --show-json --no-csv-header --title --x-label --y-label'
_dvc_plots_modify='-t --template -x -y --no-csv-header --title --x-label --y-label'
_dvc_pull='-j --jobs -r --remote -a --all-branches -T --all-tags -f --force -d --with-deps -R --recursive'
_dvc_pull_COMPGEN=_dvc_compgen_DVCFiles
_dvc_push='-j --jobs -r --remote -a --all-branches -T --all-tags -d --with-deps -R --recursive'
Expand Down
2 changes: 1 addition & 1 deletion scripts/completion/dvc.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ _dvc_push=(
)

_dvc_plots=(
"1:Sub command:(show diff)"
"1:Sub command:(show diff modify)"
)

_dvc_remote=(
Expand Down
4 changes: 2 additions & 2 deletions tests/func/plots/test_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def test_plot_csv_one_column(tmp_dir, scm, dvc, run_copy_metrics):

props = {
"csv_header": False,
"xlab": "x_title",
"ylab": "y_title",
"x_label": "x_title",
"y_label": "y_title",
"title": "mytitle",
}
plot_string = dvc.plots.show(props=props)["metric.csv"]
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/command/test_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ def test_metrics_diff(dvc, mocker):
"y_field",
"--title",
"my_title",
"--xlab",
"--x-label",
"x_title",
"--ylab",
"--y-label",
"y_title",
"HEAD",
"tag1",
Expand All @@ -47,8 +47,8 @@ def test_metrics_diff(dvc, mocker):
"x": "x_field",
"y": "y_field",
"title": "my_title",
"xlab": "x_title",
"ylab": "y_title",
"x_label": "x_title",
"y_label": "y_title",
},
)

Expand Down