Update 2: In version 10.0+, you can also use LinearGradientImage
:
Labeled[LinearGradientImage["Rainbow", ImageSize -> {30, 30}],
Style["f1", 18, Red, FontFamily -> "Times New Roman"], Top]
Update: "want the color gradient of "Rainbow" in a single box for single label":
Labeled[ImageResize[ColorData["Rainbow", "Image"], {30, 30}],
Style["f1", 18, Red, FontFamily -> "Times New Roman", ShowStringCharacters -> False],
Top]
Use
Show[ImageResize[ColorData["Rainbow", "Image"], {30, 30}], BaseStyle -> Opacity[.5]]
as the first argument of Labeled
to get:
Original answer:
labels = {"f1", "f2", "f3", "f4"};
SwatchLegend["Rainbow", labels, BaseStyle -> Opacity[.25], LegendMarkerSize -> 30]
SwatchLegend["Rainbow", Style[##, FontFamily -> "Times New Roman", 18] & @@@
Transpose[{labels, ColorData["Rainbow"] /@ Subdivide[Length@labels - 1]}],
BaseStyle -> Opacity[.25], LegendMarkerSize -> 30]