1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > python绘图使用matplotlib色卡

python绘图使用matplotlib色卡

时间:2023-05-11 16:26:25

相关推荐

python绘图使用matplotlib色卡

python绘图使用matplotlib色卡

python绘图一般使用两个库,matplotlibseaborn

这两个库的色卡不同,使用起来经常迷惑,特此总结:

matplotlib具有以下经典色卡:

或者连续的色卡

Matplotlib更多的色卡可见:/stable/tutorials/colors/colormaps.html

import matplotlib.pyplot as pltfrom matplotlib import cm# 取颜色color = plt.get_cmap('Set2')color

import numpy as np# 在柱图中使用颜色plt.bar(range(5), np.random.rand(5), color=plt.get_cmap('Accent')(range(5)))

# 在饼图中使用颜色cmap = plt.colormaps["tab20c"]inner_colors = cmap([1, 2, 5, 6, 9, 10])size = 0.3vals = np.array([[60., 32.], [37., 40.], [29., 10.]])plt.pie(vals.flatten(), radius=1-size, colors=inner_colors, wedgeprops=dict(width=size, edgecolor='w'))plt.show()

seaborn在此基础上封装的更厉害,直接使用palette=colorname即可

# 在seaborn中使用matplotlib色卡import seaborn as snsimport pandas as pddata = pd.read_csv('D:/acad2/csv/data_ob.csv')plt.figure(figsize=(15, 10))sns.violinplot( x=data["class"], y=data["speed"], linewidth=1, palette='Pastel1')sns.set_theme(style="darkgrid", palette=None ,font='Times New Roman',font_scale=3)plt.show()

ne ,font=‘Times New Roman’,font_scale=3)

plt.show()

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。