[Tex/LaTex] Automatically choosing preset color schemes in pgfplots based on number of entries

colorpgfplots

This is really more of a question to satisfy personal curiosity than to solve a real problem.

When choosing the colour schemes for my plots, I try to select colours that will work well with the amount of items involved in the plot. This means using sets of colours that are above all aesthetically pleasing, but also that contrast well, etc. (eg. schemes created with a website like this).

However, I was wondering if it would be possible to define a set of 2,3,4,…,n colours that work well, and have pgfplots (or some other package?) select automatically from the one that matches the amount of entries.

I looked around for similar questions, but I didn't seem to find anything. The colour sets could be defined as cycle lists, but it's the automatic selection that I'm wondering about. Can this be done? Any ideas?

Best Answer

This is just a longish comment. I might be wrong in understanding the workflow and hopefully I'll be corrected if so.

In pgfplots things do not happen all at once. First your plot commands together with the axis options are parsed and stored as PGF paths. Then a visualization scheme kicks in (and I'm not 100% sure about the order) and path colorings, legend styles etc. are assigned. Then they are drawn with low level TikZ/PGF commands.

In order to select a cycle list, the plots need to be collected already such that they are counted. But that would probably be too late to change the drawing options. I don't think this functionality is supported off-the-shelf.

Note that this is a very rough description, there are many things checked in each layer so don't take this too literal.

But if you are willing to provide the number of plot items then it's a matter of defining a style with an argument that selects the predefined plot cycle list.

Related Question