2.6. Code Cells¶
2.6.1. Maximum Line Length¶
We recommend you to set the maximum line length to be 78 to avoid automatic line break in PDF. You can enable the Ruler extension in nbextensions to add visual vertical line in Jupyter when writing codes.
'-' * 78
'------------------------------------------------------------------------------'
2.6.2. Hide Source and Outputs¶
We can hide the source of a code cell by adding a comment line
# Hide code
in the cell. We can also hide the code cell outputs
using # Hide outputs
For example, here is the normal code cell:
1+2+3
6
Let’s hide the source codes
6
Also try hiding the outputs
# Hide outputs
1+2+3
2.6.3. Plotting¶
We recommend you to use the svg
format to plot a figure. For
example, the following code configures matplotlib
%matplotlib inline
import numpy as np
from IPython import display
from matplotlib import pyplot as plt
display.set_matplotlib_formats('svg')
x = np.arange(0, 10, 0.1)
plt.plot(x, np.sin(x));