Python社区  »  Python

Python绘图|matplotlib05(强烈建议收藏)-内置单颜色(一)

pythonic生物人 • 1 周前 • 92 次点击  
阅读 7

Python绘图|matplotlib05(强烈建议收藏)-内置单颜色(一)

这个颜色系列共有5篇文章,详细介绍matplotlib绘图颜色使用;
出于兴趣,花了较长时间整理;
本篇汇总matplotlib支持的颜色格式及内置的单颜色色号
首发于本人公众号:pythonic生物人

更好的阅读体验请戳:

Python绘图|matplotlib05-内置单颜色(一)

目录

1、matplotlib支持的颜色格式

2、matplotlib颜色使用方法

3、matplotlib内置单颜色色号
    BASE_COLORS色号
    BASE_COLORS色图 
    TABLEAU_COLORS色号
    TABLEAU_COLORS色图 
    CSS4_COLORS色号
    CSS4_COLORS色图
    XKCD_COLORS色号
    XKCD_COLORS色图

复制代码

1、matplotlib支持的颜色格式

RGB 或者 RGBA 元组格式颜色

元组中浮点型数值位于 [0, 1] 之间,e.g(0.1, 0.2, 0.5) 或 (0.1, 0.2, 0.5, 0.3). RGA即Red, Green, Blue;RGBA即Red, Green, Blue, Alpha;

RGB or RGBA对应的hex 格式颜色

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

[0,1]之间的任意浮点数

(e.g., '0.5'),其中0为纯黑色,1为白色;

'b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'几种基本色

X11/CSS4中的颜色

e.g. "blue";

xkcd中的颜色

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

'Cn'格式颜色

matplotlib.rcParams['axes.prop_cycle']可输出所有颜色,['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf'],'C0'对应'#1f77b4',依次类推;

Tableau 的colormap中颜色

e.g. 'tab:blue';


2、matplotlib颜色使用方法

#源自官网实例
import matplotlib.pyplot as plt
import 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 string
ax.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内置单颜色色号

matplotlib内置的颜色可以使用matplotlib.colors 调用,有'BASE_COLORS','TABLEAU_COLORS','CSS4_COLORS'及 'XKCD_COLORS'四类。使用matplotlib.colors.类名称可输出颜色号。

BASE_COLORS色号

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色图

TABLEAU_COLORS色号

tab:blue #1f77b4
tab:orange #ff7f0e
tab:green #2ca02c
tab:red #d62728
tab:purple #9467bd
tab:brown #8c564b
tab:pink #e377c2
tab:gray #7f7f7f
tab:olive #bcbd22
tab:cyan #17becf
复制代码

TABLEAU_COLORS色图

CSS4_COLORS色号

共计148种颜色。

