Introduction to Matplotlib
Introduction to Matplotlib
Email: [email protected]
NumPy and Visualization:
Matplotlib
Matplotlib.pyplot provides a MATLAB-like way of plotting. This means that pyplot has
many functions to make changes to a figure and pictures. Matplotlib in combination with
Jupyter Notebook is a popular way to visualize data using Python for all kinds of
applications in Artificial Intelligence and Data Science.
Example
Draw a line in a diagram from position (0,0) to position (6,250):
plt.plot(xpoints, ypoints)
plt.show()
If we need to plot a line from (1, 3) to (8, 10), we have to pass two arrays [1, 8] and
[3, 10] to the plot function.
Email: [email protected]
Example
Draw a line in a diagram from position (1, 3) to position (8, 10):
plt.plot(xpoints, ypoints)
plt.show()
Email: [email protected]
Plotting Without Line
To plot only the markers, you can use shortcut string notation parameter 'o', which
means 'rings'.
Example
Draw two points in the diagram, one at position (1, 3) and one in position (8, 10):
Email: [email protected]
Multiple Points
You can plot as many points as you like, just make sure you have the same number of
points in both axis.
Example
Draw a line in a diagram from position (1, 3) to (2, 8) then to (6, 1) and finally to position
(8, 10):
plt.plot(xpoints, ypoints)
plt.show()
Email: [email protected]
Default X-Points
If we do not specify the points in the x-axis, they will get the default values 0, 1, 2, 3,
(etc. depending on the length of the y-points.
So, if we take the same example as above, and leave out the x-points, the diagram will
look like this:
Example
Plotting without x-points:
plt.plot(ypoints)
plt.show()
Email: [email protected]