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

# + [markdown] id="0EJs-99LXGaR"
# # Overview
# ## Data visualization

# + [markdown] id="VuzIPUAv3eHK"
# ## Visualizing Data
#  - A fundamental part of the data scientist’s toolkit is data visualization. Although it is very
# easy to create visualizations, it’s much harder to produce good ones.
#  - There are two primary uses for data visualization:
#  
# To explore data / Communicate data
#
#

# + [markdown] id="kUzTRwUf4cHb"
# ## Matplotlib
# A wide variety of tools exists for visualizing data. We will be beginning with the matplotlib library, which is widely used for simple vizualisations like bar charts, line charts, and scatterplots.
# In particular, we will be using the matplotlib.pyplot module. Pyplot
# maintains an internal state in which you build up a visualization step by step.
#

# + [markdown] id="Oy2MAncj6iba"
# ## Line Charts
#
# A line plot is generally used to present observations collected at regular intervals.
#
# > To chart time series data
#
#
#

# + colab={"base_uri": "https://localhost:8080/", "height": 265} id="o6PSX4U8LsW7" outputId="ed017fc7-6e15-429d-ff04-979f9309c95c"
import matplotlib.pyplot as plt

years = [1950, 1960, 1970, 1980, 1990, 2000, 2010]
gdp = [300.2, 543.3, 1075.9, 3862.5, 5979.6, 10286.7, 15958.3] 

plt.plot(years, gdp) 

plt.show()

# + id="RhLm9ZNc3YEV" colab={"base_uri": "https://localhost:8080/", "height": 295} outputId="e728bf9d-60b4-437e-8b0a-058cadd6f814"
from matplotlib import pyplot as plt
years = [1950, 1960, 1970, 1980, 1990, 2000, 2010]
gdp = [300.2, 543.3, 1075.9, 3862.5, 5979.6, 10289.7, 15958.3] ## Change the values and check the change
# create a line chart, years on x-axis, gdp on y-axis
plt.plot(years, gdp, color='red', 
         marker='o', 
         linestyle='dashed')    ## Possible other linestyles: ('solid', 'dotted',dashed','dashdot')
# add a title
plt.title("Nominal GDP")
# add a label to the y-axis
plt.ylabel("Millions $")
plt.xlabel('Years')
plt.show()

# + [markdown] id="dm1EknhA7Gek"
# ## Bar Charts
# A bar chart is a good choice when you want to show how some quantity varies among some discrete set of items.
#
# > Categorical quantities.

# + colab={"base_uri": "https://localhost:8080/"} id="HQ1vypepQX64" outputId="82e5cddd-b85d-479b-a1bb-a1f5ffdf52f9"
listA = []

for i in range(1,12):
  listA.append(i)
print(listA)

# + id="Nl9jtpJJ52k1" colab={"base_uri": "https://localhost:8080/", "height": 295} outputId="77a869c3-5472-42e8-f6ae-078faf92b547"
movies = ["<NAME>", "Ben-Hur", "Casablanca", "Gandhi", "West Side Story"]
num_oscars = [5, 11, 3, 8, 10]

plt.bar(movies, num_oscars,width=0.4)  ## try different values
plt.title("Favorite Movies Oscars")
plt.ylabel("# of Oscar Awards")

plt.yticks(listA)

plt.xlabel('Movies names')
plt.show()

# + colab={"base_uri": "https://localhost:8080/"} id="fdvM-k9ZTY3J" outputId="21c8b586-8861-4c97-db80-4687af6cce92"
listA = []

for i in range(495,506):
  listA.append(i)
listA

# + id="PP5R2OQl7QXW" colab={"base_uri": "https://localhost:8080/", "height": 295} outputId="76de5bf7-cc5d-48d3-f3b2-31578d084a91"
mentions = [500, 515]
years = [2013, 2014]
plt.bar(years, mentions,width=0.3)

plt.xticks(years)
plt.ylabel("# of times I heard someone say 'data science'")
plt.xlabel('Year')

plt.axis([2012.5,2014.5,450,520])

plt.title("Stydying the increament")
plt.show()

# + [markdown] id="gM9xOJO79pKT"
# ## Line Charts

# + id="X0tjpvOh9IC1" colab={"base_uri": "https://localhost:8080/", "height": 295} outputId="dd81506f-e292-41bd-a3fa-0504b4723ee7"
variance = [1, 2, 4, 8, 16, 32, 64, 128, 256]
bias_squared = [256, 128, 64, 32, 16, 8, 4, 2, 1]
total_error = [x + y for x, y in zip(variance, bias_squared)]
xs = [0,1,2,3,4,5,6,7,8]

plt.plot(xs, variance, 'g-')       # green solid line
plt.plot(xs, bias_squared, 'r-.')   # red dot-dashed line
plt.plot(xs, total_error, 'b:') # blue dotted line

plt.xlabel("model complexity")
plt.title("The Bias-Variance Tradeoff")
plt.show()

# + [markdown] id="sY3w0SnJ906p"
# ## Scatterplots
#
# > A scatterplot is the right choice for visualizing the relationship between two paired sets of
# data (or more).

# + colab={"base_uri": "https://localhost:8080/", "height": 295} id="slDiw16BhMFg" outputId="cc453fc9-32dd-4c3f-d808-b83fdaa634f0"
test_1_grades = [ 99, 90, 85, 97, 80,78]
test_2_grades = [100, 85, 60, 90, 70,83]
plt.scatter(test_1_grades, test_2_grades)
plt.title("Axes of tests grades")
plt.xlabel("test 1 grade")
plt.ylabel("test 2 grade")
plt.show()

# + id="P739hRb49r9D" colab={"base_uri": "https://localhost:8080/", "height": 295} outputId="a37b0afd-cafd-41a7-9590-7aac6e36e035"
friends = [ 70, 65, 72, 63, 71, 64, 60, 64, 67]
minutes = [175, 170, 205, 120, 220, 130, 105, 145, 190]
labels = ['i', 'i', 'i', 'i', 'e', 'e', 'e', 'e', 'e']
plt.scatter(friends, minutes)
# label each point
for label, friend_count, minute_count in zip(labels, friends, minutes):
  plt.annotate(label,
  xy=(friend_count, minute_count), # put the label with its point
  xytext=(6, -5), # but slightly offset
  textcoords='offset points')
plt.title("Daily Minutes vs. Number of Friends")
plt.xlabel("# of friends")
plt.ylabel("daily minutes spent on the site")
plt.show()

# + [markdown] id="cAbbNPWv-VmF"
# ##For Further Exploration
# Seaborn is built on top of matplotlib and allows you to easily produce prettier (and more complex) visualizations.
#
# D3.js is a JavaScript library for producing sophisticated interactive visualizations for
# the web. Although it is not in Python, it is both trendy and widely used, and it is well
# worth your while to be familiar with it.
#
# Bokeh is a newer library that brings D3-style visualizations into Python.
#
# ggplot is a Python port of the popular R library ggplot2, which is widely used for creating “publication quality” charts and graphics. It’s probably most interesting if you’re already an avid ggplot2 user, and possibly a little opaque if you’re not.

# + [markdown] id="vp_fAJZb-9dp"
# Reference: 
#   
# > Website : GeekforGeeks.com
#   
# > link: https://machinelearningmastery.com/data-visualization-methods-in-python/
#            
#

StarcoderdataJupyterScriptsDedupFiltered