颜色名称 hex色号
aliceblue #F0F8FF
antiquewhite #FAEBD7
aqua #00FFFF
aquamarine #7FFFD4
azure #F0FFFF
beige #F5F5DC
bisque #FFE4C4
black #000000
blanchedalmond #FFEBCD
blue #0000FF
blueviolet #8A2BE2
brown #A52A2A
burlywood #DEB887
cadetblue #5F9EA0
chartreuse #7FFF00
chocolate #D2691E
coral #FF7F50
cornflowerblue #6495ED
cornsilk #FFF8DC
crimson #DC143C
cyan #00FFFF
darkblue #00008B
darkcyan #008B8B
darkgoldenrod #B8860B
darkgray #A9A9A9
darkgreen #006400
darkgrey #A9A9A9
darkkhaki #BDB76B
darkmagenta #8B008B
darkolivegreen #556B2F
darkorange #FF8C00
darkorchid #9932CC
darkred #8B0000
darksalmon #E9967A
darkseagreen #8FBC8F
darkslateblue 


    
#483D8B
darkslategray #2F4F4F
darkslategrey #2F4F4F
darkturquoise #00CED1
darkviolet #9400D3
deeppink #FF1493
deepskyblue #00BFFF
dimgray #696969
dimgrey #696969
dodgerblue #1E90FF
firebrick #B22222
floralwhite #FFFAF0
forestgreen #228B22
fuchsia #FF00FF
gainsboro #DCDCDC
ghostwhite #F8F8FF
gold #FFD700
goldenrod #DAA520
gray #808080
green #008000
greenyellow #ADFF2F
grey #808080
honeydew #F0FFF0
hotpink #FF69B4
indianred #CD5C5C
indigo #4B0082
ivory #FFFFF0
khaki #F0E68C
lavender #E6E6FA
lavenderblush #FFF0F5
lawngreen #7CFC00
lemonchiffon #FFFACD
lightblue #ADD8E6
lightcoral #F08080
lightcyan #E0FFFF
lightgoldenrodyellow #FAFAD2
lightgray #D3D3D3
lightgreen #90EE90
lightgrey #D3D3D3
lightpink #FFB6C1
lightsalmon #FFA07A
lightseagreen #20B2AA
lightskyblue #87CEFA
lightslategray #778899
lightslategrey #778899
lightsteelblue #B0C4DE
lightyellow #FFFFE0
lime #00FF00
limegreen #32CD32
linen #FAF0E6
magenta #FF00FF
maroon #800000
mediumaquamarine #66CDAA
mediumblue #0000CD
mediumorchid #BA55D3
mediumpurple #9370DB
mediumseagreen #3CB371
mediumslateblue #7B68EE
mediumspringgreen #00FA9A
mediumturquoise #48D1CC
mediumvioletred #C71585
midnightblue #191970
mintcream #F5FFFA
mistyrose #FFE4E1
moccasin #FFE4B5
navajowhite #FFDEAD
navy #000080
oldlace #FDF5E6
olive #808000
olivedrab #6B8E23
orange #FFA500
orangered #FF4500
orchid #DA70D6
palegoldenrod #EEE8AA
palegreen #98FB98
paleturquoise #AFEEEE
palevioletred #DB7093
papayawhip #FFEFD5
peachpuff #FFDAB9
peru #CD853F
pink #FFC0CB
plum #DDA0DD
powderblue #B0E0E6
purple #800080
rebeccapurple #663399
red #FF0000
rosybrown #BC8F8F
royalblue #4169E1
saddlebrown #8B4513
salmon #FA8072
sandybrown #F4A460
seagreen #2E8B57
seashell #FFF5EE
sienna #A0522D
silver #C0C0C0
skyblue #87CEEB
slateblue #6A5ACD
slategray #708090
slategrey #708090



    
snow #FFFAFA
springgreen #00FF7F
steelblue #4682B4
tan #D2B48C
teal #008080
thistle #D8BFD8
tomato #FF6347
turquoise #40E0D0
violet #EE82EE
wheat #F5DEB3
white #FFFFFF
whitesmoke #F5F5F5
yellow #FFFF00
yellowgreen #9ACD32
复制代码

CSS4_COLORS色图 

XKCD_COLORS色号

共计949种色号。

