# Notebook ## Mission 1 1. Research and history function In the GitLab interface (top right), a text entry field intialized with the text “Search or jump to ...” permits to search for a character string in all files of the current project. 2. How to use Markdown 1. Headers Using #, number of # represents the level of tag. 2. Emphasis *This text will be italic* _This will also be italic_ **This text will be bold** __This will also be bold__ _You **can** combine them_ 3. Bullet list Using - 4. Numbered list Using numbers like 1. 2. 5. Hypertext link e.g. [CSC](https://www.csc.edu.cn/chuguo) 6. Code ``` Less is more. ``` ## Mission 2 1. Jupyter tips and tricks 1. Creating and importing a notebook Adding a brand new notebook in a given directory 1. From the menu: File -> Open. You're now in the Jupyter file manager. 2. Navigate to the directory where you want your notebook to be created. 3. Then from the top right button: New -> Notebook: Python 3. 4. Give your notebook a name from the menu: File -> Rename. Importing an already existing notebook 1. Download the file on your computer. E.g., for this GitLab hosted notebook, click on Open raw (a small within a document icon) and save (Ctrl-S on most browsers) the content (a long JSON text file). 2. Open the Jupyter file manager from the menu File -> Open and navigate to the directory where you want to upload your notebook. 3. Then from the top right button, Upload the previously downloaded notebook and confirm the upload. 4. Open the freshly uploaded notebook through the Jupyter file manager. 2. Running R and Python on a same notebook 1. Loading rpy2: %load_ext rpy2.ipython 2. Using the %R Ipython magic: %%R summary(cars) 3. Python objects can then even be passed to R as follows (assuming df is a pandas dataframe): %%R -i df plot(df) 2. Exo 3 1. Sequence plot import matplotlib.pyplot as plt import numpy as np x = np.arange(1, 101) # x轴数据 (1-100) y = np.random.randint(1, 101, 100) # y轴数据 plt.figure(figsize=(8, 5)) plt.plot(x, y, linestyle='-', # 实线连接 color='royalblue', # 线条颜色 linewidth=2) # 线宽 plt.xlabel('X', fontsize=12) plt.ylabel('Y', fontsize=12) plt.grid(True, linestyle='--', alpha=0.7) # 添加网格线 plt.show() 2. Histogram x = np.arange(1, 9) y = np.random.randint(1, 26, 8) plt.figure(figsize=(8, 5)) bars = plt.bar(x, y, color=['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd'], width=0.6) plt.xlabel('x', fontsize=12) plt.ylabel('y', fontsize=12) plt.ylim(0, max(y)*1.1) plt.show()