Table of Contents
1. Quick installation of palettable" > 1. Quick installation of palettable
2. Quick use of palettable color bar (Colormap)" >2. Quick use of palettable color bar (Colormap)
Import palettable package" >Import palettable package
palettable important properties-visualized chroma bar" >palettable important properties-visualized chroma bar
palettable important attribute-the number of single colors in the output chroma bar" >palettable important attribute-the number of single colors in the output chroma bar
palettable important attributes-output the color number value of a single color in the chroma bar" > palettable important attributes-output the color number value of a single color in the chroma bar
Matplotlib中使用palettable" >Matplotlib中使用palettable
" >Seaborn中使用palettable
3、palettable包含那些颜色条(Colormap)" >3、palettable包含那些颜色条(Colormap)
Home Backend Development Python Tutorial The 'hands-on” in the palette world-palettable

The 'hands-on” in the palette world-palettable

Aug 10, 2023 pm 03:13 PM
python



  • Some friends say that python visualization’s built-in colors are ugly, then you must not have encountered palettable , palettable is a colorbar (Colormap) library written in pure python, which brings together a large number of colorbars from well-known visualization software (such as Tableau color system, matplotlib partial color system, etc.). There are a total of 1587 colorbar (Colormap) categories that can be used. There are tens of thousands of single colors. This article details how to use palettable.
    The 'hands-on” in the palette world-palettable


Contents of this article

The 'hands-on” in the palette world-palettable

1. Quick installation of palettable

1

pip install palettable -i https://pypi.tuna.tsinghua.edu.cn/simple

Copy after login

2. Quick use of palettable color bar (Colormap)

Import palettable package

1

2

3

4

5

import palettable

from palettable.cartocolors.qualitative import Bold_9

 

#为了描述方便,此处直接倒入palettable.cartocolors.qualitative大类下的Bold_9小类,

#实际使用时可直接用palettable.cartocolors.qualitative.Bold_9

Copy after login

palettable important properties-visualized chroma bar

1

Bold_9.show_discrete_image()#Bold_9各种颜色条图片

Copy after login
The 'hands-on” in the palette world-palettable

palettable important attribute-the number of single colors in the output chroma bar

1

print(Bold_9.number)#Bold_9这种colormap中单颜色的数目

Copy after login

9That is, the above picture has 9 cells

palettable important attributes-output the color number value of a single color in the chroma bar

1

2

3

4

print(Bold_9.colors)#Bold_9 colormap中每种颜色的RGB格式色号

 

print(Bold_9.hex_colors)#Bold_9 colormap中每种颜色的hex格式色号

print(Bold_9.mpl_colors)#RGB tuples in the range 0-1 as used by matplotlib

Copy after login

[[127, 60, 141], [17, 165, 121], [57 , 105, 172], [242, 183, 1], [231, 63, 116], [128, 186, 90], [230, 131, 16], [0, 134, 149], [207, 28 , 144]]

['#7F3C8D', '#11A579', '#3969AC', '#F2B701', '#E73F74', '#80BA5A', '#E68310', '#008695' . 0.003 92156862745098), (0.9058823529411765, 0.24705882352941178, 0.4549019607843137), (0.5019607843137255, 0.7294117647058823, 0.35294117647058826), (0.9019607843137255, 0.5137254901960784, 0.06274509803921569), (0.0, 0.5254901960784314, 0.5843137254901961), (0.8117647058823529, 0.10980392156862745, 0.56470588235294 12)]

Matplotlib中使用palettable

例子来自matplotlib-饼图(pie)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

import matplotlib.pyplot as plt

import matplotlib as mpl

import palettable

 

mpl.rc_file_defaults()

my_dpi = 96

plt.figure(figsize=(580 / my_dpi, 580 / my_dpi), dpi=my_dpi)

plt.subplot(221)

patches, texts, autotexts = plt.pie(

    x=[1, 2, 3],

    labels=['A', 'B', 'C'],

    #使用palettable.tableau.BlueRed_6

    colors=palettable.tableau.BlueRed_6.mpl_colors[0:3],

    autopct='%.2f%%',

    explode=(0.1, 0, 0))

 

patches[0].set_alpha(0.3)

patches[2].set_hatch('|')

patches[1].set_hatch('x')

plt.title('tableau.BlueRed_6', size=12)

 