xkcd:cloudy blue #acc2d9
xkcd:dark pastel green #56ae57
xkcd:dust #b2996e
xkcd:electric lime #a8ff04
xkcd:fresh green #69d84f
xkcd:light eggplant #894585
xkcd:nasty green #70b23f
xkcd:really light blue #d4ffff
xkcd:tea #65ab7c
xkcd:warm purple #952e8f
xkcd:yellowish tan #fcfc81
xkcd:cement #a5a391
xkcd:dark grass green #388004
xkcd:dusty teal #4c9085
xkcd:grey teal #5e9b8a
xkcd:macaroni and cheese #efb435
xkcd:pinkish tan #d99b82
xkcd:spruce #0a5f38
xkcd:strong blue #0c06f7
xkcd:toxic green #61de2a
xkcd:windows blue #3778bf
xkcd:blue blue #2242c7
xkcd:blue with a hint of purple #533cc6
xkcd:booger #9bb53c
xkcd:bright sea green #05ffa6
xkcd:dark green blue #1f6357
xkcd:deep turquoise #017374
xkcd:green teal #0cb577
xkcd:strong pink #ff0789
xkcd:bland #afa88b
xkcd:deep aqua #08787f
xkcd:lavender pink #dd85d7
xkcd:light moss green #a6c875
xkcd:light seafoam green #a7ffb5
xkcd:olive yellow #c2b709
xkcd:pig pink #e78ea5
xkcd:deep lilac #966ebd
xkcd:desert #ccad60
xkcd:dusty lavender #ac86a8
xkcd:purpley grey #947e94
xkcd:purply #983fb2
xkcd:candy pink #ff63e9
xkcd:light pastel green #b2fba5
xkcd:boring green #63b365
xkcd:kiwi green #8ee53f
xkcd:light grey green #b7e1a1



    
xkcd:orange pink #ff6f52
xkcd:tea green #bdf8a3
xkcd:very light brown #d3b683
xkcd:egg shell #fffcc4
xkcd:eggplant purple #430541
xkcd:powder pink #ffb2d0
xkcd:reddish grey #997570
xkcd:baby shit brown #ad900d
xkcd:liliac #c48efd
xkcd:stormy blue #507b9c
xkcd:ugly brown #7d7103
xkcd:custard #fffd78
xkcd:darkish pink #da467d
xkcd:deep brown #410200
xkcd:greenish beige #c9d179
xkcd:manilla #fffa86
xkcd:off blue #5684ae
xkcd:battleship grey #6b7c85
xkcd:browny green #6f6c0a
xkcd:bruise #7e4071
xkcd:kelley green #009337
xkcd:sickly yellow #d0e429
xkcd:sunny yellow #fff917
xkcd:azul #1d5dec
xkcd:darkgreen #054907
xkcd:green/yellow #b5ce08
xkcd:lichen #8fb67b
xkcd:light light green #c8ffb0
xkcd:pale gold #fdde6c
xkcd:sun yellow #ffdf22
xkcd:tan green #a9be70
xkcd:burple #6832e3
xkcd:butterscotch #fdb147
xkcd:toupe #c7ac7d
xkcd:dark cream #fff39a
xkcd:indian red #850e04
xkcd:light lavendar #efc0fe
xkcd:poison green #40fd14
xkcd:baby puke green #b6c406
xkcd:bright yellow green #9dff00
xkcd:charcoal grey #3c4142
xkcd:squash #f2ab15
xkcd:cinnamon #ac4f06
xkcd:light pea green #c4fe82
xkcd:radioactive green #2cfa1f
xkcd:raw sienna #9a6200
xkcd:baby purple #ca9bf7
xkcd:cocoa #875f42
xkcd:light royal blue #3a2efe
xkcd:orangeish #fd8d49
xkcd:rust brown #8b3103
xkcd:sand brown #cba560
xkcd:swamp #698339
xkcd:tealish green #0cdc73
xkcd:burnt siena #b75203
xkcd:camo #7f8f4e
xkcd:dusk blue #26538d
xkcd:fern #63a950
xkcd:old rose #c87f89
xkcd:pale light green #b1fc99
xkcd:peachy pink #ff9a8a
xkcd:rosy pink #f6688e
xkcd:light bluish green #76fda8
xkcd:light bright green #53fe5c
xkcd:light neon green #4efd54
xkcd:light seafoam #a0febf
xkcd:tiffany blue #7bf2da
xkcd:washed out green #bcf5a6
xkcd:browny orange #ca6b02
xkcd:nice blue #107ab0
xkcd:sapphire #2138ab
xkcd:greyish teal #719f91
xkcd:orangey yellow #fdb915
xkcd:parchment #fefcaf
xkcd:straw #fcf679
xkcd:very dark brown #1d0200
xkcd:terracota #cb6843
xkcd:ugly blue #31668a
xkcd:clear blue #247afd
xkcd:creme #ffffb6
xkcd:foam green #90fda9
xkcd:grey/green #86a17d
xkcd:light gold #fddc5c
xkcd:seafoam blue #78d1b6
xkcd:topaz #13bbaf
xkcd:violet pink #fb5ffc
xkcd:wintergreen #20f986
xkcd:yellow tan #ffe36e
xkcd:dark fuchsia #9d0759
xkcd:indigo blue #3a18b1
xkcd:light yellowish green #c2ff89
xkcd:pale magenta #d767ad
xkcd:rich purple #720058



    
xkcd:sunflower yellow #ffda03
xkcd:green/blue #01c08d
xkcd:leather #ac7434
xkcd:racing green #014600
xkcd:vivid purple #9900fa
xkcd:dark royal blue #02066f
xkcd:hazel #8e7618
xkcd:muted pink #d1768f
xkcd:booger green #96b403
xkcd:canary #fdff63
xkcd:cool grey #95a3a6
xkcd:dark taupe #7f684e
xkcd:darkish purple #751973
xkcd:true green #089404
xkcd:coral pink #ff6163
xkcd:dark sage #598556
xkcd:dark slate blue #214761
xkcd:flat blue #3c73a8
xkcd:mushroom #ba9e88
xkcd:rich blue #021bf9
xkcd:dirty purple #734a65
xkcd:greenblue #23c48b
xkcd:icky green #8fae22
xkcd:light khaki #e6f2a2
xkcd:warm blue #4b57db
xkcd:dark hot pink #d90166
xkcd:deep sea blue #015482
xkcd:carmine #9d0216
xkcd:dark yellow green #728f02
xkcd:pale peach #ffe5ad
xkcd:plum purple #4e0550
xkcd:golden rod #f9bc08
xkcd:neon red #ff073a
xkcd:old pink #c77986
xkcd:very pale blue #d6fffe
xkcd:blood orange #fe4b03
xkcd:grapefruit #fd5956
xkcd:sand yellow #fce166
xkcd:clay brown #b2713d
xkcd:dark blue grey #1f3b4d
xkcd:flat green #699d4c
xkcd:light green blue #56fca2
xkcd:warm pink #fb5581
xkcd:dodger blue #3e82fc
xkcd:gross green #a0bf16
xkcd:ice #d6fffa
xkcd:metallic blue #4f738e
xkcd:pale salmon #ffb19a
xkcd:sap green #5c8b15
xkcd:algae #54ac68
xkcd:bluey grey #89a0b0
xkcd:greeny grey #7ea07a
xkcd:highlighter green #1bfc06
xkcd:light light blue #cafffb
xkcd:light mint #b6ffbb
xkcd:raw umber #a75e09
xkcd:vivid blue #152eff
xkcd:deep lavender #8d5eb7
xkcd:dull teal #5f9e8f
xkcd:light greenish blue #63f7b4
xkcd:mud green #606602
xkcd:pinky #fc86aa
xkcd:red wine #8c0034
xkcd:shit green #758000
xkcd:tan brown #ab7e4c
xkcd:darkblue #030764
xkcd:rosa #fe86a4
xkcd:lipstick #d5174e
xkcd:pale mauve #fed0fc
xkcd:claret #680018
xkcd:dandelion #fedf08
xkcd:orangered #fe420f
xkcd:poop green #6f7c00
xkcd:ruby #ca0147
xkcd:dark #1b2431
xkcd:greenish turquoise #00fbb0
xkcd:pastel red #db5856
xkcd:piss yellow #ddd618
xkcd:bright cyan #41fdfe
xkcd:dark coral #cf524e
xkcd:algae green #21c36f
xkcd:darkish red #a90308
xkcd:reddy brown #6e1005
xkcd:blush pink #fe828c
xkcd:camouflage green #4b6113
xkcd:lawn green #4da409
xkcd:putty #beae8a
xkcd:vibrant blue #0339f8
xkcd:dark sand #a88f59
xkcd:purple/blue #5d21d0
xkcd:saffron #feb209
xkcd:twilight #4e518b



    
xkcd:warm brown #964e02
xkcd:bluegrey #85a3b2
xkcd:bubble gum pink #ff69af
xkcd:duck egg blue #c3fbf4
xkcd:greenish cyan #2afeb7
xkcd:petrol #005f6a
xkcd:royal #0c1793
xkcd:butter #ffff81
xkcd:dusty orange #f0833a
xkcd:off yellow #f1f33f
xkcd:pale olive green #b1d27b
xkcd:orangish #fc824a
xkcd:leaf #71aa34
xkcd:light blue grey #b7c9e2
xkcd:dried blood #4b0101
xkcd:lightish purple 
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/71827
 
92 次点击  
分享到微博