.. _sec_code: Code Cells ========== 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. .. raw:: latex \diilbookstyleinputcell .. code:: python '-' * 78 .. raw:: latex \diilbookstyleoutputcell .. parsed-literal:: :class: output '------------------------------------------------------------------------------' 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: .. raw:: latex \diilbookstyleinputcell .. code:: python 1+2+3 .. raw:: latex \diilbookstyleoutputcell .. parsed-literal:: :class: output 6 Let's hide the source codes .. raw:: latex \diilbookstyleoutputcell .. parsed-literal:: :class: output 6 Also try hiding the outputs .. raw:: latex \diilbookstyleinputcell .. code:: python # Hide outputs 1+2+3 Plotting -------- We recommend you to use the ``svg`` format to plot a figure. For example, the following code configures ``matplotlib`` .. raw:: latex \diilbookstyleinputcell .. code:: python %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)); .. figure:: output_code_e38883_9_0.svg