本文介绍了KeyError:"axes.color_cycle不是有效的rc参数(有关有效参数的列表,请参阅rcParams.keys())"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在此行上出现错误rcParams['axes.color_cycle'] = dark2_colors
下面是回溯.如何确保我解决了这个问题?
I am having the error on this line rcParams['axes.color_cycle'] = dark2_colors
And below is the traceback. How can I make sure that i fix this issue?
错误:
~\anaconda3\lib\site-packages\matplotlib\__init__.py in __setitem__(self, key, val)
806 except KeyError:
807 raise KeyError(
--> 808 f"{key} is not a valid rc parameter (see rcParams.keys() for "
809 f"a list of valid parameters)")
810
代码:
dark2_colors = [(0.10588235294117647, 0.6196078431372549, 0.4666666666666667),
(0.8509803921568627, 0.37254901960784315, 0.00784313725490196),
(0.4588235294117647, 0.4392156862745098, 0.7019607843137254),
(0.9058823529411765, 0.1607843137254902, 0.5411764705882353),
(0.4, 0.6509803921568628, 0.11764705882352941),
(0.9019607843137255, 0.6705882352941176, 0.00784313725490196),
(0.6509803921568628, 0.4627450980392157, 0.11372549019607843),
(0.4, 0.4, 0.4)]
rcParams['figure.figsize'] = (10, 6)
rcParams['figure.dpi'] = 150
rcParams['axes.color_cycle'] = dark2_colors
rcParams['lines.linewidth'] = 2
rcParams['axes.grid'] = True
rcParams['axes.facecolor'] = '#eeeeee'
rcParams['font.size'] = 14
rcParams['patch.edgecolor'] = 'none'
推荐答案
参数为axes.prop_cycle
,而不是axes.color_cycle
.但是,还需要注意的是axes.prop_cycle
接受matplotlib.cycler
实例,而不是颜色列表.所以你的代码应该是
The parameter is axes.prop_cycle
, not axes.color_cycle
. However it also needs to be noted that axes.prop_cycle
accepts a matplotlib.cycler
instance, not a list of colors. So your code should be
import matplotlib
dark2_colors = [(0.10588235294117647, 0.6196078431372549, 0.4666666666666667),
(0.8509803921568627, 0.37254901960784315, 0.00784313725490196),
(0.4588235294117647, 0.4392156862745098, 0.7019607843137254),
(0.9058823529411765, 0.1607843137254902, 0.5411764705882353),
(0.4, 0.6509803921568628, 0.11764705882352941),
(0.9019607843137255, 0.6705882352941176, 0.00784313725490196),
(0.6509803921568628, 0.4627450980392157, 0.11372549019607843),
(0.4, 0.4, 0.4)]
rcParams['figure.figsize'] = (10, 6)
rcParams['figure.dpi'] = 150
rcParams['axes.prop_cycle'] = matplotlib.cycler(color=dark2_colors)
rcParams['lines.linewidth'] = 2
rcParams['axes.grid'] = True
rcParams['axes.facecolor'] = '#eeeeee'
rcParams['font.size'] = 14
rcParams['patch.edgecolor'] = 'none'
这篇关于KeyError:"axes.color_cycle不是有效的rc参数(有关有效参数的列表,请参阅rcParams.keys())"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!