mpl.rc_file_defaults()

plt.subplot(222)

 

patches, texts, autotexts = plt.pie(

    x=[1, 2, 3],

    labels=['A', 'B', 'C'],

    #使用palettable.cartocolors.qualitative.Bold_9

    colors=palettable.cartocolors.qualitative.Bold_9.mpl_colors[0:3],

    autopct='%.2f%%',

    explode=(0.1, 0, 0))

 

patches[0].set_alpha(0.3)

patches[2].set_hatch('|')

patches[1].set_hatch('x')

plt.title('cartocolors.qualitative.Bold_9', size=12)

 

mpl.rc_file_defaults()

plt.subplot(223)

 

patches, texts, autotexts = plt.pie(

    x=[1, 2, 3],

    labels=['A', 'B', 'C'],

    #使用palettable.cartocolors.qualitative.Bold_9

    colors=palettable.cartocolors.qualitative.Bold_9.mpl_colors[0:3],

    autopct='%.2f%%',

    explode=(0.1, 0, 0))

 

patches[0].set_alpha(0.3)

patches[2].set_hatch('|')

patches[1].set_hatch('x')

plt.title('cartocolors.qualitative.Bold_9', size=12)

 

plt.subplot(223)

 

patches, texts, autotexts = plt.pie(

    x=[1, 2, 3],

    labels=['A', 'B', 'C'],

    #使用palettable.lightbartlein.sequential.Blues10_5

    colors=palettable.lightbartlein.sequential.Blues10_5.mpl_colors[0:3],

    autopct='%.2f%%',

    explode=(0.1, 0, 0))

 

#matplotlib.patches.Wedge

patches[0].set_alpha(0.3)

patches[2].set_hatch('|')

patches[1].set_hatch('x')

plt.title('lightbartlein.sequential.Blues10_5', size=12)

 

plt.subplot(224)

 

patches, texts, autotexts = plt.pie(

    x=[1, 2, 3],

    labels=['A', 'B', 'C'],

    colors=palettable.wesanderson.Moonrise5_6.mpl_colors[0:3],

    autopct='%.2f%%',

    explode=(0.1, 0, 0))

 

patches[0].set_alpha(0.3)

patches[2].set_hatch('|')

patches[1].set_hatch('x')

plt.title('wesanderson.Moonrise5_6', size=12)

plt.show()

Copy after login

Seaborn中使用palettable

The 'hands-on” in the palette world-palettable例子来自几行代码绘制靓丽矩阵图
使用palettable.tableau.TrafficLight_9

1

2

3

4

5

6

7

8

9

10

11

12

13

import seaborn as sns

iris_sns = sns.load_dataset("iris")

 

import palettable

 

g = sns.pairplot(

    iris_sns,

    hue='species',

    palette=palettable.tableau.TrafficLight_9.mpl_colors,  #Matplotlib颜色

)

sns.set(style='whitegrid')

g.fig.set_size_inches(10, 8)

sns.set(style='whitegrid', font_scale=1.5)

Copy after login

The 'hands-on” in the palette world-palettable
使用palettable.tableau.BlueRed_6
The 'hands-on” in the palette world-palettable使用palettable.cartocolors.qualitative.Bold_9The 'hands-on” in the palette world-palettable使用palettable.wesanderson.Moonrise5_6The 'hands-on” in the palette world-palettable使用palettable.cartocolors.diverging.ArmyRose_7_rThe 'hands-on” in the palette world-palettable


3、palettable包含那些颜色条(Colormap)

palettable下面有16大类Colormap,共计1587小类Colormap,合计上万种单颜色可供使用,已经整理为pdf格式,感兴趣的可以
包含以下16大类

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

palettable.cartocolors.diverging

palettable.cartocolors.qualitative

palettable.cartocolors.sequential

palettable.cmocean.diverging

palettable.cmocean.sequential

palettable.colorbrewer.diverging

palettable.colorbrewer.qualitative

palettable.colorbrewer.sequential

palettable.lightbartlein.diverging

palettable.lightbartlein.sequential

palettable.scientific.diverging

palettable.scientific.sequential

palettable.matplotlib

palettable.mycarta

palettable.tableau

palettable.wesanderson

Copy after login

