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.
Contents of this article

1. Quick installation of palettable
pip install palettable -i https://pypi.tuna.tsinghua.edu.cn/simple
2. Quick use of palettable color bar (Colormap)
Import palettable package
import palettable from palettable.cartocolors.qualitative import Bold_9 #为了描述方便,此处直接倒入palettable.cartocolors.qualitative大类下的Bold_9小类, #实际使用时可直接用palettable.cartocolors.qualitative.Bold_9
palettable important properties-visualized chroma bar
Bold_9.show_discrete_image()#Bold_9各种颜色条图片

palettable important attribute-the number of single colors in the output chroma bar
print(Bold_9.number)#Bold_9这种colormap中单颜色的数目
9That is, the above picture has 9 cells
palettable important attributes-output the color number value of a single color in the chroma bar
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
[[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
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()
Seaborn中使用palettable
例子来自几行代码绘制靓丽矩阵图
使用palettable.tableau.TrafficLight_9
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)
使用palettable.tableau.BlueRed_6使用palettable.cartocolors.qualitative.Bold_9
使用palettable.wesanderson.Moonrise5_6
使用palettable.cartocolors.diverging.ArmyRose_7_r
3、palettable包含那些颜色条(Colormap)
palettable下面有16大类Colormap,共计1587小类Colormap,合计上万种单颜色可供使用,已经整理为pdf格式,感兴趣的可以
包含以下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
共计1587小类【每个小类还有逆类,名称后面加“_r”即可】上面16大类下面有数个小类,例如,著名BI软件Tableau的配色条palettable.tableau这一大类,下面有palettable.tableau.BlueRed_12,palettable.tableau.GreenOrange_12等等数个小类:
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
也就是类似上面的这种有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!

Python's flexibility is reflected in multi-paradigm support and dynamic type systems, while ease of use comes from a simple syntax and rich standard library. 1. Flexibility: Supports object-oriented, functional and procedural programming, and dynamic type systems improve development efficiency. 2. Ease of use: The grammar is close to natural language, the standard library covers a wide range of functions, and simplifies the development process.

Python is highly favored for its simplicity and power, suitable for all needs from beginners to advanced developers. Its versatility is reflected in: 1) Easy to learn and use, simple syntax; 2) Rich libraries and frameworks, such as NumPy, Pandas, etc.; 3) Cross-platform support, which can be run on a variety of operating systems; 4) Suitable for scripting and automation tasks to improve work efficiency.

Yes, learn Python in two hours a day. 1. Develop a reasonable study plan, 2. Select the right learning resources, 3. Consolidate the knowledge learned through practice. These steps can help you master Python in a short time.

Python is suitable for rapid development and data processing, while C is suitable for high performance and underlying control. 1) Python is easy to use, with concise syntax, and is suitable for data science and web development. 2) C has high performance and accurate control, and is often used in gaming and system programming.

The time required to learn Python varies from person to person, mainly influenced by previous programming experience, learning motivation, learning resources and methods, and learning rhythm. Set realistic learning goals and learn best through practical projects.

Python excels in automation, scripting, and task management. 1) Automation: File backup is realized through standard libraries such as os and shutil. 2) Script writing: Use the psutil library to monitor system resources. 3) Task management: Use the schedule library to schedule tasks. Python's ease of use and rich library support makes it the preferred tool in these areas.

To maximize the efficiency of learning Python in a limited time, you can use Python's datetime, time, and schedule modules. 1. The datetime module is used to record and plan learning time. 2. The time module helps to set study and rest time. 3. The schedule module automatically arranges weekly learning tasks.

Python excels in gaming and GUI development. 1) Game development uses Pygame, providing drawing, audio and other functions, which are suitable for creating 2D games. 2) GUI development can choose Tkinter or PyQt. Tkinter is simple and easy to use, PyQt has rich functions and is suitable for professional development.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 Linux new version
SublimeText3 Linux latest version

Zend Studio 13.0.1
Powerful PHP integrated development environment