Output Graphs and Uploaded Images/Data
1. Generated Data
Graphical output is stored as a file in the
from numpy import * from matplotlib import pyplot as plt def mandelbrot( h,w, maxit=40): y,x = ogrid[ -1.4:1.4:h*1j, -2:0.8:w*1j ] c = x+y*1j z = c divtime = maxit + zeros(z.shape, dtype=int) for i in range(maxit): z = z**2 + c diverge = z*conj(z) > 2**2 div_now = diverge & (divtime==maxit) divtime[div_now] = i + 100 z[diverge] = 2 return divtime fig = plt.subplots(1,figsize=(20,20)) plt.imshow(mandelbrot(1000,1000)) plt.axis('off') plt.savefig("/results/mandelbrot.png")
To get data out of Nextjournal, files can be written or copied to the
/results directory. Image files will be displayed in the article (right-click to download), while all other files will appear with a download link.
We can also access files that were previously placed in
/results, from other cells or even the same cell if recursion is needed.
These are stored in the same database as uploaded files, but to reference these we start by typing the name of the cell that created the file, then again find the file in the autocomplete list.
2. Uploaded Data
cp Image↩ /results/overbeck.jpg
Files downloaded from within cells can be preserved in either of two ways. The preferred method is to download the file directly into
/results, thus ensuring the file will be saved and versioned for reference elsewhere in the article.
import urllib urllib.request.urlretrieve("https://nextjournal.com/images/logo.svg", "/results/logo.svg")
They can even be referenced in other runtimes and languages.
cp Image↩ /logo.svg
3. Content Addressed Store
mkdir -p results/temp-dir cp Image↩ results/temp-dir ls results/temp-dir
ls -alF results/temp-dir
Why is there no file in
Every file you write to
/results will be moved to our permanent and content addressed storage after the execution of the cell. It is then available as cell result and it can be used as reference in any other cell by using copy/paste. Behind the scenes it is actually moved to a `/data/<content-hash>` file and permanently stored on a google cloud storage nas device. If you paste the reference in any other cell and access it, it automatically resolves to that file.