In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "how to use the line chart method plot () in matplotlib". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Definition and call of plt.plot ()
Definition:
Plt.plot (* args, scalex=True, scaley=True, data=None, * * kwargs)
Call:
Plot ([x], y, [fmt], *, data=None, * * kwargs)
Plot ([x], y, [fmt], [x2], y2, [fmt2],..., * * kwargs)
Location parameters:
[x], y, [fmt]
Keyword parameter transfer:
* the following parameters
Different types of x sequences
Text-type x sequence
# data X = [8Person3Person5Grampt'] # will be positioned on the scale of the x-axis in order [0Lie1JEI 2jin3] plt.plot (XPowerYLING = 'odynere cymbals') ax = plt.gca () print ('x-axis scale:', plt.xticks ()) # list xticklabels_lst = ax.get_xticklabels () print ('-'* 70)
X-axis scale: ([0,1,2,3],)
Print ('x-axis scale label:', list (xticklabels_lst)) # is a text label
X-axis scale label: [Text (0,0,8'), Text (1,0,3'), Text (2,0,5'), Text (3,0,'t')]
Digital x sequence
# data X = [8Yue3Power5Power1] # will be positioned on the scale of the x-axis by number [8pj3je 5jp1] on the scale of the x-axis Y = [1pje 2je 3je 4] plt.plot (XLI YLINGO = 'odyne parcels') ax = plt.gca () print ('x-axis scale:', plt.xticks ()) # array xticklabels_lst = ax.get_xticklabels () print ('-'* 70)
X-axis scale: (array ([0.1,2.,3.4.5.6.7.8.9]),)
Print ('x-axis scale label:', list (xticklabels_lst)) # is a text label arranged by serial number
X-axis scale labels: [Text (0.0,0,0'), Text (1.0,0,1'), Text (2.0,0,2'), Text (3.0,0,3'), Text (4.0,0,4'), Text (5.0,0,5'), Text (6.0,0,6'), Text (7.0,0,7'), Text (8.0,0) '8'), Text (9.0,0,9')]
2 types-2 Lin
# data X1 = [8pje 3pje 5pjt'] X2 = [8pje 3pje 5pje 1] Y = [1pje 2pas 3pje 4] plt.plot (X2pIe YLING = 'ooJing pencils') plt.plot (X1Med YLING = 'OOBLING') ax = plt.gca () print ('x-axis scale:', plt.xticks ()) xticklabels_lst = ax.get_xticklabels () print ('-'* 70)
X-axis scale: ([0,1,2,3],)
Print ('x-axis scale label:', list (xticklabels_lst))
X-axis scale label: [Text (0,0,8'), Text (1,0,3'), Text (2,0,5'), Text (3,0,'t')]
Provide a different number of location parameters
Several ways of calling
No parameter
# return an empty list plt.plot ()
[]
Plot ([x], y, [fmt], *, data=None, * * kwargs) plot ([x], y, [fmt], [x2], y2, [fmt2],..., * * kwargs)
1 parameter
# provide a number (point) plt.plot (4.5)
[]
# provide a numeric sequence plt.plot ([4.5pr 2p3], marker='o')
[]
2 parameters
The principle of automatic analysis of position parameters
(XBI y) form
# XPUBY is the sequence plt.plot ([2 mine1, 3], [0.5 dome 2 pr 2.5], marker='o')
[]
# XUnix y is a scalar plt.plot (2, ['z'], marker ='o')
[]
(ycmt) form
# plt.plot (2 recordings) # Unrecognized character z in format string# y is a scalar plt.plot (2)
[]
# y is the sequence plt.plot ([2jimi 1jue 3], 'rmurmuri stories')
[]
3 parameters
([X], y, [fmt]) form
Plt.plot ([2Jing 1jue 3], [0.5Jing 2Med 2.5],'p-murmur, # marker='o' markersize = 15)
[]
If # fmt does not write, or'', then the default style plt.plot is used ([2 mine1 marker='o' markersize 3], [0.5 mine2 min2 5],'', # meme = 15)
[]
Drawing Line2D
Draw lines only: default for drawing
Default style: blue [line] [unmarked]
# marker = None means that plt.plot is not set ([2meme2.5])
[]
Draw marks only
Plt.plot ([2, 2.5, 1],'o')
[]
Draw lines + marks
Plt.plot ([2mai 2.5jue 1], 'Omuri')
[]
Plt.plot ([2Jing 1jue 3], 'bo--')
[]
Is the combination order of fmt random?
6 the unity of pictures and conclusions
# 6 combinations # [color] [marker] [line], 3 arbitrary combinations are 6 possibilities # b: blue # o: circle mark # -: dotted line fmt = ['bo--','b--o','ob--','o--b','--bo','--ob'] for i in range (len (fmt)): plt.subplot (2) plt.plot ([2) Fmt [I]) # conclusion: [color] [marker] [line] Each is optional, and each attribute can choose to write or not write # regardless of the order in which they are located in the combination
[line]-line supported by fmt
Line Styles
= character description =
'-' solid line style'--'dashed line style' -' Dash-dot line style': 'dotted line style
[tag]-marker supported by fmt
Markers
= character description =
'.' Point marker', 'pixel marker\\' o\ 'circle marker' v 'triangle_down marker' ^ 'triangle_up marker', 'triangle_right marker' 1 'tri_down marker' 2 'tri_up marker' 3 'tri_left marker' 4' tri_right marker'\ 'square marker' p' pentagon marker'* 'star marker' h' hexagon1 marker 'H'hexagon2 marker' + 'plus marker' x marker 'D'diamond marker 'd'thin_diamond marker' | 'vline marker' _ 'hline marker
[colors] supported by fmt-color
Colors
The supported color abbreviations are the single letter codes
= character color =
'b'blue 'g'green 'r'red 'c'cyan 'm'magenta 'y'yellow 'k'black 'w'white
All styles: marks, lines, color references
Link: https://www.kesci.com/home/project/5ea4e5da105d91002d506ac6
Style Properti
Properties of lines
# including: (except color) # the style and width of the line # linestyle or ls: {'-','- -','-.',':',} # linewidth or lw: float ls_lst = ['-','- -','-.',':',] lw_lst = [1prim 3, 5J 7] for i in range (len (ls_lst)): plt.plot [iTun1] * 4 lw lslst [I], lw = lw_ LST [I])
Attributes of the tag
# contains:''marker: marker style # border (color and border weight) markeredgecolor or mec: color markeredgewidth or mew: float # face color markerfacecolor or mfc: color markerfacecoloralt or mfcalt: color # alternate tag color # size of the tag markersize or ms: float markevery: None or int or (int, int) or slice or List [int] or float or (float, float)''# linestyle = None means no setting By default, # linestyle =''linestyle =' none''is unformatted Wireless bar plt.plot ([4 none', 2 markerfacecolor 1 None 3], linestyle = 'none', =' oasis, markersize = 30, # edge markeredgecolor = 'ritual, markeredgewidth = 5, # face markerfacecolor =' gong, # markerfacecolor = 'none', # markerfacecolor = None,)
[]
Synthesis: line drawings marked with hollow circles
The marked point is covered on top of the line Located in the upper layer layer: [top] spines > marker > line > backgroud [bottom] spines: four borders of the axis spines enclose the line drawing inside''plt.plot ([1LJ 5J 3J 4], marker =' oval, markersize = 20, # edge markeredgecolor = 'ritual, markeredgewidth = 5, # face markerfacecolor =' w') # White Same as the background color, cover the lines to create a hollow visual effect # markerfacecolor = 'none', # colorless, transparent, you will see the line # markerfacecolor = None, # do not set, default color) # markerfacecolor ='', # unrecognized # markerfacecolor ='', # unrecognized
[]
The use of data keyword
Dictionary data
# Dictionary data d = {'name':list (' abcd'), 'age': [22 name','age',ddata 20 18 abcd' 27]} plt.plot (' dictionary = d)
[]
DataFrame data
# DataFrame data d = {'name':list (' abcd'), 'age': [22 name':list 20, 18 DataFrame 27]} df = pd.DataFrame (d) dfnameage0a221b202c183d27plt.plot (' name','age',data = df)
[]
That's all for "how to use the line chart method plot () in matplotlib". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.