Skip to content

Commit b6805a5

Browse files
committed
add example of plotly
1 parent 1875316 commit b6805a5

File tree

6 files changed

+63
-3
lines changed

6 files changed

+63
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
result*
22
README.html
33
.direnv
4+
plots/plotlypy.html
5+
__pycache__/

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
README.html: README.md
1+
README.html: README.md plots/plotlypy.html
22
revealjs.sh $<
33

44
clean:
55
rm -f README.html
6+
7+
%.html: %.py
8+
python3 $<
9+
html-minifier --collapse-whitespace -o $@.tmp $@
10+
mv $@.tmp $@

README.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,38 @@ include a chart.js plot
241241

242242
~~~
243243
``` {.include}
244-
./plots/bar.html
244+
./plots/chartjs.html
245245
```
246246
~~~
247247

248248
::::
249249
:::: {.col}
250250

251251
``` {.include}
252-
./plots/bar.html
252+
./plots/chartjs.html
253+
```
254+
255+
::::
256+
:::
257+
258+
## example: Plotly.py
259+
260+
::: {.container}
261+
:::: {.col}
262+
263+
include a plotly.py plot
264+
265+
~~~
266+
``` {.include}
267+
./plots/plotlypy.html
268+
```
269+
~~~
270+
271+
::::
272+
:::: {.col}
273+
274+
``` {.include}
275+
./plots/plotlypy.html
253276
```
254277

255278
::::
File renamed without changes.

plots/plotlypy.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python3
2+
from pathlib import Path
3+
import plotly.graph_objects as go
4+
5+
fig = go.Figure(
6+
data = [
7+
go.Bar(x=[1,2,3,4], y=[1,3,1,4])
8+
],
9+
layout=go.Layout(
10+
title=go.layout.Title(text="A Fig by a graph_objects")
11+
),
12+
)
13+
14+
# https://stackoverflow.com/questions/29968152/setting-background-color-to-transparent-in-plotly-plots
15+
fig.update_layout(
16+
template="plotly_white",
17+
paper_bgcolor="rgba(0,0,0,0)",
18+
plot_bgcolor="rgba(0,0,0,0)",
19+
)
20+
fig.write_html(Path(__file__).with_suffix(".html"),
21+
include_plotlyjs="https://cdn.bootcdn.net/ajax/libs/plotly.js/2.25.2/plotly.min.js",
22+
full_html=False,
23+
)

shell.nix

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
let
22
pkgs = import <nixpkgs> {};
33
revealjs_sh = import ./default.nix;
4+
my_python = pkgs.python3.withPackages (p: with p; [
5+
plotly
6+
pandas
7+
packaging
8+
]);
49
in pkgs.mkShell {
510
packages = [
611
revealjs_sh
12+
my_python
13+
pkgs.html-minifier
714
];
815
}

0 commit comments

Comments
 (0)