<jupyter_start><jupyter_text>Matplotlib  <img src = 'https://github.com/saeed-saffari/alzahra-workshop-spr2021/blob/main/lecture/PIC/Matplotlib.png?raw=true'      width = "650"     >  You can find a lot of example [HERE](https://matplotlib.org/gallery/index.html).  Installation- Conda install matplotlib- pip install matplotlib- pip install --upgrade matplotlib  Import<jupyter_code>import numpy as np
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Specification<jupyter_code>%matplotlib inline
x = np.linspace(-10, 10, 50)
y = x ** 2

plt.figure(figsize=(15, 8))
plt.plot(x, y, c = 'r', ls = '-', lw = 3, marker = 'o', markersize = 13, markeredgecolor = 'b',
         markerfacecolor = 'm', label = '$y = x^2$')

plt.legend(fontsize = 15, loc = 'upper center')
plt.grid(c = 'k', ls = '--', alpha = 0.5)

plt.xlabel('X range', fontsize = 15, fontweight = 2, fontname = 'Times New Roman')
plt.ylabel('Y range', fontsize = 15, fontweight = 2, fontname = 'Times New Roman')
plt.title('Function $Y=x^2$\nin range (-10, 10)', fontsize = 20, fontweight = 2, fontname = 'Times New Roman', 
         c = 'darkblue')

#plt.text(-5, 60, 'First text\nin figure!', fontsize = 15, fontweight = 2, fontname = 'Times New Roman')

#plt.ylim(top = 80, bottom = 20)   #plt.ylim((20,80))
#plt.xlim(left = 0, right = 8)      #plt.xlim((0,8))

plt.axhline(40, c = 'k', ls = '--', lw = 2)
plt.axvline(0, c = 'g',ls =  '--', lw = 2)

#plt.xticket()
#plt.savefig('first_plot.jpg', dpi = 700)
plt.show()
x = np.linspace(-10, 10, 50)
y = x ** 2

plt.figure(figsize = (15,8))
plt.plot(x, 10*y, c = 'r', ls = '-', lw = 3, label = '$y = x^2$')
plt.plot(x, x**3, c = 'b', ls = '--', lw = 2, label = '$y = x^3$')
plt.plot(x, 200 * np.sin(x), c = 'g', ls = '-.', lw = 2, label = '$y =sin(x)$')

plt.grid()
plt.legend(fontsize = 15)
plt.show()
plt.figure(figsize= (15,8))

plt.subplot(2,3,1)
plt.plot(x, x**2)
plt.grid()

plt.subplot(2,3,2)
plt.plot(x, x**3)

plt.subplot(2,3,3)
plt.plot(x, np.sin(x))

plt.subplot(2,3,5)
plt.plot(x, np.tan(x))

plt.show()
fig, ax = plt.subplots(figsize = (15,8))

ax.plot(x, x**2, label = 'one')
ax.plot(x, 50 * np.sin(x), label = 'two')
ax.grid()
ax.legend()

ax.set_xlabel('x range')
ax.set_ylabel('y range')
ax.set_title('compare')

plt.show()
fig, (ax1, ax2) = plt.subplots(2,1, figsize = (15,8), sharex= True)


ax1.plot(x, x**2, label = 'one')
ax2.plot(x, 50 * np.sin(x), label = 'two')
ax1.grid()
ax2.grid()

ax2.set_xlabel('x range')
ax2.set_ylabel('y raange')
ax1.set_ylabel('y raange')
ax1.set_title('compare')

plt.show()<jupyter_output><empty_output><jupyter_text>$$ y_1 = 20 + x $$$$ y_2 = 100 - 2  \times x $$<jupyter_code>x = np.linspace(0, 100, 100)
y_1 = 20 + x
y_2 = 100 - 2 * x

plt.figure(figsize= (15,8))
plt.plot(x, y_1, c = 'r', lw = 2, label= 'Supply')
plt.plot(x, y_2, c = 'g', lw = 2, label = 'Demand')

plt.plot(x, y_2 - 20, 'b', lw = 2, ls = '-.', label = 'Demand after taxation')

plt.xlabel('quantity')
plt.ylabel('price')
plt.title('Demand and Supply plot')

plt.xlim(left = 0, right = 110)
plt.ylim(bottom = 0)

plt.axhline(80/3+20, c = 'k', ls = '--', lw = 1.5)
plt.axvline(80/3, c = 'k', ls = '--', lw = 1.5)
# or use sympy package

plt.legend(fontsize = 15)
plt.grid()

plt.fill_between(x, y_2, y_1, where = (y_2 > y_1) & (x>=20) ,color = 'darkorange', alpha = 0.7)

plt.show()<jupyter_output><empty_output><jupyter_text>Bar<jupyter_code>plt.figure(figsize= (15,8))
plt.bar([1,3,5,7], [5,8,2,9], label = 'one')
plt.bar([2,4,6,8], [4,6,1,8], label  = 'two')

plt.legend(fontsize = 15, loc = 'upper left')
#plt.grid()
plt.show()<jupyter_output><empty_output><jupyter_text>Scatter<jupyter_code>x = np.linspace(0,10,100)
e = np.random.rand(100) * 100
y = x + e

scale = np.random.rand(100) * 1000
color = np.random.random(100) 

plt.figure(figsize= (15,8))
plt.scatter(x, y, s = scale, c = color )

plt.colorbar().set_label('color bar', fontsize = 15)

plt.grid()
plt.show()
z = np.arange(100)
d = np.arange(100) * 2
m = np.arange(100)
a = np.random.randn(100)
b = z + a * 20

plt.figure(figsize= (15,8))
plt.scatter(z, b, c = m, s = d)
plt.colorbar()
plt.grid()
plt.show()<jupyter_output><empty_output><jupyter_text>Histogram  ![image.png](attachment:image.png)<jupyter_code>data = np.random.normal(0,1,100000)

x = np.linspace(-4,4, 100)
y = 1 / np.sqrt(2*np.pi) * np.exp(-x**2 /2)


plt.figure(figsize= (15,8))
plt.plot(x, y, lw = 4, c = 'k')
plt.hist(data, 100, density = 1)

plt.show()<jupyter_output><empty_output><jupyter_text>Style<jupyter_code>plt.style.available
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-10, 10, 50)
y = x ** 2

