<jupyter_start><jupyter_text>Line PlotA line plot plots a number of different series of data points, and connect each series in a point with a line.<jupyter_code>%matplotlib --list

%matplotlib inline

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt

data_linear = np.array([1,2,3,4,5,6,7])
data_quadratic = data_linear ** 2 #broadcasting

plt.figure()
plt.plot(data_linear, 'o', data_quadratic, 'o')
plt.xlabel('some data')
plt.ylabel('some other data')
plt.legend(['yes','no'])
plt.title('A title')

plt.gca().fill_between(range(len(data_linear)), data_linear, data_quadratic, facecolor='blue', alpha=0.25)
# Great for plotting errors
plt.figure()
observation_date = np.arange('2019-01-01', '2019-01-08', dtype='datetime64[D]')
x = plt.gca().xaxis
for item in x.get_ticklabels():
  item.set_rotation(45)
dir(x)
plt.plot(observation_date, data_quadratic, 'go-')
ax = plt.gca()
ax.set_xlabel('Date')
ax.set_ylabel('Cars')
ax.set_title('Cars per day')
# plt.subplots_adjust(bottom=0.25)<jupyter_output><empty_output><jupyter_text>Bar chart<jupyter_code>plt.figure()
data_x = range(len(data_linear))
plt.bar(data_x, data_linear, width=0.3)
plt.figure()
data_x = range(len(data_linear))
plt.bar(data_x, data_linear, width=0.3)

red_data_x = [x+0.3 for x in data_x]
plt.bar(red_data_x, data_quadratic, width=0.3, color='r')
# Stacked bar chart
plt.figure()
data_x = range(len(data_linear))
plt.bar(data_x, data_linear, width=0.3, color='#C13584')
plt.bar(data_x, data_quadratic, width=0.3, bottom=data_linear, color='#FFDC80')
# Color is from instagram brand https://brandpalettes.com/instagram-color-codes/
# Horizontal bar chart
plt.figure()
data_x = range(len(data_linear))
plt.barh(data_x, data_linear, height=0.3, color='#F77737')
plt.barh(data_x, data_quadratic, height=0.3, left=data_linear, color='#4285F4')<jupyter_output><empty_output><jupyter_text>In class challenge<jupyter_code>import matplotlib.pyplot as plt
import numpy as np

plt.figure()

languages =['Python', 'SQL', 'Java', 'C++', 'JavaScript']
pos = np.arange(len(languages))
popularity = [56, 39, 34, 34, 29]

plt.bar(pos, popularity, align='center')
plt.xticks(pos, languages)
plt.ylabel('% Popularity')
plt.title('Top 5 Languages for Math & Data \nby % popularity on Stack Overflow', alpha=0.8)

#TODO: remove all the ticks (both axes), and tick labels on the Y axis

plt.show()
import matplotlib.pyplot as plt
import numpy as np

plt.figure()

languages =['Python', 'SQL', 'Java', 'C++', 'JavaScript']
pos = np.arange(len(languages))
popularity = [56, 39, 34, 34, 29]

plt.bar(pos, popularity, align='center')
plt.xticks(pos, languages)
plt.ylabel('% Popularity')
plt.title('Top 5 Languages for Math & Data \nby % popularity on Stack Overflow', alpha=0.8)

# remove all the ticks (both axes), and remove tick labels on the Y axis
plt.tick_params(top=False, bottom=False, left=False, right=False, labelleft=False, labelbottom=True)

# TODO: remove the frame of the chart


plt.show()
import matplotlib.pyplot as plt
import numpy as np

plt.figure()

languages =['Python', 'SQL', 'Java', 'C++', 'JavaScript']
pos = np.arange(len(languages))
popularity = [56, 39, 34, 34, 29]
# TODO: change the bar colors to be less bright blue
# TODO: make one bar, the python bar, a contrasting color
plt.bar(pos, popularity, align='center')

# TODO: soften all labels by turning grey
plt.xticks(pos, languages)
plt.ylabel('% Popularity')
plt.title('Top 5 Languages for Math & Data \nby % popularity on Stack Overflow')

# remove all the ticks (both axes), and tick labels on the Y axis
plt.tick_params(top=False, bottom=False, left=False, right=False, labelleft=False, labelbottom=True)

# remove the frame of the chart
for spine in plt.gca().spines.values():
    spine.set_visible(False)
plt.show()
import matplotlib.pyplot as plt
import numpy as np

plt.figure()

languages =['Python', 'SQL', 'Java', 'C++', 'JavaScript']
pos = np.arange(len(languages))
popularity = [56, 39, 34, 34, 29]

