<jupyter_start><jupyter_text>Data Visualization with Python using Matplotlib -- Exercises OverviewHi Guys,Welcome to the matplotlib exercises lecture. Please follow the instructions while solving the exercises. These are relatively easy tasks, if you are new to matplotlib, the tasks may be tricky. You can always reference to the solutions if you find things complicated. &9989; Please note, the commands for plotting figures should go all together in the same cell. Splitting them in multiple cells may not show the results. Let's have a quick overview on the tasks. In the first cell, we are simply creating data x and y to use in the provided tasks.<jupyter_code># We need data to work with, lets create data first!
import numpy as np
x = np.arange(0,10)
y = x*2
z = x**2<jupyter_output><empty_output><jupyter_text>&9758; If you are a jupyter users:* Let's import **matplotlib.pyplot as plt** and set **%matplotlib inline**.If you are not using jupyter notebook, you will use **plt.show()**<jupyter_code>import matplotlib.pyplot as plt
%matplotlib inline
# plt.show() for non-notebook users<jupyter_output><empty_output><jupyter_text>**1. Instructions: *** ** Use plt.figure() and create a figure object, say fig.*** ** Add an axis to the figure canvas (`fig`), `[left, bottom, width, height] is [0,0,1,1]`. Hint: add_axes()*** ** Plot the data x,y on the axes*** ** Set the labels x and y*** ** Set the title*** ** Create legends as shown in the plot**Match the output below:<jupyter_code># code here please
fig = plt.figure()
axes = fig.add_axes([0, 0, 1, 1])
axes.plot(x, y, 'g', label='y=x*2')
axes.legend(loc=4)
axes.set_xlabel('x_label')
axes.set_ylabel('y_label')
axes.set_title('Plot_title')<jupyter_output><empty_output><jupyter_text>**2. Instructions*** ** Create a figure object*** ** Put two axes on the figure at [0,0,1,1] and [0.1,0.6,0.2,0.2]*** ** Plot data (x,z) on main axes*** ** Plot data (x,z) on the small axes and set its x limit b/w 1, 2, y limit 0, 5*** ** Replicate the figure to axes, titles, legends etc**<jupyter_code># code here please
fig = plt.figure()
axes_m = fig.add_axes([0, 0, 1, 1])
axes_m.plot(x, z, 'r', label='y_main=x_main**2')
axes_m.legend(loc=4)
axes_m.set_xlabel('x_label')
axes_m.set_ylabel('y_label')
axes_m.set_title('Title_Main')

axes_i = fig.add_axes([0.1, 0.6, 0.2, 0.2])
axes_i.plot(x, z, 'b')
axes_i.set_xlim([1, 2])
axes_i.set_ylim([0, 5])
axes_i.set_xlabel('x_inset')
axes_i.set_ylabel('y_inset')
axes_i.set_title('Inset')

fig.show()<jupyter_output><empty_output><jupyter_text>**3. Replicate the output using subplots() and for loop** -- Note, the data is x and y.<jupyter_code># code here please
fig, axes = plt.subplots(nrows=1, ncols=3)
for ax in axes:
    ax.plot(x, y)
fig.tight_layout()<jupyter_output><empty_output><jupyter_text>**4. Replicate the output using subplots()**<jupyter_code># code here please
fig, axes = plt.subplots(nrows=3)<jupyter_output><empty_output><jupyter_text>**5. plot `(x,y)`, `(x,z)` and `(x,y)` on the above empty canvas to replicate the plot given below.**<jupyter_code># code here please
fig, axes = plt.subplots(nrows=3)
axes[0].plot(x, y, 'b--', lw=3)
axes[1].plot(x, z, 'r', lw=3)
axes[2].plot(x, y, 'g', lw=3)

fig.tight_layout()<jupyter_output><empty_output><jupyter_text>**6. Resize the above plots to `figsize = (3,4)`**<jupyter_code># code here please
plt.figsize=(3, 4)<jupyter_output><empty_output><jupyter_text>**7. Replicate the plot given below:***hint: scatter plot*<jupyter_code># code here please
plt.scatter(x, z, marker='s')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15210084033613444, 'fraction_numerical': 0.021848739495798318, 'mean_word_length': 5.90715667311412, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '486768', 'license': 'MIT', 'n_tokens_mistral': 1405, 'n_tokens_neox': 1328, 'n_words': 408, 'path': 'class_03_10/2_1_matplotlib_Exercises.ipynb', 'repo_name': 'tnordal/DataScienceMLBootcamp', 'size': '3570'}