In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how matplotlib assigns drawing colors in python. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
When drawing with matplotlib's pyplot library, you will often find that various open source code does not specify "color" in a consistent way. It is found that there are 8 ways to specify color.
Eight ways are as follows:
Use floating point values between [0,1] to represent RGB/RGBA color values
Use hexadecimal RGB/RGBA strings to represent colors
Use color initials
Use the color name of X11/CSS4
Use xkcd color
T10 colors of Tableau
Circular colors represented by CN
Floating-point value represented by a string
Through the color settings in the above 8, almost all color choices can be achieved. The second of the eight ways should be the best, which can be flexibly selected according to the hexadecimal color code. The following details each way of the specific concept and use of the process, and gives the source code.
1. Use floating-point values between [0,1] to represent RGB/RGBA color values.
For the RGB/RGBA color model, the value of each color component is between 0 and 255. After zooming, it becomes a floating-point number between [0prime1] as the parameter value of the color:
Draw_bar ((255Compact 255,255x255,0Universe), ax1, "tuple of RGB/RGBA")
The figure is as follows:
2. Use hexadecimal RGB/RGBA string to represent color
In the color representation method, the hexadecimal values of six digits represent the three colors of RGB, that is, the conversion of 0-255s. For example, "# FF3300" means that the red component is FF, the green component is 33, and the blue component is 00.
At this point, the code that uses the hexadecimal string as the color parameter is as follows:
Draw_bar ("# FF0000", ax2, "hex color code")
The figure is as follows:
3. Use the initials of the color
According to the convention, the first letter of the color in {'baked,' gelled, 'rusted,' clocked, 'milled,' yearly, 'knight,' w'} can be used as a color parameter:
Draw_bar ("b", ax, "color's first char")
The figure is as follows:
4. Use the color name of X11/CSS4
According to the color definition in HTML, you can use the color name directly as a parameter, and there are many specific names. It is recommended that you can consult the relevant information.
The mode of use is as follows:
Draw_bar ("pink", ax, "color's name")
The figure is as follows:
5. Use xkcd color
According to the color name provided by xkcd website [2], it can be used as a color parameter:
Draw_bar ("violet", ax, "xkc color")
The figure is as follows:
6. T10 colors of Tableau
By using the color defined by Tableau, you can use the {'tab:blue',' tab:orange', 'tab:green'} given in [1] as color parameters:
Draw_bar ("tab:brown", ax, "T10")
The figure is as follows:
7. Circular colors represented by CN
According to [1], this should be a built-in representation, and no specific documentation has been found for the time being:
Draw_bar ("C2", ax, "Cn")
The figure is as follows:
8. Floating-point values represented by strings
This method is rarely introduced and used less frequently, and it is not as convenient as floating-point RGB mode:
Draw_bar (color_type= "0.2", ax=ax, title=" float string ")
The figure is as follows:
9. Drawing function and summary
The definition of the draw_bat () function in the previous analysis is as follows:
Def draw_bar (color_type, ax, title): "" draw with different color formats Parameters-color_type:object any feasible color type ax: Ax drawing axis title:string the title of the subgraph "" x = np.linspace (1,6) 6) y = np.linspace (0.2,1,6) ax.bar (xonomx, height=y, width=0.6, color=color_type) ax.set_title (title) return None
Thank you for reading! This is the end of this article on "how matplotlib assigns drawing colors in python". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
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.