summaryrefslogtreecommitdiffstats
path: root/docs/index.md
blob: 5fa76167c7862ecbecd337d258e461c970cbe152 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
---
plot-configuration: plot-config.yml
---

<!-- The file index.html is automatically generated by the mksite.ps1 script. Do not edit manually.
-->

`pandoc-plot` is a [pandoc](https://pandoc.org) filter to generate figures from code blocks in documents. This page is generated [from Markdown](index.md) using `pandoc-plot`, so you can get a sense of what is possible. 

- [Supported toolkits](#supported-toolkits)
- [Simple examples](#simple-examples)
- [Interactive plots](#interactive-plots)
- [Source repository](https://github.com/LaurentRDC/pandoc-plot)
- [Documentation](MANUAL.html)

## Supported toolkits

`pandoc-plot` currently supports the following plotting toolkits
(**installed separately**):

  - `matplotlib`: plots using the [matplotlib](https://matplotlib.org/)
    Python library;
  - `plotly_python` : plots using the
    [plotly](https://plotly.com/python/) Python library;
  - `plotly_r`: plots using the [plotly](https://plotly.com/r/) R
    library
  - `matlabplot`: plots using [MATLAB](https://www.mathworks.com/);
  - `mathplot` : plots using
    [Mathematica](https://www.wolfram.com/mathematica/);
  - `octaveplot`: plots using [GNU
    Octave](https://www.gnu.org/software/octave/);
  - `ggplot2`: plots using [ggplot2](https://ggplot2.tidyverse.org/);
  - `gnuplot`: plots using [gnuplot](http://www.gnuplot.info/);
  - `graphviz`: graphs using [Graphviz](http://graphviz.org/);
  - `bokeh`: plots using the [Bokeh](https://bokeh.org/) visualization library;
  - `plotsjl`: plots using the [Julia `Plots.jl`](http://docs.juliaplots.org/latest/) package;
  - `plantuml`: diagrams using [PlantUML](https://plantuml.com).

## Simple examples

Here's the simplest way to create a figure in Markdown:

````markdown
```{.matplotlib}
import numpy as np
import matplotlib.pyplot as plt

np.random.seed(23)

# Compute areas and colors
N = 150
r = 2 * np.random.rand(N)
theta = 2 * np.pi * np.random.rand(N)
area = 200 * r**2
colors = theta

fig = plt.figure()
ax = fig.add_subplot(111, projection='polar')
c = ax.scatter(theta, r, c=colors, s=area, cmap='hsv', alpha=0.75)
```
````

which renders like so:

```{.matplotlib}
import numpy as np
import matplotlib.pyplot as plt

np.random.seed(23)

# Compute areas and colors
N = 150
r = 2 * np.random.rand(N)
theta = 2 * np.pi * np.random.rand(N)
area = 200 * r**2
colors = theta

fig = plt.figure()
ax = fig.add_subplot(111, projection='polar')
c = ax.scatter(theta, r, c=colors, s=area, cmap='hsv', alpha=0.75)
```

## Interactive plots

`pandoc-plot` supports interactive plots for certain toolkits. Here's an example using [`bokeh`](https://bokeh.org):

````markdown
```{.python .bokeh format=html caption="Move around in the plot by using your mouse. This gallery example was modified from [here](https://docs.bokeh.org/en/latest/docs/gallery/hex_tile.html)."}
import numpy as np

from bokeh.plotting import figure
from bokeh.transform import linear_cmap
from bokeh.util.hex import hexbin

np.random.seed(23)

n = 50000
x = np.random.standard_normal(n)
y = np.random.standard_normal(n)

bins = hexbin(x, y, 0.1)

p = figure(title="Interactive plotting with Bokeh", tools="wheel_zoom,pan,reset", match_aspect=True, background_fill_color='#440154', width=550, height=550)

p.grid.visible = False

p.hex_tile(q="q", r="r", size=0.1, line_color=None, source=bins,
           fill_color=linear_cmap('counts', 'Viridis256', 0, max(bins.counts)))

```
````

```{.python .bokeh format=html caption="Move around in the plot by using your mouse. This gallery example was modified from [here](https://docs.bokeh.org/en/latest/docs/gallery/hex_tile.html)."}
import numpy as np

from bokeh.plotting import figure
from bokeh.transform import linear_cmap
from bokeh.util.hex import hexbin

np.random.seed(23)

n = 50000
x = np.random.standard_normal(n)
y = np.random.standard_normal(n)

bins = hexbin(x, y, 0.1)

p = figure(title="Interactive plotting with Bokeh", tools="wheel_zoom,pan,reset", match_aspect=True, background_fill_color='#440154', width=550, height=550)

p.grid.visible = False

p.hex_tile(q="q", r="r", size=0.1, line_color=None, source=bins,
           fill_color=linear_cmap('counts', 'Viridis256', 0, max(bins.counts)))

```