Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of matplotlib built-in single Color in Python

Shulou Source: shulou.com Published: 2022-06-01 12:22:59 10月02日 Update

Xiaobian to share with you the Python matplotlib built-in single color example analysis, I hope you have something to gain after reading this article, let's discuss it together!

1. Matplotlib supports color formats

1. RGB or RGBA tuple format colors

Floating-point values in tuples are between [0, 1], e.g(0.1, 0.2, 0.5) or (0.1, 0.2, 0.5, 0.3). RGA stands for Red, Green, Blue;RGBA stands for Red, Green, Blue, Alpha;

2. RGB or RGBA corresponding hex format color

(e.g., '#0F0F0F' or '#0F0F0F0F');

3. Any floating point number between [0,1]

(e.g., '0.5'), where 0 is pure black and 1 is white;

4. {'b',' g','r',' c','m',' y','k',' w'} several basic colors;

Colors in X11/CSS4

e.g. "blue";

6. Color in xkcd

e.g., 'purple (#7e1e9c)';

7. 'Cn' Format Color

matplotlib.rcParams ('axes.prop_cycle') can output all colors,['#1f77b4','#ff7f0e','#2ca02c','#d62728','#9467bd','#8c564b','#e377c2','#7f7f','#bcbd22','#17becf'],'C0' corresponds to '#1f77b4', and so on;

8. Tableau colors in colormap

e.g. 'tab:blue';

2. matplotlib color usage method #from official website instance import matplotlib.pyplot as pltimport numpy as np t = np.linspace (0.0, 2.0, 201)s = np.sin (2 * np.pi * t) # 1) RGB tuple:fig, ax = plt.subplots (facecolor=(.18, .31, .31),figsize=(10,5))# 2) hex string:ax.set_facecolor ('#eafff5')# 3) gray level string:ax.set_title ('Voltage vs. time chart', color='0.7')# 4) single letter color stringax.set_xlabel ('time (s)', color='c')# 5) a named color:ax.set_ylabel ('voltage (mV)', color='peachpuff')# 6) a named xkcd color:ax.plot (t, s, 'xkcd:crimson')# 7) Cn notation:ax.plot(t, .7*s, color='C4', linestyle='--')# 8) tab notation:ax.tick_params(labelcolor='tab:orange')plt.show()

3. Matplotlib built-in single color color number

Matplotlib's built-in colors can be called using matplotlib.colors, and there are four types: 'BASE_COLORS','TABLEAU_COLORS','CSS4_COLORS' and 'XKCD_COLORS'. Use the matplotlib.colors. class name to output color numbers.

'BASE_COLORS' color number b (0, 0, 1)g (0, 0.5, 0)r (1, 0, 0)c (0, 0.75, 0.75)m (0.75, 0, 0.75)y (0.75, 0.75, 0)k (0, 0, 0)w (1, 1, 1)'BASE_COLORS' Color Map

TABLEAU_COLORS color number tab:blue #1f77b4tab:orange #ff7f0etab:green #2ca02ctab:red #d62728tab:purple #9467bdtab:brown #8c564btab:pink #e377c2tab:gray #7f7f7ftab:olive #bcbd22tab:cyan #17becfTABLEAU_COLORS Color Map

CSS4_COLORS color number

There are 148 colors.

color name hex color number aliceblue #F0F8FFantiquewhite #FAEBD7aqua #00FFFFaquamarine #7FFFD4azure #F0FFFFbeige #F5F5DCbisque #FFE4C4black #00000CSS4_COLORS Color Map

XKCD_COLORS color number

A total of 949 color number.

xkcd:cloudy blue #acc2d9xkcd:dark pastel green #56ae57xkcd:dust #b2996exkcd:electric lime #a8ff04xkcd:fresh green #69d84fxkcd:light eggplant #894585xkcd:nasty green #70b23fxkcd:really light blue #d4ffffXKCD_COLORS Color Map

After reading this article, I believe you have a certain understanding of "sample analysis of single color built in matplotlib in Python". If you want to know more about it, please pay attention to the industry information channel. Thank you for reading!

Tags: Color format example analysis between article e.g. output usage name finished instance numeric method more floating point point white knowledge class name Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Technology Redmi Shulou Tech Info MySQL