diff --git a/Notebook-HengkuanZhang.md b/Notebook-HengkuanZhang.md index 63ea4addf25899a0e2831183d461772c3b4f9a4b..569ac6a4240389121d4968eb1bbbbba1f62c4599 100644 --- a/Notebook-HengkuanZhang.md +++ b/Notebook-HengkuanZhang.md @@ -42,7 +42,88 @@ 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) - \ No newline at end of file + plt.show() \ No newline at end of file