<jupyter_start><jupyter_text>HISTOGRAM<jupyter_code>#Bar plots have cateogrical variables while histogram has quantitative variables

population_ages = [22,34,45,78,23,65,47,98,70,56,54,87,23,54,31,35,
                   64,76,87,80,60,73,47,63,79,52,75,64,51,46,83,62,36,74,63]

from numpy.random import seed
from numpy.random import randint

seed(1)
#generate some random integers
population_ages_2 = randint(10,50,40)
#print(population_ages_2)
    

bins = [20,30,40,50,60,70,80,90,100]

plt.hist(population_ages, bins, histtype='bar', color = 'm', rwidth = 0.5)
plt.hist(population_ages_2, bins, histtype='bar', color = 'c', rwidth = 0.5)

plt.xlabel('X asis')
plt.ylabel('Y axis')

plt.title('Histogram')
plt.legend()
plt.show()<jupyter_output>No handles with labels found to put in legend.<jupyter_text>AREA PLOT AND STACK PLOT<jupyter_code>days = randint(1,5,5) 

seed(0)

sleeping = randint(10,30,5)
eating = randint(40,60,5)
working = randint(70,100,5)
playing = randint(100,150,5)

plt.plot([],[], color = 'm', label = 'sleeping', linewidth = 5)
plt.plot([],[], color = 'c', label = 'eating', linewidth = 5)
plt.plot([],[], color = 'r', label = 'working', linewidth = 5)
plt.plot([],[], color = 'k', label = 'playing', linewidth = 5)

plt.stackplot(days, sleeping, eating, working, playing, colors = ['m','c','r','k'])
plt.legend()<jupyter_output><empty_output><jupyter_text>PIE CHART<jupyter_code>seed(0)
slices = randint(20,100,5)

activities = ['balling','playing','sleeping','praying','eating']

cols = ['c','m','r','b','y']

plt.pie(slices,
       labels = activities,
       startangle = 90,
       shadow = True,
       colors = cols,
       autopct = '%.1f%%', #formats the percentage of the data given
       explode=(0,0.2,0,0,0.1)) #this is to explode the chart and takes positional argument

plt.title('Pie Chart')
plt.show()
#working with Multiple Plots

def f(t):
    return np.exp(-t) * np.cos(2*np.pi*t)

t1 = np.arange(0.0,5.0,0.1)
t2 = np.arange(0.0,6.0,0.4)

plt.subplot(211)
plt.plot(t1, f(t1),'bo',
        t2, f(t2))

plt.subplot(212)
plt.plot(t1, np.cos(2*np.pi*t1), color = 'k')

plt.show()<jupyter_output><empty_output><jupyter_text>FURTHER PLOTTING IN MATPLOTLIB/PYLAB<jupyter_code>from matplotlib import pylab
pylab.__version__
import numpy as np
x = np.linspace(0,10,25)
y  = x*x+2
print()
print(x)
print()
print(y)
#print(np.array([x,y]).reshape(25,2)) # to join the array together
pylab.plot(x,y, 'r') #'r' stands for red
#drawing a subgraph
pylab.subplot(1,2,1) #rows, columns and indexes
pylab.plot(x,y, 'b--') 

pylab.subplot(1,2,2)
pylab.plot(y,x, 'g*-')
import matplotlib.pyplot as plt
from matplotlib import style
style.use('ggplot')

fig = plt.figure()

ax = fig.add_axes([0.5,0.1,0.8,0.8]) #this controls the left,bottom,width and height of the canvas

ax.plot(x,y, 'r')
#we can also draw subgraphs

fig, ax = plt.subplots(nrows=1, ncols=2)
for ax in ax:
    ax.plot(x,y, 'r')
#we can drw a picture or a graph inside of another graph
fig = plt.figure()
ax1 = fig.add_axes([0.5,0.1,0.8,0.8]) #Big axes
ax2 = fig.add_axes([0.6,0.5,0.35,0.3]) #small canvas

ax1.plot(x,y,'r')
ax2.plot(y,x, 'g')

fig, ax = plt.subplots(dpi=100)
ax.set_xlabel('X-axis')
ax.set_ylabel('Y-axis')
ax.set_title('tutorial plots')

#ax.plot(x,y, 'r')

ax.plot(x,x**2)
ax.plot(x, x**3)


#ax.legend(['label 1', 'label 2'])
ax.legend(['y = x**2', 'y = x**3'], loc=2) #plotting the legend
#you can also set other properties such as line color, transparency and more

