Skip to content

Commit 37ccb2e

Browse files
authored
Add interactive plotly example to distill post (alshedivat#1027)
1 parent b9f1fc8 commit 37ccb2e

File tree

2 files changed

+105
-1
lines changed

2 files changed

+105
-1
lines changed

_posts/2018-12-22-distill.md

+34-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ toc:
3636
- name: Citations
3737
- name: Footnotes
3838
- name: Code Blocks
39+
- name: Interactive Plots
3940
- name: Layouts
4041
- name: Other Typography?
4142

@@ -74,7 +75,6 @@ $$
7475

7576
Note that MathJax 3 is [a major re-write of MathJax](https://docs.mathjax.org/en/latest/upgrading/whats-new-3.0.html) that brought a significant improvement to the loading and rendering speed, which is now [on par with KaTeX](http://www.intmath.com/cg5/katex-mathjax-comparison.php).
7677

77-
7878
***
7979

8080
## Citations
@@ -123,6 +123,39 @@ function(x) {
123123

124124
***
125125

126+
## Interactive Plots
127+
128+
You can add interative plots using plotly + iframes :framed_picture:
129+
130+
<div class="l-page">
131+
<iframe src="{{ '/assets/plotly/demo.html' | relative_url }}" frameborder='0' scrolling='no' height="500px" width="100%" style="border: 1px dashed grey;"></iframe>
132+
</div>
133+
134+
The plot must be generated separately and saved into an HTML file.
135+
To generate the plot that you see above, you can use the following code snippet:
136+
137+
{% highlight python %}
138+
import pandas as pd
139+
import plotly.express as px
140+
df = pd.read_csv(
141+
'https://raw.githubusercontent.com/plotly/datasets/master/earthquakes-23k.csv'
142+
)
143+
fig = px.density_mapbox(
144+
df,
145+
lat='Latitude',
146+
lon='Longitude',
147+
z='Magnitude',
148+
radius=10,
149+
center=dict(lat=0, lon=180),
150+
zoom=0,
151+
mapbox_style="stamen-terrain",
152+
)
153+
fig.show()
154+
fig.write_html('assets/plotly/demo.html')
155+
{% endhighlight %}
156+
157+
***
158+
126159
## Layouts
127160

128161
The main text column is referred to as the body.

assets/plotly/demo.html

+71
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)