<jupyter_start><jupyter_text>Matplotlib- A data visualization package in Python- Matplotlib is one of the most popular python library used for data visualization.It uses numpy for data source. It can be used in Python and IPython shells, Jupyter notebook and web application servers also.It is designed to resemble MATLAB, a proprietary programming language developed by MathWorks.- Matplotlib was originally written by <NAME> in 2003, Now it is in release version-3.3.3  Installing MatplotLib- pip install matplotlib or- conda install matplotlib<jupyter_code>import matplotlib.pyplot as plt # import pyplot as plt

plt.plot([1, 2, 3, 4]) # plot a line
plt.ylabel('some numbers') # label the y-axis
plt.savefig('abc.png')
plt.show() # show the plot<jupyter_output><empty_output><jupyter_text>- here if we provide only one list, it will be displayed in y-axis and pyplot automatically generate x-axis values.<jupyter_code>plt.plot([1, 2, 3, 4],[1, 4, 9, 16])<jupyter_output><empty_output><jupyter_text>Formating the style of plot- For every x, y pair of arguments, there is an optional third argument which is the format string that indicates the color and line type of the plot.<jupyter_code>plt.plot([1, 2, 3, 4], [1, 4, 9, 16], 'b-') # plot x and y axis and red- circle
plt.axis([0, 6, 0, 20]) # range of x-axis and y-axis
plt.show() # plot show/display<jupyter_output><empty_output><jupyter_text>list or array- All sequences are converted to numpy arrays internally. - The example below illustrates plotting several lines with different format styles in one function call using arrays.<jupyter_code># evenly sampled time at 200ms intervals
import numpy as np
t = np.arange(0., 5., 0.2)
t
a=t
b=t**2
c=t**3
# red dashes, blue squares and green triangles
plt.plot(t, t**2, 'bs', t, t**3, 'g^')
plt.show()
# Lets create a sin wave with matplotlib
from matplotlib import pyplot as plt
import numpy as np
import math #needed for definition of pi
x = np.arange(0, math.pi*2, 0.05)
y = np.sin(x)
plt.plot(x,y)
plt.xlabel("angle") # x-axis label
plt.ylabel("sine") # y-axis label
plt.title('sine wave') # title of the figure
plt.show()
# multiple plot in a single figure
plt.plot(x, np.sin(x), 'b*')
plt.plot(x, np.cos(x), 'r+')
plt.plot(x, -np.sin(x), 'g--')
plt.show()<jupyter_output><empty_output><jupyter_text>object oriented approach of Pyplot- create a figure/canvas as an object first- Now add each plot element such as axis, label, legend as an attribute to figure<jupyter_code>fig = plt.figure() # plot area define
ax=fig.add_axes([0,0,1,1]) # define cordinate range of plot
ax.set_title("sine wave") # add title
ax.set_xlabel('angle') # add x-axis label
ax.set_ylabel('sine') # add y- axis label
ax.plot(x,y) # plot the figure<jupyter_output><empty_output><jupyter_text>Figure function has many parameters such as     - Figsize:  (width,height) tuple in inches    - Dpi	:    Dots per inches    - Facecolor	Figure patch facecolor    - Edgecolor	Figure patch edge color    - Linewidth	Edge line width - Reference: https://matplotlib.org/3.3.2/api/_as_gen/matplotlib.pyplot.figure.html<jupyter_code>fig = plt.figure(figsize=(10,5), dpi=300,facecolor='blue',edgecolor='blue',linewidth=0.1)
ax=fig.add_axes([0,0,1,1])
ax.set_title("sine wave")
ax.set_xlabel('angle')
ax.set_ylabel('sine')
ax.plot(x,y)<jupyter_output><empty_output><jupyter_text>ax.legend- https://matplotlib.org/3.3.1/api/_as_gen/matplotlib.axes.Axes.legend.html- Syntax:    - ax.legend(handles, labels, loc)- Location is determined by following codes    - Best &emsp; 0    - upper right &emsp; 1    - upper left &emsp; 2    - lower left &emsp; 3    - lower right &emsp; 4    - Right         &emsp;5    - Center left	  &emsp;6    - Center right	 &emsp;7    - lower center	  &emsp;8    - upper center	  &emsp;9    - Center	     &emsp;10  Color codes    - ‘b’	Blue, ‘g’	Green, ‘r’	Red, ‘b’	Blue, ‘c’	Cyan etc Marker codes    - ‘.’	Point marker, ‘o’	Circle marker, ‘x’	X marker, ‘D’	Diamond marker, ‘H’	Hexagon marker, ‘s’	Square marker, ‘+ Plus marker Line styles    - -‘	Solid line, ‘—‘	Dashed line, ‘-.’	Dash-dot line ‘:’	Dotted line ‘H’	Hexagon marker<jupyter_code>import matplotlib.pyplot as plt
y = [1, 4, 9, 16, 25,36,49, 64]
x1 = [1, 16, 30, 42,55, 68, 77,88]
x2 = [1,6,12,18,28, 40, 52, 65]
fig = plt.figure()
ax = fig.add_axes([0,0,1,1])
l1 = ax.plot(x1,y,'ys-') # solid line with yellow colour and square marker
l2 = ax.plot(x2,y,'go--') # dash line with green colour and circle marker
ax.legend(labels = ('tv', 'Smartphone'), loc = 'lower right') # legend placed at lower right
ax.set_title("Advertisement effect on sales")
ax.set_xlabel('medium')
ax.set_ylabel('sales')
plt.show()
plt.plot(x1,y,'ys-') # solid line with yellow colour and square marker
plt.plot(x2,y,'go--')
# inset figure
fig=plt.figure()
y = [1, 4, 9, 16, 25,36,49, 64]
x1 = [1, 16, 30, 42,55, 68, 77,88]
x2 = [1,6,12,18,28, 40, 52, 65]
axes1 = fig.add_axes([0.1, 0.1, 0.8, 0.8]) # main axes
axes2 = fig.add_axes([0.15, 0.5, 0.3, 0.3]) # inset axes
axes1.plot(x1,y, 'ro')
axes2.plot(x2,y,'b+')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14068666140489344, 'fraction_numerical': 0.04044988161010261, 'mean_word_length': 4.433011789924973, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 30, 'https://': 2, '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': '327192', 'license': 'MIT', 'n_tokens_mistral': 2023, 'n_tokens_neox': 1851, 'n_words': 602, 'path': 'notebook/Matplotlib Tutorial- Data Visualization.ipynb', 'repo_name': 'tejshahi/starter-machine-learning', 'size': '5076'}