[英]plot with matplotlib using django
How I can add on my code that I want colors without color yellow because the yellow is just for outliers?我如何在我的代码中添加我想要没有黄色的颜色,因为黄色仅用于异常值?
def show_absorbance(df_abs, crop_left, crop_right, clean_param):
df_abs_t = df_abs.iloc[:, -1].T
outliers = inf_norm_detection(df_abs,crop_left, crop_right, clean_param)
colors = list(mcolors.CSS4_COLORS.values())
plt.figure(figsize=(16, 10))
plt.subplot(221)
plt.plot(df_abs.to_numpy()[:, 1:].T, 'yellow')
for i, outlier in enumerate(outliers):
plt.plot(df_abs.loc[outlier].iloc[1:], c=colors[i],label=outlier)
plt.legend()
plt.show()
so when I defined here colors , how I remove the yellow?所以当我在这里定义颜色时,我如何去除黄色?
colors = list(mcolors.CSS4_COLORS.values())
Use a list comprehension with an if-clause:使用带有 if 子句的列表推导:
colors = [color for color in mcolors.CSS4_COLORS.values() if color != 'yellow']
Or use whatever the appropriate value for "yellow" is.或者使用“黄色”的任何适当值。
For multiple colors, you can use this variant:对于多种颜色,您可以使用此变体:
colors = [color for color in mcolors.CSS4_COLORS.values() if color not in ['yellow', 'green']]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.