nextjournal GmbH May 03, 2017

Writing Research with Nextjournal

A Nextjournal article is composed of cells. This one is just a normal paragraph. Hitting enter twice, or hovering between sections, gives us the choice to add other cells like a Heading.

1. Uploading an image

Upload an image using the Image cell option. It will show up right in the article.

2. Coding in cells

Code cells can run Python, Bash or Julia live. Let's create a random normal distribution in Julia. Focus on this cell, and hit Shift-Enter.

random numbers
Julia
srand()
x0 = randn(500)
x1 = x0 + 1

Code cells run independently, but they can reference variables from other cells. Try typing a cell's name to pull up an auto-completed list of available variables.

The histograms below update automatically when you run the previous cell.

histogram
Julia
trace1 = histogram(x=x0, opacity=0.75)
trace2 = histogram(x=x1, opacity=0.75)
plot([trace1, trace2], Layout(barmode="overlay"))

This plot was created using our wrapper around amazing Plot.ly library. See documentation for Julia and Python.

3. Writing LaTeX Formula

Write formula using LaTeX either by inserting between sections, or writing inline by typing the @ sign and selecting "Formula": y\sqrt{y}

4. Reference values in paragraphs

Type the @ sign and pick "Reference" to select a value from a cell like: .

5. Using uploaded data

We've uploaded a CSV file with climate data from the OpenNEX PlanetOS project.

OpenNEX-chicago-climate.csv
Open in new window

Let's graph climate change data from the OpenNEX PlanetOS project using Python Pandas. We've uploaded a CSV file - we parse it and prepare the data for plotting. To see the Python code, uncollapse the cell using the arrow icon to the left of the graph.

opennex climate
Python
import pandas as pd

data = pd.read_csv(OpenNEX-chicago-climate.csv)
for col in ['Model', 'Scenario', 'Variable']:
   data[col] = data[col].astype('category')
data['Date'] = data['Date'].astype('datetime64')
data['Temperature'] = data['Value'] - 273.15	

model = data.loc[1, 'Model']
title = "Maximum mean temperature for warmest month using model %s" % (model)

data['Year'] = data['Date'].map(lambda d: "%d-01-01" % (d.year)).astype('datetime64')
by_year = data.groupby(['Year', 'Scenario']).max().loc[:,['Temperature']]
groups = by_year.reset_index().set_index('Year').groupby('Scenario')

plot_data = [{'x': grp.index, 'y': grp['Temperature'], 'name': key} for key, grp in groups]
layout = { 'title': title,'xaxis': {'title': 'Year', 'type': 'lin'}, 'yaxis': {'title': 'Temperature [Celsius]'}}

plot({'data': plot_data, 'layout': layout})

We're excited to see what you publish with Nextjournal!