0

I'm trying to use a custom colormap for matplotlib but getting the error ValueError: Invalid RGBA argument: [(0.12156862745098039, 0.4666666666666667, 0.7058823529411765),...

It annoyingly works for a bar plot, but not for a line plot.

My absolute minimum example:

plt.bar(range(10), range(10), color=tableau20)

example_1

My failing example (actual example as more lines):

plt.plot(np.linspace(0, 10), color=tableau20)

My colormap is as follows:

tableau20 = [(0.12156862745098039, 0.4666666666666667, 0.7058823529411765),
 (0.6823529411764706, 0.7803921568627451, 0.9098039215686274),
 (1.0, 0.4980392156862745, 0.054901960784313725),
 (1.0, 0.7333333333333333, 0.47058823529411764),
 (0.17254901960784313, 0.6274509803921569, 0.17254901960784313),
 (0.596078431372549, 0.8745098039215686, 0.5411764705882353),
 (0.8392156862745098, 0.15294117647058825, 0.1568627450980392),
 (1.0, 0.596078431372549, 0.5882352941176471),
 (0.5803921568627451, 0.403921568627451, 0.7411764705882353),
 (0.7725490196078432, 0.6901960784313725, 0.8352941176470589),
 (0.5490196078431373, 0.33725490196078434, 0.29411764705882354),
 (0.7686274509803922, 0.611764705882353, 0.5803921568627451),
 (0.8901960784313725, 0.4666666666666667, 0.7607843137254902),
 (0.9686274509803922, 0.7137254901960784, 0.8235294117647058),
 (0.4980392156862745, 0.4980392156862745, 0.4980392156862745),
 (0.7803921568627451, 0.7803921568627451, 0.7803921568627451),
 (0.7372549019607844, 0.7411764705882353, 0.13333333333333333),
 (0.8588235294117647, 0.8588235294117647, 0.5529411764705883),
 (0.09019607843137255, 0.7450980392156863, 0.8117647058823529),
 (0.6196078431372549, 0.8549019607843137, 0.8980392156862745)]
roastbeeef
  • 1,039
  • 1
  • 12
  • 23

1 Answers1

0

Unlike the pyplot.bar, plot does not accept a list of colors for color, so you will have to decide for each line which color it will be. The following example uses your color number 6:

plt.plot(np.linspace(0, 10), color=tableau20[6])

Output:

enter image description here

jf_
  • 3,099
  • 2
  • 13
  • 31