<jupyter_start><jupyter_text>Tirgul 5The topics are:- Plots- Histograms- BoxPlots- Lots of Fun!  matplotlib - library used for graphics1. For matplotlib video tutorials: https://www.youtube.com/watch?v=UO98lJQ3QGI1. Matplotlib tutorial: https://www.datacamp.com/community/tutorials/matplotlib-tutorial-python1. Matplitlib Docs: https://matplotlib.org/stable/contents.html<jupyter_code># Import matplotlib, we usually work with pyplot
import matplotlib.pyplot as plt

# Plot size in jupyter
plt.rcParams['figure.figsize'] = [10, 5]
xValues = [10,20,30]
yValues = [100,120,110]
fig = plt.figure()
plt.plot(xValues,yValues)
plt.show()
# We can set titles for x\y labels
plt.title('this is a nice title')
plt.xlabel('x values')
plt.ylabel('y values')
plt.plot(xValues,yValues)
plt.show()
# We can save the figure as an image
fig.savefig('my_figure.png') # remember to refresh files display<jupyter_output><empty_output><jupyter_text>Let's plot some practicle plotsRead the *trees.csv* file and display height vs volume graph<jupyter_code>import pandas as pd
url = 'trees.csv'
treesData = pd.read_csv(url)
treesData.head()
treesHeight = treesData['Height']
treesVolume = treesData['Volume']
plt.plot(treesHeight,treesVolume,'bo') # b- is for 'bule', 'o' sets the marker shape to be a circle. For more colors/shapes look a the docs
plt.title('Trees Volume vs Height')
plt.ylabel('Volume')
plt.xlabel('Height')
plt.show()<jupyter_output><empty_output><jupyter_text>Display the *boxplot*+ O is an outlier+ \- represents the max/min values that are not outliers+ red line is the medial+ The box top/bottom represent the 2nd and 3rd quarters of the data<jupyter_code>myData = [treesData['Height'] , treesData['Volume']]
fig=plt.boxplot(myData)<jupyter_output><empty_output><jupyter_text>Histogram:<jupyter_code>plt.hist(treesData['Height'] )
plt.ylabel('# num of appearances')
plt.xlabel('height')
plt.title('Histogram of trees height')<jupyter_output><empty_output><jupyter_text>Matplotlib excercises: https://pynative.com/python-matplotlib-exercise/<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0,10*np.pi , 1000)
print("X: {}...{}".format(x[:5],x[-5:]))
y = np.sin(x)
print("Y: {}...{}".format(y[:5],y[-5:]))
plt.plot(x,y)<jupyter_output>X: [0.         0.03144737 0.06289475 0.09434212 0.1257895 ]...[31.29013704 31.32158441 31.35303179 31.38447916 31.41592654]
Y: [0.         0.03144219 0.06285329 0.09420224 0.12545803]...[-1.25458030e-01 -9.42022363e-02 -6.28532900e-02 -3.14421909e-02
 -1.22464680e-15]<jupyter_text>Subplots<jupyter_code># We can plot several subplots in one figure
fig = plt.figure() # create a plot figure
# create the first of two panels and set current axis
import numpy as np
x = np.linspace(-2*np.pi, 2*np.pi, 100)
plt.subplot(2, 1, 1) # (rows, columns, panel number)
plt.plot(x, np.sin(x))
plt.title('sin x')
# create the second panel and set current axis
plt.subplot(2, 1, 2)
plt.plot(x, np.cos(x), color = 'red' , linestyle = '--'); # --r will also work
plt.title('cos x',color = 'green', fontsize = 20)<jupyter_output><empty_output><jupyter_text>self excercise:<jupyter_code># plot y=x^2 from -10 to 10
# with x and y labels and title and legend
# with dashed yellow line
x = np.linspace(-10,10,1000)
plt.plot(x,x**2,'--y')
plt.xlabel('x')
plt.ylabel('y=x^2')
plt.title('y=x^2')<jupyter_output><empty_output><jupyter_text>Plot X/Y axis limits<jupyter_code># we can control the axis limits:
plt.plot(x, np.sin(x))
plt.xlim(-4,4)
plt.ylim(-2,2)
plt.show()
plt.plot(x, np.sin(x))
plt.axis('tight')
# Set equal ratio
plt.plot(x, np.sin(x))
plt.axis('equal');<jupyter_output><empty_output><jupyter_text>Plot Legend<jupyter_code>plt.plot(x, np.sin(x), '-g', label='sin(x)')
plt.plot(x, np.cos(x), ':r', label='cos(x)')
plt.legend();<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16068152031454783, 'fraction_numerical': 0.06526867627785059, 'mean_word_length': 5.706502636203866, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '45197', 'license': 'MIT', 'n_tokens_mistral': 1686, 'n_tokens_neox': 1475, 'n_words': 345, 'path': 'tirgul5.ipynb', 'repo_name': 'inbartzurs/exam', 'size': '3815'}