<jupyter_start><jupyter_text>Watch Me Code 1: MatplotlibWe will demonstrate Pythons data visualization library Matplotlib using it two ways- Standalone- With Pandas<jupyter_code># Jupyter Directive
%matplotlib inline 

# imports
import matplotlib
import pandas as pd
import matplotlib.pyplot as plt

matplotlib.rcParams['figure.figsize'] = (20.0, 10.0) # larger figure size

str.startswith<jupyter_output><empty_output><jupyter_text>Manual Plotting in Matplotlib<jupyter_code># Matplotlib requires lists to plot
x = [1,2,3,4,5]
xsquared = [1,4,9,16,25]
plt.plot(x,xsquared) # default is a blue line
# this can be overridden. consult help(plt.plot) for details
plt.plot(x, xsquared, 'ro') # red dots
# we can manipulate the axis too, rather than auto scale. In this case we must call plt.show() to display the plot
plt.plot(x, xsquared, 'ro') # red dots
plt.axis([0,6,0,26]) # a list in the form [xmin, xmax, ymin, ymax]
plt.show()
# Labels are simple
plt.plot(x, xsquared,'r--') # red dashes
plt.axis([0,6,0,26]) # a list in the form [xmin, xmax, ymin, ymax]
plt.xlabel("Value of X", fontsize=14)
plt.ylabel("Value of X Squared", fontsize=14)
plt.title("Plot of X versus X Squared", fontsize=20)
plt.grid(True, which='both', axis='y')
plt.show()<jupyter_output><empty_output><jupyter_text>Plotting chart types<jupyter_code>plt.bar(x,xsquared)
from IPython.display import display
plt.pie(x)
print("Hi There Pie!")
display(plt.show())
plt.scatter(x, xsquared)<jupyter_output><empty_output><jupyter_text>Plotting with Pandas<jupyter_code>scores = pd.read_csv("https://raw.githubusercontent.com/mafudge/datasets/master/exam-scores/exam-scores.csv")
scores.sample(10)
# Plotting with Pandas is a bit more expressive
scores.plot.scatter(x ='Completion_Time', y ='Student_Score' )
## Labels too small, we can fall back to Matplot lib!
p = scores.plot.scatter(x ='Completion_Time', y ='Student_Score', fontsize=20)
p.set_xlabel('Completetion Time in Minutes', fontsize=20)
p.set_ylabel('Student Score out of 30', fontsize=20)
p
# Take the value counts of letter grade and create a data frame
letter_grades = pd.DataFrame( { 'Letter' : scores['Letter_Grade'].value_counts() } ).sort_index()
letter_grades.plot.bar(sort_columns=True)
letter_grades.plot.pie( y = 'Letter', fontsize = 20)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1305290546400694, 'fraction_numerical': 0.020381613183000868, 'mean_word_length': 6.3471337579617835, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 1, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '25851', 'license': 'MIT', 'n_tokens_mistral': 899, 'n_tokens_neox': 830, 'n_words': 226, 'path': 'content/lessons/13/Watch-Me-Code/WMC1-Matplotlib.ipynb', 'repo_name': 'IST256-classroom/fall2018-learn-python-mafudge', 'size': '2306'}