TransWikia.com

Create SwatchLegend with some elements including opacity

Mathematica Asked on August 17, 2021

colorList = 
 Flatten[{{Gray, Opacity[0.2]}, {Magenta, Opacity[0.2]}, 
   ColorData["Rainbow"][(# - 1)/5] & /@ Range[5]}]

This creates a list {Grey

But I want a list that joins opacity to the gray and magenta colors:
{{Gray,Opacity[0.2]},{Magenta,Opacity[0.2]},”Other colors”}

I tried catenate and partition to try and reform the list into the shape I wanted, but it did not work. Any help would be appreciated.

One Answer

You can construct your colorlist in a number of alternative ways:

colorList1 = {{Gray, Opacity[0.2]}, {Magenta, Opacity[0.2]}, 
   Sequence @@ (ColorData["Rainbow"][(# - 1)/5] & /@ Range[5])};

colorList2 = Join[{{Gray, Opacity[0.2]}, {Magenta, 
    Opacity[0.2]}}, (ColorData["Rainbow"][(# - 1)/5] & /@ Range[5])];

colorList3 = Flatten[{Opacity[0.2, Gray], Opacity[0.2, Magenta], 
    ColorData["Rainbow"][(# - 1)/5] & /@ Range[5]}];

colorList4 = Flatten[{Directive[Opacity[0.2], Gray], Directive[Opacity[0.2], Magenta], 
    ColorData["Rainbow"][(# - 1)/5] & /@ Range[5]}];



SwatchLegend[colorList1, Range[Length@colorList1]]

enter image description here

SwatchLegend[colorList2, Range[Length@colorList1]]

same picture

SwatchLegend[colorList3, Range[Length@colorList3]]

same picture

SwatchLegend[colorList4, Range[Length@colorList4]]

same picture

Correct answer by kglr on August 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP