0% found this document useful (0 votes)
9 views6 pages

Introduction to Matplotlib Basics

The document is a guide for using Matplotlib and NumPy for data visualization in Python, particularly in the context of Raspberry Pi programming. It provides examples of plotting lines and points using the plot() function, including how to plot without connecting lines and using default x-points. The document serves as a tutorial for beginners in data visualization and programming with Python.

Uploaded by

Haya
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views6 pages

Introduction to Matplotlib Basics

The document is a guide for using Matplotlib and NumPy for data visualization in Python, particularly in the context of Raspberry Pi programming. It provides examples of plotting lines and points using the plot() function, including how to plot without connecting lines and using default x-points. The document serves as a tutorial for beginners in data visualization and programming with Python.

Uploaded by

Haya
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

RASPBERRY PI COURSE GUIDE

thingsRoam Academy Contact: +92-308-1222240 [Link]

Email: academy@[Link]
NumPy and Visualization:

Matplotlib
[Link] 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):

import [Link] as plt


import numpy as np

xpoints = [Link]([0, 6])


ypoints = [Link]([0, 250])

[Link](xpoints, ypoints)
[Link]()

Plotting x and y points


The plot() function is used to draw points (markers) in a diagram.

By default, the plot() function draws a line from point to point.

The function takes parameters for specifying points in the diagram.


Parameter 1 is an array containing the points on the x-axis.

Parameter 2 is an array containing the points on the y-axis.

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.

thingsRoam Academy Contact: +92-308-1222240 [Link]

Email: academy@[Link]
Example
Draw a line in a diagram from position (1, 3) to position (8, 10):

import [Link] as plt


import numpy as np

xpoints = [Link]([1, 8])


ypoints = [Link]([3, 10])

[Link](xpoints, ypoints)
[Link]()

thingsRoam Academy Contact: +92-308-1222240 [Link]

Email: academy@[Link]
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):

import [Link] as plt


import numpy as np

xpoints = [Link]([1, 8])


ypoints = [Link]([3, 10])

[Link](xpoints, ypoints, 'o')


[Link]()

thingsRoam Academy Contact: +92-308-1222240 [Link]

Email: academy@[Link]
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):

import [Link] as plt


import numpy as np

xpoints = [Link]([1, 2, 6, 8])


ypoints = [Link]([3, 8, 1, 10])

[Link](xpoints, ypoints)
[Link]()

thingsRoam Academy Contact: +92-308-1222240 [Link]

Email: academy@[Link]
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:

import [Link] as plt


import numpy as np

ypoints = [Link]([3, 8, 1, 10, 5, 7])

[Link](ypoints)
[Link]()

thingsRoam Academy Contact: +92-308-1222240 [Link]

Email: academy@[Link]

You might also like