共计1587小类【每个小类还有逆类,名称后面加“_r”即可】上面16大类下面有数个小类,例如,著名BI软件Tableau的配色条palettable.tableau这一大类,下面有palettable.tableau.BlueRed_12,palettable.tableau.GreenOrange_12等等数个小类:

1

2

3

4

5

6

7

8

9

10

11

12

13

palettable.tableau.BlueRed_12

palettable.tableau.BlueRed_6

palettable.tableau.ColorBlind_10

palettable.tableau.Gray_5

palettable.tableau.GreenOrange_12

palettable.tableau.GreenOrange_6

palettable.tableau.PurpleGray_12

palettable.tableau.PurpleGray_6

palettable.tableau.TableauLight_10

palettable.tableau.TableauMedium_10

palettable.tableau.Tableau_10

palettable.tableau.Tableau_20

palettable.tableau.TrafficLight_9

Copy after login

也就是类似上面的这种有1587行


The above is the detailed content of The 'hands-on” in the palette world-palettable. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the function of C language sum? What is the function of C language sum? Apr 03, 2025 pm 02:21 PM

There is no built-in sum function in C language, so it needs to be written by yourself. Sum can be achieved by traversing the array and accumulating elements: Loop version: Sum is calculated using for loop and array length. Pointer version: Use pointers to point to array elements, and efficient summing is achieved through self-increment pointers. Dynamically allocate array version: Dynamically allocate arrays and manage memory yourself, ensuring that allocated memory is freed to prevent memory leaks.

Is distinctIdistinguish related? Is distinctIdistinguish related? Apr 03, 2025 pm 10:30 PM

Although distinct and distinct are related to distinction, they are used differently: distinct (adjective) describes the uniqueness of things themselves and is used to emphasize differences between things; distinct (verb) represents the distinction behavior or ability, and is used to describe the discrimination process. In programming, distinct is often used to represent the uniqueness of elements in a collection, such as deduplication operations; distinct is reflected in the design of algorithms or functions, such as distinguishing odd and even numbers. When optimizing, the distinct operation should select the appropriate algorithm and data structure, while the distinct operation should optimize the distinction between logical efficiency and pay attention to writing clear and readable code.

Who gets paid more Python or JavaScript? Who gets paid more Python or JavaScript? Apr 04, 2025 am 12:09 AM

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

How to understand !x in C? How to understand !x in C? Apr 03, 2025 pm 02:33 PM

!x Understanding !x is a logical non-operator in C language. It booleans the value of x, that is, true changes to false, false changes to true. But be aware that truth and falsehood in C are represented by numerical values ​​rather than boolean types, non-zero is regarded as true, and only 0 is regarded as false. Therefore, !x deals with negative numbers the same as positive numbers and is considered true.

What does sum mean in C language? What does sum mean in C language? Apr 03, 2025 pm 02:36 PM

There is no built-in sum function in C for sum, but it can be implemented by: using a loop to accumulate elements one by one; using a pointer to access and accumulate elements one by one; for large data volumes, consider parallel calculations.

Does H5 page production require continuous maintenance? Does H5 page production require continuous maintenance? Apr 05, 2025 pm 11:27 PM

The H5 page needs to be maintained continuously, because of factors such as code vulnerabilities, browser compatibility, performance optimization, security updates and user experience improvements. Effective maintenance methods include establishing a complete testing system, using version control tools, regularly monitoring page performance, collecting user feedback and formulating maintenance plans.

Copy and paste Love code Copy and paste Love code for free Copy and paste Love code Copy and paste Love code for free Apr 04, 2025 am 06:48 AM

Copying and pasting the code is not impossible, but it should be treated with caution. Dependencies such as environment, libraries, versions, etc. in the code may not match the current project, resulting in errors or unpredictable results. Be sure to ensure the context is consistent, including file paths, dependent libraries, and Python versions. Additionally, when copying and pasting the code for a specific library, you may need to install the library and its dependencies. Common errors include path errors, version conflicts, and inconsistent code styles. Performance optimization needs to be redesigned or refactored according to the original purpose and constraints of the code. It is crucial to understand and debug copied code, and do not copy and paste blindly.

How to obtain real-time application and viewer data on the 58.com work page? How to obtain real-time application and viewer data on the 58.com work page? Apr 05, 2025 am 08:06 AM

How to obtain dynamic data of 58.com work page while crawling? When crawling a work page of 58.com using crawler tools, you may encounter this...

See all articles