| 1 |
--- |
| 2 |
jupyter: |
| 3 |
kernelspec: |
| 4 |
display_name: Python 3 |
| 5 |
language: python |
| 6 |
name: python3 |
| 7 |
nbformat: 4 |
| 8 |
nbformat_minor: 2 |
| 9 |
--- |
| 10 |
|
| 11 |
::: {.cell .markdown} |
| 12 |
This notebook contains outputs of many different types: text, HTML, plots and errors. |
| 13 |
::: |
| 14 |
|
| 15 |
::: {.cell .markdown} |
| 16 |
# Text outputs |
| 17 |
|
| 18 |
Using `print`, `sys.stdout` and `sys.stderr` |
| 19 |
::: |
| 20 |
|
| 21 |
::: {#cell-1 .cell .code} |
| 22 |
``` python |
| 23 |
import sys |
| 24 |
print('using print') |
| 25 |
sys.stdout.write('using sys.stdout.write') |
| 26 |
sys.stderr.write('using sys.stderr.write') |
| 27 |
``` |
| 28 |
::: |
| 29 |
|
| 30 |
::: {#cell-2 .cell .code} |
| 31 |
``` python |
| 32 |
import logging |
| 33 |
logging.debug('Debug') |
| 34 |
logging.info('Info') |
| 35 |
logging.warning('Warning') |
| 36 |
logging.error('Error') |
| 37 |
``` |
| 38 |
::: |
| 39 |
|
| 40 |
::: {.cell .markdown} |
| 41 |
# HTML outputs |
| 42 |
|
| 43 |
Using `pandas`. Here we find two representations: both text and HTML. |
| 44 |
::: |
| 45 |
|
| 46 |
::: {#cell-3 .cell .code} |
| 47 |
``` python |
| 48 |
import pandas as pd |
| 49 |
pd.DataFrame([4]) |
| 50 |
``` |
| 51 |
::: |
| 52 |
|
| 53 |
::: {#cell-4 .cell .code} |
| 54 |
``` python |
| 55 |
from IPython.display import display |
| 56 |
display(pd.DataFrame([5])) |
| 57 |
display(pd.DataFrame([6])) |
| 58 |
``` |
| 59 |
::: |
| 60 |
|
| 61 |
::: {.cell .markdown} |
| 62 |
# Images |
| 63 |
::: |
| 64 |
|
| 65 |
::: {#cell-5 .cell .code} |
| 66 |
``` python |
| 67 |
%matplotlib inline |
| 68 |
``` |
| 69 |
::: |
| 70 |
|
| 71 |
::: {#cell-6 .cell .code} |
| 72 |
``` python |
| 73 |
# First plot |
| 74 |
from matplotlib import pyplot as plt |
| 75 |
import numpy as np |
| 76 |
w, h = 3, 3 |
| 77 |
data = np.zeros((h, w, 3), dtype=np.uint8) |
| 78 |
data[0,:] = [0,255,0] |
| 79 |
data[1,:] = [0,0,255] |
| 80 |
data[2,:] = [0,255,0] |
| 81 |
data[1:3,1:3] = [255, 0, 0] |
| 82 |
plt.imshow(data) |
| 83 |
plt.axis('off') |
| 84 |
plt.show() |
| 85 |
# Second plot |
| 86 |
data[1:3,1:3] = [255, 255, 0] |
| 87 |
plt.imshow(data) |
| 88 |
plt.axis('off') |
| 89 |
plt.show() |
| 90 |
``` |
| 91 |
::: |
| 92 |
|
| 93 |
::: {.cell .markdown} |
| 94 |
# Errors |
| 95 |
::: |
| 96 |
|
| 97 |
::: {#cell-7 .cell .code} |
| 98 |
``` python |
| 99 |
undefined_variable |
| 100 |
``` |
| 101 |
::: |