Try out Nextjournal and share this article!

Writing Reproducible Research
Insert

Go ahead and edit this article! Hover between sections to add a new paragraph, heading, code cell, image or data file.

Insert

1.
Coding in cells
Insert

We start by installing PlotlyJS.jl.

Insert
Done
install
local
Julia
Pkg.add("PlotlyJS")
using PlotlyJS
nothingnothing
Map
(1){
:value
nil
}
Insert

Code cells support Python, Bash or Julia. Let's create a random normal distribution of numbers in Julia and plot it. Click the number of the left and change its value, then press Cmd-Enter to re-run all affected cells.

Insert
Done
random numbers
install
Julia
x0 = randn() 
x1 = x0 + 1
[-0.3128133053038685, 0.2105133435744301, -1.0527040238890897, -0.40788585265516575, -1.9381620944793125, -0.31577996494293914, 0.12523734489598737, 1.3733674581298005, -1.480352723374835, -0.805952733735184][0.6871866946961315, 1.2105133435744302, -0.05270402388908968, 0.5921141473448343, -0.9381620944793125, 0.6842200350570609, 1.1252373448959874, 2.3733674581298008, -0.48035272337483503, 0.19404726626481605]
Insert

Code cells run in isolation by default. But they can run in the scope of another cell. The following cell runs in the scope of the previous. The following cell runs in the scope of the previous.

Insert
Done
plot
random numbers
Julia
trace1 = histogram(x=x0, opacity=0.75)
trace2 = histogram(x=x1, opacity=0.75)
Plot([trace1, trace2], Layout(barmode="overlay"))  
{"opacity":0.75,"type":"histog...{"opacity":0.75,"type":"histog...{"layout":{"barmode":"overlay"...
Insert

2.
Using uploaded data
Insert

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.

Insert
OpenNEX-chicago-climate.csv
Open in new window
Insert
Done
opennex climate
local
Python
import pandas as pd 
 
data = pd.read_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})
{'data': [{'x': DatetimeIndex(...
Insert

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

Insert