Skip to content

Commit b99c36e

Browse files
committed
Close #3137 with support for Plotly and examples
1 parent 7f21c2d commit b99c36e

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

_pages/about.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Many of the features of dynamic content management systems (like Wordpress) can
2020
For those users that need more advanced functionality, the template also supports the following popular tools:
2121
- [MathJax](https://www.mathjax.org/) for mathematical equations
2222
- [Mermaid](https://mermaid.js.org/) for diagraming
23+
- [Plotly](https://plotly.com/javascript/) for plotting
2324

2425
Getting started
2526
======

_pages/markdown.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,33 @@ graph TD;
9393
```
9494

9595
## Plotly
96+
Academic Pages includes support for Plotly diagrams via a hook in the Markdown code elements, although those that are comfortable with HTML and JavaScript can also access it [via those routes](https://plotly.com/javascript/getting-started/).
9697

98+
In order to render a Plotly plot via Markdown the relevant plot data need to be added as follows:
99+
100+
```markdown
101+
```plotly
102+
{
103+
"data": [
104+
{
105+
"x": [1, 2, 3, 4],
106+
"y": [10, 15, 13, 17],
107+
"type": "scatter"
108+
},
109+
{
110+
"x": [1, 2, 3, 4],
111+
"y": [16, 5, 11, 9],
112+
"type": "scatter"
113+
}
114+
]
115+
}
116+
```
117+
```
118+
119+
**Important!** Since the data is parsed as JSON *all* of the keys will need to be quoted for the plot to render. The use of a tool like [JSONLint](https://jsonlint.com/) to check syntax is highly recommended.
120+
{: .notice}
121+
122+
Which produces the following:
97123
```plotly
98124
{
99125
"data": [
@@ -111,6 +137,87 @@ graph TD;
111137
}
112138
```
113139

140+
Essentially what is taking place is that the [Plotly attributes](https://plotly.com/javascript/reference/index/) are being taken from the code block as JSON data, parsed, and passed to Plotly along with a theme that matches the current site theme (i.e., a light theme, or a dark theme). This allows all plots that can be described via the `data` attribute to rendered with some limitations for the theme of the plot.
141+
142+
```plotly
143+
{
144+
"data": [
145+
{
146+
"x": [1, 2, 3, 4, 5],
147+
"y": [1, 6, 3, 6, 1],
148+
"mode": "markers",
149+
"type": "scatter",
150+
"name": "Team A",
151+
"text": ["A-1", "A-2", "A-3", "A-4", "A-5"],
152+
"marker": { "size": 12 }
153+
},
154+
{
155+
"x": [1.5, 2.5, 3.5, 4.5, 5.5],
156+
"y": [4, 1, 7, 1, 4],
157+
"mode": "markers",
158+
"type": "scatter",
159+
"name": "Team B",
160+
"text": ["B-a", "B-b", "B-c", "B-d", "B-e"],
161+
"marker": { "size": 12 }
162+
}
163+
],
164+
"layout": {
165+
"xaxis": {
166+
"range": [ 0.75, 5.25 ]
167+
},
168+
"yaxis": {
169+
"range": [0, 8]
170+
},
171+
"title": {"text": "Data Labels Hover"}
172+
}
173+
}
174+
```
175+
176+
```plotly
177+
{
178+
"data": [{
179+
"x": [1, 2, 3],
180+
"y": [4, 5, 6],
181+
"type": "scatter"
182+
},
183+
{
184+
"x": [20, 30, 40],
185+
"y": [50, 60, 70],
186+
"xaxis": "x2",
187+
"yaxis": "y2",
188+
"type": "scatter"
189+
}],
190+
"layout": {
191+
"grid": {
192+
"rows": 1,
193+
"columns": 2,
194+
"pattern": "independent"
195+
},
196+
"title": {
197+
"text": "Simple Subplot"
198+
}
199+
}
200+
}
201+
```
202+
203+
```plotly
204+
{
205+
"data": [{
206+
"z": [[10, 10.625, 12.5, 15.625, 20],
207+
[5.625, 6.25, 8.125, 11.25, 15.625],
208+
[2.5, 3.125, 5.0, 8.125, 12.5],
209+
[0.625, 1.25, 3.125, 6.25, 10.625],
210+
[0, 0.625, 2.5, 5.625, 10]],
211+
"type": "contour"
212+
}],
213+
"layout": {
214+
"title": {
215+
"text": "Basic Contour Plot"
216+
}
217+
}
218+
}
219+
```
220+
114221
## Markdown guide
115222

116223
Academic Pages uses [kramdown](https://kramdown.gettalong.org/index.html) for Markdown rendering, which has some differences from other Markdown implementations such as GitHub's. In addition to this guide, please see the [kramdown Syntax page](https://kramdown.gettalong.org/syntax.html) for full documentation.

0 commit comments

Comments
 (0)