# change the bar colors to be less bright blue
bars = plt.bar(pos, popularity, align='center', linewidth=0, color='lightslategrey')
# make one bar, the python bar, a contrasting color
bars[0].set_color('#1F77B4')

# soften all labels by turning grey
plt.xticks(pos, languages, alpha=0.8)
plt.ylabel('% Popularity', alpha=0.8)
plt.title('Top 5 Languages for Math & Data \nby % popularity on Stack Overflow', alpha=0.8)

# remove all the ticks (both axes), and tick labels on the Y axis
plt.tick_params(top=False, bottom=False, left=False, right=False, labelleft=False, labelbottom=True)

# remove the frame of the chart
for spine in plt.gca().spines.values():
    spine.set_visible(False)
plt.show()
import matplotlib.pyplot as plt
import numpy as np

plt.figure()

languages =['Python', 'SQL', 'Java', 'C++', 'JavaScript']
pos = np.arange(len(languages))
popularity = [56, 39, 34, 34, 29]

# change the bar color to be less bright blue
bars = plt.bar(pos, popularity, align='center', linewidth=0, color='lightslategrey')
# make one bar, the python bar, a contrasting color
bars[0].set_color('#1F77B4')

# soften all labels by turning grey
plt.xticks(pos, languages, alpha=0.8)
# remove the Y label since bars are directly labeled
#plt.ylabel('% Popularity', alpha=0.8)
plt.title('Top 5 Languages for Math & Data \nby % popularity on Stack Overflow', alpha=0.8)

# remove all the ticks (both axes), and tick labels on the Y axis
plt.tick_params(top=False, bottom=False, left=False, right=False, labelleft=False, labelbottom=True)

# remove the frame of the chart
for spine in plt.gca().spines.values():
    spine.set_visible(False)
    
# direct label each bar with Y axis values
for bar in bars:
    plt.gca().text(bar.get_x() + bar.get_width()/2, bar.get_height() - 5, str(int(bar.get_height())) + '%', 
                 ha='center', color='w', fontsize=11)
plt.show()<jupyter_output><empty_output><jupyter_text>HistogramBar chart with y axis representing frequency.   Box plots  Heat maps  Pandas Visualization<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

%matplotlib notebook
# pandas styles
plt.style.available
plt.style.use('seaborn-colorblind')
mpl.get_backend()
np.random.seed(123)

df = pd.DataFrame({'A': np.random.randn(365).cumsum(0), 
                   'B': np.random.randn(365).cumsum(0) + 20,
                   'C': np.random.randn(365).cumsum(0) - 20}, 
                  index=pd.date_range('1/1/2017', periods=365))
df.head()
%matplotlib inline

df.plot()<jupyter_output><empty_output><jupyter_text><jupyter_code>import matplotlib.pyplot as plt
import numpy as np


# generate 4 random variables from the random, gamma, exponential, and uniform distributions
x1 = np.random.normal(-2.5, 1, 10000)
x2 = np.random.gamma(2, 1.5, 10000)
x3 = np.random.exponential(2, 10000)+7
x4 = np.random.uniform(14,20, 10000)

# plot the histograms
plt.figure(figsize=(9,3))
plt.hist(x1, normed=True, bins=20, alpha=0.5)
plt.hist(x2, normed=True, bins=20, alpha=0.5)
plt.hist(x3, normed=True, bins=20, alpha=0.5)
plt.hist(x4, normed=True, bins=20, alpha=0.5);
plt.axis([-7,21,0,0.6])

plt.text(x1.mean()-1.5, 0.5, 'x1\nNormal')
plt.text(x2.mean()-1.5, 0.5, 'x2\nGamma')
plt.text(x3.mean()-1.5, 0.5, 'x3\nExponential')
plt.text(x4.mean()-1.5, 0.5, 'x4\nUniform')<jupyter_output><empty_output><jupyter_text>New York Taxi Data PlotDownload weather data from here: https://www.kaggle.com/jsphyg/weather-dataset-rattle-package/downloads/weather-dataset-rattle-package.zip/2<jupyter_code>https://www.kaggle.com/jsphyg/weather-dataset-rattle-package/downloads/weather-dataset-rattle-package.zip/2
%%bigquery --project a data

SELECT * FROM `bigquery-public-data.new_york_taxi_trips.tlc_yellow_trips_2018` LIMIT 1000
https://www.kaggle.com/jsphyg/weather-dataset-rattle-package/downloads/weather-dataset-rattle-package.zip/2<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup