<jupyter_start><jupyter_text>Beginning Programming in Python Supplemental Topics: Plotting CSE20 - Spring 2021Interactive Slides: [https://tinyurl.com/cse20-spr21-plotting](https://tinyurl.com/cse20-spr21-plotting)  Plotting This material will not be on the final, however it is a helpful tool if you are working with data in any way.  The `matplotlib` package- The `matplotlib` package can be used to make a variety of different plots. For example:    - Line plots    - Bar charts    - Histograms    - and more  More information and examples can be found on the website: https://matplotlib.org/  Installation- `matplotlib` can be installed using wither `pip` or `conda`Run the cell below to install `matplotlib` and import the module we will be using<jupyter_code>!pip install matplotlib
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Example: Line Plot<jupyter_code>xs = [0, 1, 2, 3, 4]
ys = [1, 2, 1, 3, 5]

plt.figure()
plt.plot(xs, ys)
plt.show()<jupyter_output><empty_output><jupyter_text>Example: Line Plot Customizations<jupyter_code>xs = [0, 1,   2,   3,   4, 5]
ys = [1, 2.2, 1.1, 3.5, 5, 6]

plt.figure()
plt.plot(xs, ys, color="red", label="loss")
plt.plot(xs, ys[::-1], "--", color="green", label="profit")
plt.legend()
plt.show()<jupyter_output><empty_output><jupyter_text>Example: Histogram<jupyter_code>import random

data = [random.randint(0, 10) for _ in range(int(50))]

plt.figure()
plt.hist(data)
plt.xlabel("X-Values")
plt.ylabel("Counts")
plt.show()<jupyter_output><empty_output><jupyter_text>Example: Bar Chart<jupyter_code>data =       [12,  15,   8,  20,  45]
categories = ["A", "B", "C", "D", "E"]

plt.figure()
plt.bar(range(len(data)), data, color="r")
#plt.bar([1, 3, 5, 7, 9], data, color="r")
#plt.xticks(range(len(data)), categories)
plt.show()<jupyter_output><empty_output><jupyter_text>Example: Scatterplot<jupyter_code>xs = [3, 5, 4,  2, 7]
ys = [1, 8, 7, -5, 3]
zs = [0, 1, 2,  2, 4]

plt.figure()
plt.scatter(xs, ys)
#plt.scatter(xs, ys, c=zs)
#plt.colorbar()
plt.show()<jupyter_output><empty_output><jupyter_text>Example: Image<jupyter_code>data_2d = [
    [0, 13, 5],
    [4, 5,  3],
    [2, 22, 4],
]

plt.figure()
plt.imshow(data_2d)
#plt.colorbar()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16460176991150444, 'fraction_numerical': 0.03849557522123894, 'mean_word_length': 5.228650137741047, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 3, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '512846', 'license': 'MIT', 'n_tokens_mistral': 984, 'n_tokens_neox': 899, 'n_words': 226, 'path': 'CSE20_Plotting.ipynb', 'repo_name': 'ryanhausen/cse-20-spring-2021', 'size': '2260'}