#plt.style.use('seaborn')
#plt.xkcd()

# for return in defualt
import matplotlib as mpl
mpl.rcParams.update(mpl.rcParamsDefault)

plt.figure(figsize=(15, 8))
plt.plot(x, y, c = 'r', ls = '-', lw = 3, marker = 'o', markersize = 13, markeredgecolor = 'b',
         markerfacecolor = 'm', label = '$y = x^2$')

plt.legend(fontsize = 15, loc = 'upper center')
plt.grid(c = 'k', ls = '--', alpha = 0.5)

plt.xlabel('X range', fontsize = 15, fontweight = 2, fontname = 'Times New Roman')
plt.ylabel('Y range', fontsize = 15, fontweight = 2, fontname = 'Times New Roman')
plt.title('Function $Y=x^2$\nin range (-10, 10)', fontsize = 20, fontweight = 2, fontname = 'Times New Roman', 
         c = 'darkblue')

#plt.text(-5, 60, 'First text\nin figure!', fontsize = 15, fontweight = 2, fontname = 'Times New Roman')

#plt.ylim(top = 80, bottom = 20)   #plt.ylim((20,80))
#plt.xlim(left = 0, right = 8)      #plt.xlim((0,8))

plt.axhline(40, c = 'k', ls = '--', lw = 2)
plt.axvline(0, c = 'g',ls =  '--', lw = 2)

#plt.xticket()
#plt.savefig('first_plot.jpg', dpi = 700)
plt.show()<jupyter_output><empty_output><jupyter_text>See [seeborn](https://seaborn.pydata.org) library    Exercise 3   Q4: data<jupyter_code>GDP_2017 = [4867, 3666, 2666, 2595, 336, 342, 195, 20, 445, 204, 312, 680, 834]
Life_exp = [84, 81, 81, 82, 83, 83, 70, 64, 76, 82, 77, 83, 81]
Freedom  = [96, 95, 95, 90, 96, 51, 27, 24, 17, 84, 64, 18, 99]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2158866183256427, 'fraction_numerical': 0.07234673698088333, 'mean_word_length': 4.200514138817481, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 36, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '490219', 'license': 'MIT', 'n_tokens_mistral': 3101, 'n_tokens_neox': 2692, 'n_words': 610, 'path': 'Lecture/.ipynb_checkpoints/4. Matplotlib-checkpoint.ipynb', 'repo_name': 'saeed-saffari/UT-workshop-sum2021', 'size': '6068'}