Matplotlib is a low level graph plotting library in python that serves as a visualization utility.
Matplotlib was created by John D. Hunter.
Most of the Matplotlib utilities lies under the pyplot
submodule, and are usually imported under the plt
alias.
Plotting
The plot()
function is used to draw points (markers) in a diagram.
To plot only the markers, you can use shortcut string notation parameter ‘o’, which means ‘rings’.
xpoints = np.array([1, 8])
ypoints = np.array([3, 10])
plt.plot(xpoints, ypoints, 'o')
plt.show()
If we do not specify the points in the x-axis, they will get the default values 0, 1, 2, 3,
Maker
You can use the keyword argument marker
to emphasize each point with a specified marker
plt.plot(ypoints, 'o:r')
## marker|line|color
plt.show()
Marker | Description | |
---|---|---|
‘o’ | Circle | Try it » |
‘*’ | Star | Try it » |
‘.’ | Point | Try it » |
‘,’ | Pixel | Try it » |
‘x’ | X | Try it » |
‘X’ | X (filled) | Try it » |
‘+’ | Plus | Try it » |
‘P’ | Plus (filled) | Try it » |
’s’ | Square | Try it » |
‘D’ | Diamond | Try it » |
’d' | Diamond (thin) | Try it » |
‘p’ | Pentagon | Try it » |
‘H’ | Hexagon | Try it » |
‘h’ | Hexagon | Try it » |
‘v’ | Triangle Down | Try it » |
‘^’ | Triangle Up | Try it » |
‘<’ | Triangle Left | Try it » |
‘>’ | Triangle Right | Try it » |
‘1’ | Tri Down | Try it » |
‘2’ | Tri Up | Try it » |
‘3’ | Tri Left | Try it » |
‘4’ | Tri Right | Try it » |
‘|’ | Vline | Try it » |
‘_’ | Hline |
Line Syntax | Description | |
---|---|---|
‘-’ | Solid line | Try it » |
‘:’ | Dotted line | Try it » |
‘–’ | Dashed line | Try it » |
‘-.’ | Dashed/dotted line |
Color Syntax | Description | |
---|---|---|
‘r’ | Red | Try it » |
‘g’ | Green | Try it » |
‘b’ | Blue | Try it » |
‘c’ | Cyan | Try it » |
’m' | Magenta | Try it » |
‘y’ | Yellow | Try it » |
‘k’ | Black | Try it » |
‘w’ | White |
You can use the keyword argument markersize
or the shorter version, ms
to set the size of the markers.
plt.plot(ypoints, marker = 'o', ms = 20)