In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Today, I would like to share with you the relevant knowledge points about how to use the annotate function in python. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.
Annotate function of python annotate function
The detailed parameters of this function can be viewed by calling the built-in property _ _ doc__.
Import matplotlib.pyplot as plt # plt.annotate (str, xy=data_point_position, xytext=annotate_position, # va= "center", ha= "center", xycoords= "axes fraction", # textcoords= "axes fraction", bbox=annotate_box_type, arrowprops=arrow_style) # str is the content to annotate data points Support to enter a string # xy= is the location of the data point to add comments # xytext= is the location of the comment content # bbox= is the style and color depth of the comment box, the smaller the fc, the darker the color of the comment box. Support to enter a dictionary # va= "center", ha= "center" indicates that the coordinates of the comment box are based on the center of the comment box, not the lower left corner of the comment box (v represents vertical direction) H represents horizontal direction) # xycoords and textcoords can specify the coordinate system of the data point and the coordinate system of the annotation content, usually only need to specify xycoords, textcoords is the same as xycoords by default # arrowprops can specify the style support of arrowhead, enter a dictionary # plt.annotate () detailed parameters can be viewed with _ _ doc__, such as: print (plt.annotate.__doc__)
Example 1:
Import matplotlib.pyplot as plt fig = plt.figure (1, facecolor='white') fig.clf () plt.annotate ('a decision node', (0.1,0.5), (0.5,0.1), va= "center", ha= "center", xycoords= "axes fraction", textcoords= "axes fraction", bbox=dict (box, fc= "0.8"), arrowprops=dict (arrow) plt.show ()
The results are as follows:
Example 2: assign different coordinate systems to annotations and data points
Import matplotlib.pyplot as plt fig = plt.figure (1, facecolor='white') fig.clf () # here specifies that the coordinate system origin of the data point is in the lower left corner of the xy axis The origin of the coordinate system of the annotation is in the lower-left corner of the image (figure) # so that the annotation content is shifted down to cover the x-axis plt.annotate ('a decision node', (0.1,0.5), (0.5,0.1), va= "center", ha= "center", xycoords= "axes fraction", textcoords= "figure fraction", bbox=dict (box, fc= "0.8"). Arrowprops=dict (arrow)) plt.show ()
The results are as follows:
Analysis of Visual annotate () function
Function function: add directed comment text to the details of the graphic content.
Call signature:
Plt.annotate (string, xy= (np.pi/2, 1.0), xytext= ((np.pi/2) + 0.15,1), weight= "bold", color= "b", arrowprops=dict (arrow, connection, color= "b"))
String: annotation text for drawing content
Xy: the location coordinates of the content of the annotated drawing
Xytext: the location coordinates of the comment text
Weight: font weight style of comment text
Color: the font color of the comment text
Arrowprops: attribute dictionary that indicates the arrowhead of the annotated content
Code implementation:
Import matplotlib.pyplot as pltimport numpy as npx = np.linspace (0.05,10,1.0) y = np.sin (x) plt.plot (x, y, ls= "-.", lw=2, c = "c", label= "plot figure") plt.legend () plt.annotate ("maximum", xy= (np.pi/2, 1000), xytext= ((np.pi/2) + 1.0,0.8), weight= "bold", color= "b", arrowprops=dict (arrow, connection) Color= "b")) plt.show ()
That's all of the article "how to use the annotate function in python". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
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.