【Python】Matplotlib

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()
MarkerDescription
‘o’CircleTry it »
‘*’StarTry it »
‘.’PointTry it »
‘,’PixelTry it »
‘x’XTry it »
‘X’X (filled)Try it »
‘+’PlusTry it »
‘P’Plus (filled)Try it »
’s’SquareTry it »
‘D’DiamondTry it »
’d'Diamond (thin)Try it »
‘p’PentagonTry it »
‘H’HexagonTry it »
‘h’HexagonTry it »
‘v’Triangle DownTry it »
‘^’Triangle UpTry it »
‘<’Triangle LeftTry it »
‘>’Triangle RightTry it »
‘1’Tri DownTry it »
‘2’Tri UpTry it »
‘3’Tri LeftTry it »
‘4’Tri RightTry it »
‘|’VlineTry it »
‘_’Hline
Line SyntaxDescription
‘-’Solid lineTry it »
‘:’Dotted lineTry it »
‘–’Dashed lineTry it »
‘-.’Dashed/dotted line
Color SyntaxDescription
‘r’RedTry it »
‘g’GreenTry it »
‘b’BlueTry it »
‘c’CyanTry it »
’m'MagentaTry it »
‘y’YellowTry it »
‘k’BlackTry 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)
Licensed under CC BY-NC-SA 4.0
Last updated on Jan 14, 2021 00:00 UTC
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy