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