<jupyter_start><jupyter_text>Basic Data Visualization using MatplotlibThe data science trio is a set of libraries which power almost all data science tasks. These libraries are as follows: - numpy - pandas - matplotlibBy now, you have already used two of them. And now, you'll get to use matplotlib. Matplotlib is the most used Python package for 2d graphics. It is simple to use and has almost all standard graphs/plots in it. This is a very big topic so we will just focus on the practical aspect of it. This will be further discussed in our data visualization module, but for now, we will just show some code snippets for doing basic visualizations for commonly used data.**Import**The first thing that we have to do is to import it.<jupyter_code>import matplotlib.pyplot as plt  # plt is the convention for the alias<jupyter_output><empty_output><jupyter_text>Let's check the styles that we could use.<jupyter_code>plt.style.available<jupyter_output><empty_output><jupyter_text>Let's use the `seaborn-darkgrid` style.<jupyter_code>plt.style.use('seaborn-darkgrid')<jupyter_output><empty_output><jupyter_text>1. Plotting 1.1 Line plotSay we want to plot a sequential data, we can plot using the following code snippet:<jupyter_code>import numpy as np

np.random.seed(42)

x = np.arange(10)
y = np.random.randint(50, 100, size=10)

plt.figure(figsize=(6, 4), dpi=100)
plt.ylabel('value')
plt.xlabel('time')
plt.title('Line Plot')

plt.plot(x, y)
plt.show()<jupyter_output><empty_output><jupyter_text>1.2 Scatter plotWe can also do a scatter plot for the data above.<jupyter_code>np.random.seed(42)

x = np.arange(10)
y = np.random.randint(50, 100, size=10)

plt.figure(figsize=(6, 4), dpi=100)
plt.ylabel('value')
plt.xlabel('time')
plt.title('Scatter Plot')

plt.scatter(x, y)
plt.show()<jupyter_output><empty_output><jupyter_text>What if we have multiple categories in our data? In the following example, there are 3 categories.<jupyter_code>from sklearn import datasets

# import some data to play with
iris = datasets.load_iris()
X = iris.data[:, :2]  # we only take the first two features.
y = iris.target

plt.figure(figsize=(6, 4), dpi=100)
plt.ylabel('sepal width')
plt.xlabel('sepal length')
plt.title('Scatter Plot')

plt.scatter(X[:,0], X[:,1], c=y, cmap=plt.cm.Set1)
plt.show()<jupyter_output><empty_output><jupyter_text>1.3 Bar graphBar graph is used for categorical data.<jupyter_code>x = ['Jude', 'Sash', 'Unisse']
y = [5, 6, 4]

plt.figure(figsize=(6, 4), dpi=100)
plt.ylabel('height')
plt.xlabel('person')
plt.title('Height')

plt.bar(x, y)
plt.show()<jupyter_output><empty_output><jupyter_text>1.4 HistogramHistograms are typically used for showing the distribution of data.<jupyter_code>dist = np.random.normal(size=100)

plt.figure(figsize=(6, 4), dpi=100)
plt.hist(dist)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12067748764996472, 'fraction_numerical': 0.02399435426958363, 'mean_word_length': 5.931540342298288, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '101139', 'license': 'MIT', 'n_tokens_mistral': 1062, 'n_tokens_neox': 987, 'n_words': 303, 'path': 'Module_0_Basic_Python_Programming/04_Visualizing_with_matplotlib.ipynb', 'repo_name': 'chechsap/foundations-of-data-science', 'size': '2834'}