# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Watch Me Code 1: Matplotlib
#
# We will demonstrate Pythons data visualization library Matplotlib using it two ways
#
# - Standalone
# - With Pandas
#

# +
# Jupyter Directive
# %matplotlib inline 

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

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

# ## Manual Plotting in Matplotlib

# 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
#MATLAB MATPLOTLIB
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.bar(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=36)
plt.ylabel("Value of X Squared", fontsize=36)
plt.title("Plot of X versus X Squared", fontsize=48)
plt.grid(True)
plt.show()

# ## Plotting chart types

plt.bar(x,xsquared)

plt.pie(x)

plt.scatter(x, xsquared)

# ## Plotting with Pandas

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' )

scores.corr()

## 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', fontsize=20)
p.set_ylabel('Student Score', fontsize=20)
p

# + active=""
#
# -

# 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)



StarcoderdataJupyterScriptsDedupFiltered