fig, ax = plt.subplots(dpi=100)
ax.plot(x, x**2, 'r', alpha=0.5) #alpha sets the line colour transparency
ax.plot(x, x+2, alpha=.5)
ax.plot(x, x+3, alpha=.5)
fig, ax = plt.subplots(dpi=100)
#line width
ax.plot(x, x+1, 'b', lw=0.5 ) 
ax.plot(x, x+2, 'b', lw=1.5)
ax.plot(x, x+3, 'b', lw=3)
ax.plot(x, x+4, 'b', lw=3.5)
fig, ax = plt.subplots(dpi=100)
ax.plot(x, x+1, 'b', lw=0.5, linestyle='-') 
ax.plot(x, x+2, 'b', lw=1.5, linestyle='-.')
ax.plot(x, x+3, 'b', lw=3, linestyle=':')
ax.plot(x, x+4, 'b', lw=3.5, linestyle='-')
fig, ax = plt.subplots(dpi=100)
ax.plot(x, x+1, 'b', lw=0.5 , marker='o', markersize=5, markerfacecolor='r') 
ax.plot(x, x+2, 'b', lw=1.5, marker='+')
ax.plot(x, x+3, 'b', lw=3, marker='s')
ax.plot(x, x+4, 'b', lw=3.5, marker='1', markersize=10)<jupyter_output><empty_output><jupyter_text>LIMITING OUR DATA<jupyter_code>fig, ax = plt.subplots(1,2, figsize=(10,5))
ax[0].plot(x,x**2, x,x**3, lw=3)
#ax[0].grid(True) this applies if we are not using ggplot
ax[1].plot(x,x**2, x,x**3, lw=3)

#we set the x and y limit on the second plot
ax[1].set_ylim([0,60])
ax[1].set_xlim([2,5])<jupyter_output><empty_output><jupyter_text>Other 2_d Graphs<jupyter_code>n = np.array([0,1,2,3,4,5])

fig, ax = plt.subplots(1,4, figsize=(16,5)) 
ax[0].set_title('scatter')
ax[0].scatter(x, x + 0.25*np.random.randn(len(x)))

ax[1].set_title('step plot')
ax[1].step(n, n**2, lw=2, color='b')

ax[2].set_title('Bar')
ax[2].bar(n, n**2, align='center', color ='g', alpha=0.5)

ax[3].set_title('fill between')
ax[3].fill_between(x, x**2, x**3, color ='g', alpha=0.5)

plt.show()
#Draw a Histogram '''Very important''

x = np.random.randn(10000)
fig, ax = plt.subplots(1,2, figsize=(12,4))
ax[0].set_title('Histogram')
ax[0].hist(x, color='g', alpha=0.8)

ax[1].set_title('Cumulative detailed histogram')
ax[1].hist(x, cumulative=True, bins=9)

plt.show()
#draw a contour map

#lets create some data where X and Y are coordinates and Z is the depth or height

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

delta = 0.0075
x = np.arange(-3, 3, delta)
y = np.arange(-2, 2, delta)

X, Y = np.meshgrid(x,y)
Z1 = np.exp(-X**2 - Y**2)
Z2 = np.exp(-(-X - 1)**2 - (Y - 1)**2)
Z = (Z1 - Z2)*2
fig, ax = plt.subplots(dpi=100)
CS = ax.contour(X,Y,Z) #CS is contour surface
ax.clabel(CS, inline=1, fontsize=10)
ax.set_title('Contour Map')<jupyter_output><empty_output><jupyter_text>3 D MAPS<jupyter_code>from mpl_toolkits.mplot3d.axes3d import Axes3D

fig = plt.figure(figsize=(14,6), dpi=100)

#Specify the 3D graphics to draw with projection='3d'

ax = fig.add_subplot(1,2,1, projection='3d')
ax.plot_surface(X, Y, Z, rstride=10, cstride=10, lw=0, color='c')



#write a program to create a pie chart of the popularity of programming languages

popularity = [200,334,890,290,679,300,980] #No of users of programming languages

prog_lang = ['Java', 'C#', 'C++', 'CSS', 'Java Script', 'Python', 'R']

fig = plt.figure(figsize=(14,6), dpi=100)

plt.pie(popularity,
       shadow = True, 
       autopct= '%.f%%', startangle = 180,
       explode=[0,0,0,0,0,0,0.1],
       labels = prog_lang)

plt.title('Popularity of Programming languages')

plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2042464114832536, 'fraction_numerical': 0.06668660287081339, 'mean_word_length': 5.142332415059688, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, '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': '5752', 'license': 'MIT', 'n_tokens_mistral': 3178, 'n_tokens_neox': 2967, 'n_words': 641, 'path': 'notebooks/MatplotLib lessons 2.ipynb', 'repo_name': 'TolaAbiodun/2020-Pandas-tutorial_notes', 'size': '6688'}