3

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?

Error:

~\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 

Code:

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'
cubick
  • 293
  • 3
  • 13
Ashita Ramteke
  • 119
  • 1
  • 7
  • 20

1 Answers1

3

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'
William Miller
  • 9,839
  • 3
  • 25
  • 46