Skip to content

Commit

Permalink
Plot docs
Browse files Browse the repository at this point in the history
  • Loading branch information
neelasha23 committed Dec 31, 2023
1 parent 94b781a commit c31c829
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 32 additions & 0 deletions doc/api/magic-plot.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,35 @@ You can also show the percentage on top of the pie using the `S`/`show-numbers`
```{code-cell} ipython3
%sqlplot pie --table penguins.csv --column species -S
```

## Parametrizing arguments

JupySQL supports variable expansion of arguments in the form of `{{variable}}`. This allows the user to specify arguments with placeholders that can be replaced by variables dynamically.

Currently, `table`, `column`, `schema` and `with` can be parametrized. Let's see an example:

```{code-cell} ipython3
%%sql
DROP TABLE IF EXISTS penguins;
CREATE SCHEMA IF NOT EXISTS s1;
CREATE TABLE s1.penguins (
species VARCHAR(255),
island VARCHAR(255),
bill_length_mm DECIMAL(5, 2),
bill_depth_mm DECIMAL(5, 2),
flipper_length_mm DECIMAL(5, 2),
body_mass_g INTEGER,
sex VARCHAR(255)
);
COPY s1.penguins FROM 'penguins.csv' WITH (FORMAT CSV, HEADER TRUE);
```

```{code-cell} ipython3
table = "penguins"
schema = "s1"
column = "bill_length_mm"
```

```{code-cell} ipython3
%sqlplot boxplot --table {{penguins}} --schema {{schema}} --column {{column}}
```
2 changes: 1 addition & 1 deletion src/sql/magic_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def execute(self, line="", cell="", local_ns=None):

cmd = SQLPlotCommand(self, line)

util.expand_args(cmd.args, user_ns, ["table", "column", "with_"])
util.expand_args(cmd.args, user_ns, ["table", "column", "schema", "with_"])

if len(cmd.args.column) == 1:
column = cmd.args.column[0]
Expand Down

0 comments on commit c31c829

Please sign in to comment.