0

I am automatically generating numerous figures where each figure has 7 subplots. in each subplot there are numerous traces (up to 17 in one subplot).

In which sequence does Matplotlib assign the colors of the traces automatically as I need to generate a figure key.

i.e. if I have in my code for a subplot with four traces:

axarr[0, 0].plot(data for trace 1) #what would matlibplot color assignment be

axarr[0, 0].plot(data for trace 2) #what would matlibplot color assignment be

axarr[0, 0].plot(data for trace 3) #what would matlibplot color assignment be

axarr[0, 0].plot(data for trace 4) #what would matlibplot color assignment be
DavidG
  • 24,279
  • 14
  • 89
  • 82

1 Answers1

0

There are only 8 predefined colors according to the Matlb colorspec documentation.

But you can easily generate a matrix with colors yourself and pick them by index to make sure you get consistent colors.

>> C=ones(17, 3) ./ [1:17]'

C =

    1.0000    1.0000    1.0000
    0.5000    0.5000    0.5000
    0.3333    0.3333    0.3333
    0.2500    0.2500    0.2500
    0.2000    0.2000    0.2000
    0.1667    0.1667    0.1667
    0.1429    0.1429    0.1429
    0.1250    0.1250    0.1250
    0.1111    0.1111    0.1111
    0.1000    0.1000    0.1000
    0.0909    0.0909    0.0909
    0.0833    0.0833    0.0833
    0.0769    0.0769    0.0769
    0.0714    0.0714    0.0714
    0.0667    0.0667    0.0667
    0.0625    0.0625    0.0625
    0.0588    0.0588    0.0588

>> C(1, :)

ans =

     1     1     1

>> C(17, :)

ans =

    0.0588    0.0588    0.0588

You could then add 'Color', C[index, :] to you plot command, see the LineSpec parameter of plot

Jonathan
  • 748
  • 3
  • 20
  • OP is using python, not MATLAB – DavidG Mar 28 '18 at 12:41
  • Oops, missed that. The solution offered still stands though as according to the matplotlib documentation you can also supply a 1x3 vector with numeric values to define color as can be seen on https://matplotlib.org/2.0.2/api/colors_api.html – Jonathan Mar 28 '18 at 12:46