How to write nice code in articles

How to write nice code in articles#

Part of a series: Template series.

Follow reading here

Open .ipynb files in a jupyter notebook. Here, all code chunks will be executable python code and markdown chunks will also be displayed properly. Several examples can be found in this guide.

Code from other applications (like R) can be written in an ordinary code-cell, but adding the tag “remove-output”. To add tags in jupyter, click on View -> Cell Toolbar -> Tags. Here you find a list of some useful tags.

x <- rnorm(100)
hist(x, prob=TRUE)

Inlines may be shown as this code snippet: density(x).

Since the engine of jupyter notebooks is python, we can execute code JIT when the book is build and include interactive graphics! I recommend that we use this neat feature:

import plotly.io as pio
import plotly.express as px
import plotly.offline as py

df = px.data.iris()
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species", size="sepal_length")
fig