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/01 Report--
This article mainly introduces Python and matplotlib how to draw, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Icon display settings in English:
Normally, the string is transmitted in the form of a string, but the English display format is not very beautiful. in order to make the text more beautiful, write in this format when writing:
Ritual stringency'
Here, if you need special mathematical characters to escape, spaces also need to be escaped.
For example: r'$This\ is\ the\ some\ text.\\ mu\\ sigma_i\\ alpha_t$'
1. Figure window and axis setting plt.figure (figsize = (20,8), dpi = 80) window for displaying pictures
1. The meaning of figure figure, which refers to the picture we drew.
2. By instantiating a figure and passing parameters, the figure instance can be used automatically in the background.
3. When the image is blurred, you can input the dpi parameter to make the image clearer.
4. Figsize: specify the size of the image
5. Linewidth: specify the width of the displayed line
6. Linestyle: specify the style of line display, such as dotted line line
Ax = plt.gca () gets the axis of the current drawing
Gca = = "get current axis" get axis
The border of an ax.spines ['right'] .set_color (' none') graphic
Spines formats the four borders by setting left\ right\ bottom\ top in []
Set_color is the setting color
Ax.xaxis.set_ticks_position ('bottom') sets which scale to use as the axis using bottom as the x-axis ax.spines [' bottom'] .set_position (('data', 0)) sets the position of the axis and sets the position of the x-axis at the 0 scale of the y-axis import numpy as npfrom matplotlib import pyplot as plt x = np.linspace (- 3,3) 50) Y1 = x*2+1y2 = x pictures 2 # create a window plt.figure () # place multiple pictures in the same window L1, = plt.plot (x, y1, label='up') L2, = plt.plot (x, y2, color= "red", linewidth=2.0, line, label='down') # set display legend plt.legend (handles= [L1, L2], labels= ['aaa',' bbb'] Loc='best') # set the value range of the axis plt.xlim ((- 1p2)) plt.ylim ((- 2p3)) # hint for setting the axis plt.xlabel ("I am x") plt.ylabel ("I am y") # generate a new coordinate point new_ticks = np.linspace (- 1pyr2) 5) # divide-1x2 into 5 copies # set the displayed coordinate unit plt.xticks (new_ticks) # artificially specify the content of the axis display # set the content displayed on the scale But you need to specify the corresponding order plt.yticks ([- 2,-1.8,1,1.22,3,], [r'$really\ bad$', R'$really\ good$']) # gca = = "get current axis" get the frame of the axis ax = plt.gca () # ax.spines ['right']. Set_color (' none') ax.spines ['top']. Set_color (' none') # change the position of the axis # set which scale to use for the axis ax.xaxis.set_ticks_position ('bottom') ax.yaxis.set_ticks_position (' left') # horizontal 0ax.spines ['bottom'] .set_position ((' data') with coordinates set to the y axis 0)) # outward Axesax.spines ['left'] .set_position ((' data', 0)) plt.show ()
2. Annotate special points (Annotation)
Using text () places the text anywhere in the axis domain. A common use case for text is to annotate some of the features of the drawing, while the annotate () method provides helper functions to make it easy. Annotate is used to add text annotations to data on graphics, and supports underlining tools with arrows, making it easy for us to add description information in the right place. There are two points to consider in dimensions: the position of the dimension represented by the parameter xy and the text position of the xytext. Both parameters are (x, y) tuples.
Parameter description:
Axes.annotate (s, xy, * args, * * kwargs)
S: the content of the comment text
Xy: annotated coordinate points, two-dimensional tuples such as (xQuery y)
Xytext: the coordinate point of the comment text, which is also a two-dimensional tuple, which is the same as xy by default
Xycoords: coordinate system attribute of the annotated point. The values allowed are as follows
The meaning of attribute value 'figure points' takes the lower left corner of the drawing area as the reference, the unit is the number of points, the unit is the number of pixels, the unit is the number of pixels, the unit is the percentage, the unit is the percentage, the lower left corner of the sub-drawing area, the unit is the number of points (a figure can have multiple axex, default is 1)' axes pixels' takes the lower-left corner of the sub-drawing area as the reference. The unit is the number of pixels' axes fraction' takes the lower left corner of the sub-drawing area as the reference, and the unit is percentage 'data' takes the annotated coordinate point xy as the reference (default)' polar' does not use the local data coordinate system, but uses the polar coordinate system
Textcoords: the coordinate system property of the annotation text, which defaults to the same value as the xycoords property, or can be set to a different value. In addition to allowing you to enter attribute values for xycoords, you are also allowed to enter the following two types:
The attribute value means the offset of the offset points' from the annotated point xy (in pixels) the offset of the offset pixels' relative to the annotated point xy (in pixels)
Arrowprops: the style of the arrow, dict (dictionary) data. If the attribute is not empty, an arrow is drawn between the comment text and the annotated point. If the 'arrowstyle' keyword is not set, the following keywords are allowed:
Keyword indicates the width of the width arrow (in points) the width of the head of the headwidth arrow (points) the length of the head of the headlength arrow (points) the percentage of contraction at both ends of the shrink arrow (in total length)? The keywords import numpy as npfrom matplotlib import pyplot as plt x = np.linspace (- 3,3,50) y1 = x*2+1plt.figure () plt.plot (x, y1, label='up') # add comments x0 = 1y0 = 2*x0 + dot in any matplotlib.patches.FancyArrowPatch, showing only one dot Blueplt.scatter (x0, y0, Song50, color='b') # kmuri-for black-- plt.plot ([x0, x0], [0, y0], 'kmuri' Lw=2.5) ax = plt.gca () ax.spines ['top']. Set_color (' none') ax.spines ['right']. Set_color (' none') ax.xaxis.set_ticks_position ('bottom') ax.yaxis.set_ticks_position (' left') ax.spines ['bottom']. Set_position ((' data', 0)) ax.spines ['left']. Set_position ((' data') 0)) # set callout # method 1plt.annotate (rattling 2xroom1% slots'% str (y0), xy= (x0, y0), xycoords='data', xytext= (+ 30,-30), textcoords='offset points', fontsize=16, arrowprops=dict (arrowstyle='- >', connectionstyle='arc3, rad=.2') plt.text (- 3.7,3, r'$This\ is\ the\ some\ text.\\ mu\\ sigma_i\\ alpha_t$' Fontdict= {'size':16,' color': 'r'}) plt.show ()
Thank you for reading this article carefully. I hope the article "how to draw Python and matplotlib" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.