DEV Community

Cover image for Print DVC plots and metrics directly in the terminal
João Santiago
João Santiago

Posted on

1 2

Print DVC plots and metrics directly in the terminal

DVC has changed the way I handle Machine Learning projects for the better. The dvc plots diff command is a great way to see the effect of rounds of experimentation.

If you use the kitty terminal, it's possible to print DVC plots directly in the terminal without opening an external program/browser. I wrote a function for the fish shell to simplify this process.

Alt Text

Assuming you are using fish as your shell, save this code as ~/.config/fish/functions/plotit.fish

# Usage: plotit <target (required)> <x> <y> <width> <height>
function plotit -d="Prints DVC plots on the terminal" -a target x y width height
if test -z "$target"
echo Please provide a target csv file.
return 1
end
# set `-x` or `-y` if they are provided
set x_or $x ""
set y_or $y ""
if test $x_or[1] != ""
set x_or -x $x_or
end
if test $y_or[1] != ""
set y_or -y $y_or
end
# set fallback width and height
test -z "$width"; and set width 500
test -z "$height"; and set height 500
set dvcplotdiff dvc plots diff $x_or $y_or --show-vega --targets $target
eval $dvcplotdiff | \
jq ". += {\"width\": $width, \"height\": $height}" | \
vl2vg | \
vg2svg | \
kitty +kitten icat --align left && \
dvc metrics diff
end
view raw plotit.fish hosted with ❤ by GitHub

Then refresh your shell with source ~/.config/fish/functions/plotit.fish. Finally, install jq and vega-cli, if you don't have them in your system yet.

Example usage when inside a DVC-enabled project:

  • plotit pr_curve.csv -> prints diff plot with width x height of 500px x 500px and x set to row-index and y to the second column of the csv
  • plotit pr_curve.csv recall precision -> same as above but selects the columns for x and y
  • plotit pr_curve.csv recall precision 800 800 -> with custom width and height in pixels

Enjoy!

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

Try REST API Generation for Snowflake

DevOps for Private APIs. Automate the building, securing, and documenting of internal/private REST APIs with built-in enterprise security on bare-metal, VMs, or containers.

  • Auto-generated live APIs mapped from Snowflake database schema
  • Interactive Swagger API documentation
  • Scripting engine to customize your API
  • Built-in role-based access control

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay