6
$\begingroup$

I am using the options PlotTheme -> "Scientific" and PlotLegends -> Placed[Automatic, Right] on a MatrixPlot and I would like to change the font size of the legend labels.

I would usually do that by specifying

BarLegend[{"LakeColors", {0, 1}}, LabelStyle -> {FontSize -> 20}] 

but

  • I don't know the color function used by the base theme "Scientific" and

  • I would like to keep the range of min and max values {0,1} as Automatic

What would be the best way to change the legend font in this case?

$\endgroup$

2 Answers 2

6
$\begingroup$

This is straightforward. All of the legend functions accept the generic, top level arguments, e.g. LineLegend[Automatic] which allows you to modify the behavior. So, you would use BarLegend[Automatic, LabelStyle -> {FontSize -> 20}].

$\endgroup$
1
  • $\begingroup$ To the random downvoter, why? Is my answer incorrect? Too short? What? $\endgroup$ Commented May 1, 2017 at 18:35
1
$\begingroup$

You can see what ColorFunction was used for the graphics as follows.

data = RandomReal[1, {4, 4}]; MatrixPlot[data, PlotTheme -> "Scientific", PlotLegends -> Placed[BarLegend[Automatic, LegendLayout -> "Column", LabelStyle -> {FontSize -> 20}], After]] // InputForm (*Legended[Graphics[Raster[{{{0.4461453382422279, 0.491477006229007, 0.7637054679655062, 1.}, {0.3154254478896804, 0.3694472079594942, 0.65486047117729, 1.}, {0.7569822664902999, 0.7361394855201956, 0.7844867644266112, 1.}, {0.9143712804788171, 0.8600217622903947, 0.7950091556297764, 1.}}, {{0.6337218541194113, 0.6391201311626331, 0.7762460731231854, 1.}, {0.35374427405760145, 0.4143282314629484, 0.7344141311061161, 1.}, {0.4107447677037708, 0.46361290589486254, 0.7613387293820364, 1.}, {0.6601415148287806, 0.6599152784046868, 0.7780123844964757, 1.}}, {{0.5282720496463704, 0.5561196628831526, 0.7691961268350438, 1.}, {0.33466924070697635, 0.39198654969047086, 0.6948124817847957, 1.}, {0.47836178822829944, 0.5168348572796462, 0.7658593291616591, 1.}, {0.6966959644875594, 0.6886876071400427, 0.780456266758513, 1.}}, {{0.8161315485390368, 0.782696405497182, 0.7884412455516316, 1.}, {0.292198, 0.342242, 0.606638, 1.}, {0.5970079564384867, 0.6102222994870824, 0.7737915308130096, 1.}, {0.30371427829734576, 0.35573047051500206, 0.6305469288199474, 1.}}}, {{0, 0}, {4, 4}}, {0, 1}], Axes -> False, Frame -> True, FrameLabel -> {None, None}, FrameStyle -> Automatic, FrameTicks -> {{{{3.5, 1}, {2.5, 2}, {1.5, 3}, {0.5, 4}}, {{3.5, 1}, {2.5, 2}, {1.5, 3}, {0.5, 4}}}, {{{0.5, 1}, {1.5, 2}, {2.5, 3}, {3.5, 4}}, {{0.5, 1}, {1.5, 2}, {2.5, 3}, {3.5, 4}}}}, GridLines -> None, GridLinesStyle -> Directive[GrayLevel[0.5, 0.4]], LabelStyle -> {FontFamily -> "Times"}, Method -> {"AxisPadding" -> Scaled[0.02], "DefaultBoundaryStyle" -> Automatic, "DefaultPlotStyle" -> Automatic, "DomainPadding" -> Scaled[0.02], "RangePadding" -> Scaled[0.05]}], Placed[BarLegend[{Blend[System`PlotThemeDump`$ThemeColorMatrix, #1] & , {0.5478712433217057, 1.}}, LabelStyle -> {FontSize -> 20}, LegendLayout -> "Column", Ticks -> {{0.6506512323727816, 0.3}, {0.7410419717964505, 0.48}, {0.8264110034743599, 0.65}, {0.9117800351522696, 0.8200000000000001}, {0.565282200694872, 0.13}, {0.997149066830179, 0.99}}, "PinningPoint" -> 0.5, "SmoothRange" -> False, Charting`TickSide -> Right, ColorFunctionScaling -> False], After, Identity]]*) 

The ColorFunction used by BarLegend is specified in the output

Blend[System`PlotThemeDump`$ThemeColorMatrix, #1] & 
$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.