假设我在Matplotlib中有颜色.也许它是一个字符串('k')或一个rgb元组((0.5, 0.1, 0.8))甚至一些十六进制(#05FA2B).在Matplotlib中是否有一个命令/便利功能,可以让我变暗(或变亮)那种颜色.
即在那里matplotlib.pyplot.darken(c, 0.1)或类似的东西?我想我所希望的是,在幕后,将采用一种颜色,将其转换为HSL,然后将L值乘以某个给定因子(地板为0,加上1)或明确设置L值到给定值并返回修改后的颜色.
我使用Seaborn包创建了一个带有重叠stripplot的嵌套boxplot.我在stackoverflow上看到了关于如何使用sns.boxplot生成的ax.artists 为单个框和所有框编辑框属性的答案.
有没有办法用类似的方法编辑whisker,cap,flier等属性?目前我必须手动编辑seaborn - > categorical.py文件中类的restyle_boxplot方法中的值,_BoxPlotter()以从默认绘图到所需的绘图:
这是我的代码供参考:
sns.set_style('whitegrid')
fig1, ax1 = plt.subplots()
ax1 = sns.boxplot(x="Facility", y="% Savings", hue="Analysis",
data=totalSavings)
plt.setp(ax1.artists,fill=False) # <--- Current Artist functionality
ax1 = sns.stripplot(x="Facility", y="% Savings", hue="Analysis",
data=totalSavings, jitter=.05,edgecolor = 'gray',
split=True,linewidth = 0, size = 6,alpha = .6)
ax1.tick_params(axis='both', labelsize=13)
ax1.set_xticklabels(['Test 1','Test 2','Test 3','Test 4','Test 5'], rotation=90)
ax1.set_xlabel('')
ax1.set_ylabel('Percent Savings (%)', fontsize = 14)
handles, labels = ax1.get_legend_handles_labels()
legend1 = plt.legend(handles[0:3], ['A','B','C'],bbox_to_anchor=(1.05, 1), …Run Code Online (Sandbox Code Playgroud) 我正在使用这个漂亮的箱线图,来自 @Parfait 的回答。
j不得不使用range(i*5,i*5+5). 为什么?red。medianprops=dict(color="red")行不通的。怎么做?免责声明:我不知道我在做什么。
这是使用随机数据的代码:
# import the required library
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import string
import matplotlib.colors as mc
import colorsys
# data
df = pd.DataFrame(np.random.normal(np.random.randint(5,15),np.random.randint(1,5),size=(100, 16)), columns=list(string.ascii_uppercase)[:16])
# Boxplot
fig, ax = plt.subplots(figsize=(9, 10))
medianprops=dict(color="red")
ax = sns.boxplot(data=df, orient="h", showfliers=False, palette = "husl")
ax = sns.stripplot(data=df, orient="h", jitter=True, size=7, …Run Code Online (Sandbox Code Playgroud)